@@ -1,6 +1,29 @@
11module Abcjs.Types
22 ( Selector(..)
33 , Abc(..)
4+ , Pixels(..)
5+ , Scale(..)
6+ , Percent(..)
7+ , Qpm(..)
8+ , BeatNumber(..)
9+ , TotalBeats(..)
10+ , Fraction(..)
11+ , Measures(..)
12+ , LineCount(..)
13+ , MidiNote(..)
14+ , Velocity(..)
15+ , Instrument(..)
16+ , CharOffset(..)
17+ , TuneNumber(..)
18+ , Classes(..)
19+ , FileName(..)
20+ , Color(..)
21+ , MeasureStart(..)
22+ , Display(..)
23+ , AddClasses(..)
24+ , UserAction(..)
25+ , Responsive(..)
26+ , resize
427 , TuneObject
528 , tuneLineCount
629 , TimingEvent
@@ -10,20 +33,210 @@ module Abcjs.Types
1033 , eventTop
1134 , eventWidth
1235 , eventHeight
36+ , eventElements
37+ , MidiPitch
38+ , eventMidiPitches
39+ , AbcElem
40+ , abcElemStartChar
41+ , abcElemEndChar
42+ , Analysis
43+ , DragContext
1344 ) where
1445
46+import Prelude
47+
1548import Data.Newtype (class Newtype)
49+import Data.Time.Duration (Milliseconds)
50+import Web.DOM (Element)
51+
52+-- A leaf newtype per primitive so nothing in the API is a bare Number/Boolean/
53+-- String. They erase at runtime, so the FFI still hands abcjs raw values.
1654
17−-- | A CSS selector (or element id) naming where to draw, distinct from the
18−-- | music itself so the two can never be passed in the wrong order.
55+-- | The id of the element to draw into — abcjs resolves it with
56+-- | `getElementById`, so give the bare id ("staff"), not a CSS selector
57+-- | ("#staff").
1958newtype Selector = Selector String
2059
2160derive instance Newtype Selector _
61+derive newtype instance Eq Selector
62+derive newtype instance Show Selector
2263
2364-- | ABC notation source text — the thing you generate for the game.
2465newtype Abc = Abc String
2566
2667derive instance Newtype Abc _
68+derive newtype instance Eq Abc
69+derive newtype instance Show Abc
70+
71+-- | A length on the rendered SVG, in CSS pixels.
72+newtype Pixels = Pixels Number
73+
74+derive instance Newtype Pixels _
75+derive newtype instance Eq Pixels
76+derive newtype instance Ord Pixels
77+derive newtype instance Show Pixels
78+
79+-- | A unitless render zoom multiplier (1.0 = as engraved).
80+newtype Scale = Scale Number
81+
82+derive instance Newtype Scale _
83+derive newtype instance Eq Scale
84+derive newtype instance Ord Scale
85+derive newtype instance Show Scale
86+
87+-- | A percentage of the written tempo (100.0 = as written).
88+newtype Percent = Percent Number
89+
90+derive instance Newtype Percent _
91+derive newtype instance Eq Percent
92+derive newtype instance Ord Percent
93+derive newtype instance Show Percent
94+
95+-- | Tempo in quarter notes per minute.
96+newtype Qpm = Qpm Number
97+
98+derive instance Newtype Qpm _
99+derive newtype instance Eq Qpm
100+derive newtype instance Ord Qpm
101+derive newtype instance Show Qpm
102+
103+newtype BeatNumber = BeatNumber Number
104+
105+derive instance Newtype BeatNumber _
106+derive newtype instance Eq BeatNumber
107+derive newtype instance Ord BeatNumber
108+derive newtype instance Show BeatNumber
109+
110+newtype TotalBeats = TotalBeats Number
111+
112+derive instance Newtype TotalBeats _
113+derive newtype instance Eq TotalBeats
114+derive newtype instance Ord TotalBeats
115+derive newtype instance Show TotalBeats
116+
117+-- | A position along the tune, from 0.0 to 1.0.
118+newtype Fraction = Fraction Number
119+
120+derive instance Newtype Fraction _
121+derive newtype instance Eq Fraction
122+derive newtype instance Ord Fraction
123+derive newtype instance Show Fraction
124+
125+-- | A musical length in whole-note units (abcjs's internal duration measure).
126+newtype Measures = Measures Number
127+
128+derive instance Newtype Measures _
129+derive newtype instance Eq Measures
130+derive newtype instance Ord Measures
131+derive newtype instance Show Measures
132+
133+newtype LineCount = LineCount Int
134+
135+derive instance Newtype LineCount _
136+derive newtype instance Eq LineCount
137+derive newtype instance Ord LineCount
138+derive newtype instance Show LineCount
139+
140+-- | A MIDI note number (middle C = 60).
141+newtype MidiNote = MidiNote Int
142+
143+derive instance Newtype MidiNote _
144+derive newtype instance Eq MidiNote
145+derive newtype instance Ord MidiNote
146+derive newtype instance Show MidiNote
147+
148+-- | A MIDI velocity, 0–127.
149+newtype Velocity = Velocity Int
150+
151+derive instance Newtype Velocity _
152+derive newtype instance Eq Velocity
153+derive newtype instance Ord Velocity
154+derive newtype instance Show Velocity
155+
156+-- | A General MIDI instrument (program) number.
157+newtype Instrument = Instrument Int
158+
159+derive instance Newtype Instrument _
160+derive newtype instance Eq Instrument
161+derive newtype instance Ord Instrument
162+derive newtype instance Show Instrument
163+
164+-- | A character offset into the ABC source.
165+newtype CharOffset = CharOffset Int
166+
167+derive instance Newtype CharOffset _
168+derive newtype instance Eq CharOffset
169+derive newtype instance Ord CharOffset
170+derive newtype instance Show CharOffset
171+
172+-- | Which tune in the source a click landed on (0-based).
173+newtype TuneNumber = TuneNumber Int
174+
175+derive instance Newtype TuneNumber _
176+derive newtype instance Eq TuneNumber
177+derive newtype instance Ord TuneNumber
178+derive newtype instance Show TuneNumber
179+
180+-- | The space-joined CSS classes on a clicked element.
181+newtype Classes = Classes String
182+
183+derive instance Newtype Classes _
184+derive newtype instance Eq Classes
185+derive newtype instance Show Classes
186+
187+-- | A download file name, e.g. for rendered-audio export.
188+newtype FileName = FileName String
189+
190+derive instance Newtype FileName _
191+derive newtype instance Eq FileName
192+derive newtype instance Show FileName
193+
194+-- | A CSS colour string (e.g. "#1db954", "red") for recolouring notes.
195+newtype Color = Color String
196+
197+derive instance Newtype Color _
198+derive newtype instance Eq Color
199+derive newtype instance Show Color
200+
201+-- | Whether a timing event begins a new measure.
202+newtype MeasureStart = MeasureStart Boolean
203+
204+derive instance Newtype MeasureStart _
205+derive newtype instance Eq MeasureStart
206+derive newtype instance Show MeasureStart
207+
208+-- | Whether a control-panel button is shown.
209+newtype Display = Display Boolean
210+
211+derive instance Newtype Display _
212+derive newtype instance Eq Display
213+derive newtype instance Show Display
214+
215+-- | Whether abcjs tags rendered elements with CSS classes.
216+newtype AddClasses = AddClasses Boolean
217+
218+derive instance Newtype AddClasses _
219+derive newtype instance Eq AddClasses
220+derive newtype instance Show AddClasses
221+
222+-- | Whether playback was triggered by a user gesture (so the browser may
223+-- | unlock the audio context).
224+newtype UserAction = UserAction Boolean
225+
226+derive instance Newtype UserAction _
227+derive newtype instance Eq UserAction
228+derive newtype instance Show UserAction
229+
230+-- | The abcjs "responsive" mode. Use `resize` to make the SVG scale to its
231+-- | container.
232+newtype Responsive = Responsive String
233+
234+derive instance Newtype Responsive _
235+derive newtype instance Eq Responsive
236+derive newtype instance Show Responsive
237+
238+resize :: Responsive
239+resize = Responsive "resize"
27240
28241-- | A parsed/rendered tune, as returned by `renderAbc` or `parseOnly`.
29242-- | Opaque: pass it back into the synth and timing APIs.
@@ -32,7 +245,7 @@ foreign import data TuneObject :: Type
32245-- | How many lines of music the tune parsed to. Zero means abcjs found no
33246-- | notes (empty or unparseable input) — abcjs still returns a tune object,
34247-- | so this is how you tell a generated phrase actually parsed.
35−foreign import tuneLineCount :: TuneObject -> Int
248+foreign import tuneLineCount :: TuneObject -> LineCount
36249
37250-- | One playback event (a note, rest, or bar) handed to your callbacks.
38251-- | The accessors below pull out the fields a follow-along game needs:
@@ -40,16 +253,52 @@ foreign import tuneLineCount :: TuneObject -> Int
40253foreign import data TimingEvent :: Type
41254
42255-- | Milliseconds from the start of the tune at which this event sounds.
43−foreign import eventMilliseconds :: TimingEvent -> Number
256+foreign import eventMilliseconds :: TimingEvent -> Milliseconds
44257
45258-- | Whether this event begins a new measure (handy for bar-level scoring).
46−foreign import eventMeasureStart :: TimingEvent -> Boolean
259+foreign import eventMeasureStart :: TimingEvent -> MeasureStart
47260
48261-- | The on-screen bounding box of the event, for drawing a cursor.
49−foreign import eventLeft :: TimingEvent -> Number
262+foreign import eventLeft :: TimingEvent -> Pixels
263+
264+foreign import eventTop :: TimingEvent -> Pixels
265+
266+foreign import eventWidth :: TimingEvent -> Pixels
267+
268+foreign import eventHeight :: TimingEvent -> Pixels
269+
270+-- | The SVG nodes drawn for this event's note(s): one inner array per note,
271+-- | each holding the notehead/stem/etc. elements. Recolour these (set their
272+-- | `fill`) to highlight a note — see `Abcjs.Highlight`.
273+foreign import eventElements :: TimingEvent -> Array (Array Element)
274+
275+-- | The sounding notes at this event — the hook for scoring "did the player
276+-- | play the right note?". Empty for rests and bar events. `start`/`duration`
277+-- | are in whole-note units; `startChar`/`endChar` index back into the ABC.
278+type MidiPitch =
279+ { pitch :: MidiNote
280+ , volume :: Velocity
281+ , start :: Measures
282+ , duration :: Measures
283+ , instrument :: Instrument
284+ , startChar :: CharOffset
285+ , endChar :: CharOffset
286+ }
287+
288+foreign import eventMidiPitches :: TimingEvent -> Array MidiPitch
289+
290+-- | A clicked notation element (note, rest, bar, …) handed to a `ClickListener`.
291+-- | `startChar`/`endChar` index back into the ABC source — enough to tell which
292+-- | note was clicked.
293+foreign import data AbcElem :: Type
294+
295+foreign import abcElemStartChar :: AbcElem -> CharOffset
50296
51−foreign import eventTop :: TimingEvent -> Number
297+foreign import abcElemEndChar :: AbcElem -> CharOffset
52298
53−foreign import eventWidth :: TimingEvent -> Number
299+-- | abcjs's harmonic analysis of a clicked element. Opaque here.
300+foreign import data Analysis :: Type
54301
55−foreign import eventHeight :: TimingEvent -> Number
302+-- | The drag context for a clicked element (step/max/index/setSelection).
303+-- | Opaque here.
304+foreign import data DragContext :: Type