<> <> <> <> <> <<>> <> <> DIRECTORY Imager USING [Context], MusicFileDefs USING [AccidentalFormat, DisplayModeFormat, EmbellishmentFormat, NoteValueFormat], Rope USING [ROPE]; MusicDefs: CEDAR DEFINITIONS ~ BEGIN ROPE: TYPE ~ Rope.ROPE; Error: SIGNAL[s: ROPE]; Notify: SIGNAL[s: ROPE]; <<****************************************************************************>> <> <<****************************************************************************>> ScorePTR: TYPE ~ REF ScoreRec; ScoreRec: TYPE ~ RECORD [ name: ROPE _ NIL, -- name of the score beamHeap: BeamHeapPTR _ NIL, -- collection of beams chordHeap: ChordHeapPTR _ NIL, -- collection of chords cache: CachePTR _ NIL, -- current key, time signature, etc. sheet: SheetPTR _ NIL, -- cached information about the sheet (derived from the piece) style: StylePTR _ NIL, -- maxVoice: NAT _ 0, -- index of the highest numbered voice command: BOOL _ FALSE, -- we have a new command flash: BOOL _ FALSE, -- flash the screen for an error length: NAT _ 0, -- length of score event: SEQUENCE max: NAT OF EventPTR -- collection of events ]; ScorePortionPTR: TYPE ~ REF ScorePortionRec; ScorePortionRec: TYPE ~ RECORD[ -- a portion of a score. score: ScorePTR _ NIL, toc: Time _ 0, -- length of portion in seconds of playing time. duration: Time _ 0, -- length in portion in pixels on the screen. <> ss1, ss2: ScoreStateRec _ [] -- state of score at beginning and end ]; ScoreStatePTR: TYPE ~ REF ScoreStateRec; ScoreStateRec: TYPE ~ RECORD[ key: INTEGER _ 0, style: NAT _ 1, staff: ARRAY [0..4) OF Staff _ ALL[[]] ]; EventPTR: TYPE ~ REF EventRec; EventRec: TYPE ~ RECORD[ time: Time _ 0, -- measured in pixels from beginning of piece variant: SELECT type: EventType FROM sync => [ length: NAT _ 0, -- actual length of the sequence note: SEQUENCE max: NAT OF NotePTR -- collection of notes ], measure => [ measure: MeasureType _ measure, eol: BOOL _ FALSE -- eol => force to end of line ], timeSignature => [ts: TimeSignature _ [4,4]], keySignature => [key: INTEGER _ 0], metronome => [metronome: INTEGER _ 128], staves => [ -- marks a change in staffing staves: StavesType _ style, value: NAT _ 0, -- index of the staff OR style number height: INTEGER _ 0, offset: INTEGER _ 0, length: [0..4] _ 4, -- number of staffs in following array staff: ARRAY [0..4) OF Staff _ ALL[[0, 0]] ], ENDCASE ]; SyncPTR: TYPE ~ REF EventRec[sync]; -- 'sync' comes from 'synchronize' MeasurePTR: TYPE ~ REF EventRec[measure]; TimeSignaturePTR: TYPE ~ REF EventRec[timeSignature]; KeySignaturePTR: TYPE ~ REF EventRec[keySignature]; MetronomePTR: TYPE ~ REF EventRec[metronome]; StavesPTR: TYPE ~ REF EventRec[staves]; Time: TYPE ~ LONG INTEGER; EventType: TYPE ~ {sync, measure, timeSignature, keySignature, metronome, staves}; MeasureType: TYPE ~ {measure, repeat1, repeat2, endMeasure, doubleMeasure, m5}; TimeSignature: TYPE ~ RECORD [top, bottom: [0..32)]; StavesType: TYPE ~ {style, clef, octava1, octava2}; NotePTR: TYPE ~ REF NoteRec; NoteRec: TYPE ~ RECORD[ sync: SyncPTR _ NIL, -- pointer back to sync beam: BeamPTR _ NIL, -- pointer back to beam chord: ChordPTR _ NIL, -- pointer back to chord pitch: INTEGER _ 44, -- pitch of the note voice: NAT _ 0, -- the voice that this note belongs to value: NoteValue _ unknown, -- what is the logical value of this note? spelled: Accidental _ inKey, -- does this note have an explicit spelling on it? rest: BOOL _ FALSE, -- is this a rest note? dotted: BOOL _ FALSE, -- is this note dotted? doubleDotted: BOOL _ FALSE, -- is this note double dotted? grace: BOOL _ FALSE, -- is this a grace note? stemUp: BOOL _ TRUE, -- is the stem up or down? spare1: BOOL _ FALSE, embellish: Embellishment _ none, -- does this note have an embellishment on it? tied: BOOL _ FALSE, -- is this the second note of a tied note? tie: NotePTR _ NIL, -- pointer to the second note of a tie tieHeight: INTEGER _ 0, -- the height of said tie show: BOOL _ FALSE, shown: Accidental _ inKey, -- the accidental displayed on the screen (cached) spare: [0..256) _ 0, staff: [0..16) _ 1, -- the index of the staff that this note is on delta: [-128..128) _ 0, -- how far to move the note relative to the sync accDelta: [-128..128) _ 0, -- how far to move the accidental relative to the sync toc: LONG CARDINAL _ 0, -- physical-note time of occurrence (in clock pulses) duration: CARDINAL _ 0 -- physical-note duration (in clock pulses) ]; NoteValue: TYPE ~ MusicFileDefs.NoteValueFormat; Accidental: TYPE ~ MusicFileDefs.AccidentalFormat; Embellishment: TYPE ~ MusicFileDefs.EmbellishmentFormat; PhysicalNote: TYPE ~ RECORD[ pitch: INTEGER _ 0, duration: CARDINAL _ 0, loudness: CARDINAL _ 0, toc: LONG CARDINAL _ 0 -- toc is the physical time of occurrence ]; ChordPTR: TYPE ~ REF ChordRec; ChordRec: TYPE ~ RECORD[ stemUp: BOOL _ TRUE, delta: INTEGER _ 0, -- offset from center line of sync (cached) length: NAT _ 0, -- length of note sequence note: SEQUENCE max: NAT OF NotePTR ]; BeamPTR: TYPE ~ REF BeamRec; BeamRec: TYPE ~ RECORD[ tilt: REAL _ 0, -- tilt of beam beamed: BOOL _ TRUE, -- does the beam show, or do you use brackets instead? ntuple, against: [0..128) _ 1, -- for ntupled beams; the ratio is what is important sync1, sync2: SyncPTR _ NIL, -- first and last sync in beam (cached) beam: BeamPTR _ NIL, -- beam that this beam belongs to height: INTEGER _ 0, -- height of beam from top of left-most note invisible: BOOL _ FALSE, length: NAT _ 0, -- length of chord sequence staff: NAT _ 0, -- graphical information chord: SEQUENCE max: NAT OF VariousPTR -- chord sequence ]; VariousPTR: TYPE ~ REF; -- NotePTR, ChordPTR, or BeamPTR endOfBeam: VariousPTR ~ NIL; <<******************************************************************************>> <> <<******************************************************************************>> BeamHeapPTR: TYPE ~ REF BeamHeapRec; BeamHeapRec: TYPE ~ RECORD[ length: NAT _ 0, beam: SEQUENCE max: NAT OF BeamPTR ]; ChordHeapPTR: TYPE ~ REF ChordHeapRec; ChordHeapRec: TYPE ~ RECORD[ length: NAT _ 0, chord: SEQUENCE max: NAT OF ChordPTR ]; CachePTR: TYPE ~ REF CacheRec; CacheRec: TYPE ~ RECORD[ -- all of the structural (non-sync) events beamIndex: NAT _ 0, beamQueue: ARRAY [0..3) OF BeamPTR _ ALL[NIL], -- drawn beams key1, key2: KeySignaturePTR _ NIL, -- bracketing keys ts1, ts2: TimeSignaturePTR _ NIL, -- bracketing time signatures met1, met2: MetronomePTR _ NIL -- bracketing metronomes ]; SheetPTR: TYPE ~ REF SheetRec; SheetRec: TYPE ~ RECORD[ context: Imager.Context _ NIL, voice: NAT _ noVoice, -- currently selected voice top: INTEGER _ 0, -- the y position of the top of the score (for scrolling) begin, endTime: Time _ 0, -- start and end of the part of the score that is currently visible dirty1, dirty2: Time _ 0, -- the portion of the score that needs to be repainted scale: INTEGER _ 1, -- normal, hardcopy and overview density: INTEGER _ 256, -- scale factor in physical mode. justification: INTEGER _ 1, -- density of justification. used in graphical mode. accidental: BOOL _ TRUE, notehead: BOOL _ TRUE, sync: BOOL _ FALSE, display: DisplayMode _ graphical, noCarry: BOOL _ FALSE, hardcopy: BOOL _ FALSE, -- display in hardcopy mode printing: BOOL _ FALSE, -- we are printing instead of displaying width: INTEGER _ 550, -- width of staff current: NAT _ 0, -- current section index length: NAT _ 0, -- length of sheet sequence section: SEQUENCE max: NAT OF Section -- sequence of sections ]; Section: TYPE ~ RECORD[ time: Time _ 0, -- actual time of beginning of section. (may be different from staves.time) x, y: INTEGER _ 0, -- position of the lower left corner of the section page: INTEGER _ 0, -- the page that this section is on key: INTEGER _ 0, -- the key for this section staves: StavesPTR _ NIL ]; noVoice: NAT ~ 1000; Staff: TYPE ~ RECORD[ pitch: INTEGER _ 0, -- pitch of note on bottom line y: INTEGER _ 0 -- height relative to bottom line ]; StylePTR: TYPE ~ REF StyleRec; StyleRec: TYPE ~ RECORD[ length: NAT _ 0, style: SEQUENCE max: NAT OF StavesPTR ]; SelectionPTR: TYPE ~ REF SelectionRec; SelectionRec: TYPE ~ RECORD[ lineSelect: BOOL _ FALSE, -- line selection or note selection? score: ScorePTR _ NIL, -- score of primary selection or note selection select1, select2: Time _ 0, -- line selected score2: ScorePTR _ NIL, -- score of secondary selection greySelect1, greySelect2: Time _ 0, -- secondary line selection length: NAT _ 0, -- length of note selection note: SEQUENCE max: NAT OF NotePTR -- notes selected ]; DisplayMode: TYPE ~ MusicFileDefs.DisplayModeFormat; ObjectType: TYPE ~ {measure, note, leftBeam, rightBeam, tie}; LookCommand: TYPE ~ {accidental, graphical, hardcopy, justified, logical, noCarry, notehead, overview, physical, style, sync, voice}; <> <> <> <> <> <> <> <> <> ColorType: TYPE ~ {black, grey, light, white}; FontType: TYPE ~ {text, music}; PaintMode: TYPE ~ {opaque, transparent, invert}; <<****************************************************************************>> <> <<****************************************************************************>> Measure: PROC[event: EventPTR] RETURNS[BOOL] ~ INLINE { WITH event SELECT FROM ev: MeasurePTR => RETURN[TRUE]; ev: StavesPTR => RETURN[ev.staves=style]; ENDCASE => RETURN[FALSE]; }; EndOfScore: PROC[score: ScorePTR] RETURNS[Time] ~ INLINE { IF score.length#0 THEN RETURN[score.event[score.length-1].time+40] ELSE RETURN[10] }; LMod: PROC[m, n: Time] RETURNS[k: Time] ~ INLINE { k _ m - n*(m/n); IF k>n THEN k _ k+n; }; Mod: PROC[m, n: INTEGER] RETURNS[k: INTEGER] ~ INLINE { k _ m MOD n; IF k<0 THEN k _ k+n; }; SetDirty: PROC[score: ScorePTR, begin, end: Time] ~ INLINE { score.sheet.dirty1 _ MIN[score.sheet.dirty1, begin]; score.sheet.dirty2 _ MAX[score.sheet.dirty2, end]; }; END.