<> <> <> <> <> DIRECTORY Beam USING [SetStems], Graphics USING [DisplayContext, DrawRectangle, GetTexture, MakeFont, MoveTo, Scale, SetLineWidth, SetPaint, SetTexture, Texture, Vec], InlineDefs USING [LowHalf], MusicDefs, Piece USING [AddSync, RemoveSync], Score USING [BuildCache, cache, cacheLength, DrawKey, Look], Selection USING [AddLine], Sheet USING [default, FindLine, FindSection, Map, NextLine, NormalPitch, OctavaHeight, PriorLine, Reset, SetBegin], StringDefs USING [AppendDecimal], Sync USING [GetScoreIndex, Hidden, SetStave], Utility USING [DrawChar, DrawLine, DrawString, NewSync, SetFont]; SheetImplA: CEDAR PROGRAM IMPORTS Beam, Graphics, InlineDefs, MusicDefs, Piece, Score, Selection, Sheet, StringDefs, Sync, Utility EXPORTS MusicDefs, Sheet = BEGIN OPEN MusicDefs, Score, Sheet; begin: PUBLIC Time; endTime: PUBLIC Time; scale, staffLength: PUBLIC INTEGER; Last: PUBLIC PROC[l: CARDINAL] RETURNS[CARDINAL] = {FOR i: CARDINAL IN [l..sheetLength-1) DO IF sheet[i].time#sheet[i+1].time THEN RETURN[i]; ENDLOOP; RETURN[sheetLength-1]}; LineNumber: PUBLIC PROC[l: CARDINAL] RETURNS[n: CARDINAL _ 1] = {FOR i: CARDINAL IN (0..l] DO IF sheet[i].y#sheet[i-1].y THEN n _ n+1; ENDLOOP}; NextLine: PUBLIC PROC[l: CARDINAL] RETURNS[CARDINAL] = {FOR i: CARDINAL IN (l..sheetLength) DO IF sheet[i].y=sheet[l].y THEN LOOP; RETURN[Last[i]]; ENDLOOP; RETURN[sheetLength-1]}; NextStaff: PUBLIC PROC[s: CARDINAL, t: Time] RETURNS[CARDINAL] = {staves: StavesPTR = sheet[FindSection[t]].staves; FOR i: CARDINAL IN (s..staves.sl] DO IF staves.staff[i].y#staves.staff[s].y THEN RETURN[i]; ENDLOOP; RETURN[s]}; NormalPitch: PUBLIC PROC[staff: CARDINAL] RETURNS[INTEGER] = {RETURN[IF staff IN [0..1] THEN 48 ELSE 27]}; PriorLine: PUBLIC PROC[l: CARDINAL] RETURNS[CARDINAL] = {FOR i: CARDINAL DECREASING IN [0..l) DO IF sheet[i].y#sheet[l].y THEN {l _ i; EXIT}; ENDLOOP; FOR i: CARDINAL DECREASING IN [0..l) DO IF sheet[i].y#sheet[l].y THEN RETURN[Last[i+1]]; ENDLOOP; RETURN[Last[0]]}; PriorStaff: PUBLIC PROC[s: CARDINAL, t: Time] RETURNS[CARDINAL] = {staves: StavesPTR = sheet[FindSection[t]].staves; FOR i: CARDINAL DECREASING IN [0..s) DO IF staves.staff[i].y#staves.staff[s].y THEN RETURN[i]; ENDLOOP; RETURN[s]}; OctavaHeight: PUBLIC PROC[pitch, height: INTEGER] RETURNS[INTEGER] = {IF pitch=60 AND height<40 THEN RETURN[40]; IF pitch=60 AND height>90 THEN RETURN[90]; IF pitch=15 AND height<-40 THEN RETURN[-40]; IF pitch=15 AND height>-8 THEN RETURN[-8]; RETURN[height]}; <<****************************************************************************>> <> <<****************************************************************************>> sheet: PUBLIC ARRAY [0..sheetLength) OF Section; Initialize: PUBLIC PROC[dc: Graphics.DisplayContext] = BEGIN context _ dc; music _ Graphics.MakeFont["music"]; text _ Graphics.MakeFont["TimesRoman"]; Utility.SetFont[context, music, 8]; style _ ALL[[NIL, 0, 0, 0,[[0, 0],[0, 0],[0, 0],[0, 0]]]]; <> style[0] _ [NIL, 0, 60, 3,,]; style[0].staff _[[72,-32],[48,-88],[27,-136],[3,-196]]; <> style[1] _ [NIL, 0, 80, 3,,]; style[1].staff _[[48,-32],[48,-32],[48,-32],[48,-32]]; <> style[2] _ [NIL, 0, 85, 3,,]; style[2].staff _[[48,-32],[48,-32],[27,-125],[27,-125]]; style[12] _ [NIL, 0, 85, 3,,]; style[12].staff _[[48,-32],[48,-32],[27,-150],[27,-150]]; <> style[3] _ [NIL, 0, 75, 3,,]; style[3].staff _[[48,-32],[48,-32],[27,-110],[27,-185]]; style[13] _ [NIL, 0, 75, 3,,]; style[13].staff _[[48,-32],[48,-32],[27,-130],[27,-220]]; <> style[4] _ [NIL, 0, 75, 3,,]; style[4].staff _[[48,-32],[48,-110],[27,-185],[27,-260]]; show _ [, TRUE, TRUE, FALSE, FALSE, TRUE, graphical]; selection _ ALL[NIL]; selectionLength _ 0; begin _ 0; scale _ 1; staffLength _ 550; TF _ 256; Score.Look[sheet,, 2]; Selection.AddLine[0, 0]; END; Reset: PUBLIC PROC= { sync: SyncPTR _ NIL; staves: StavesPTR _ NIL; page, pitch: INTEGER _ 2; v, j, last, next: CARDINAL _ 0; time, break, lastBreak, cacheTime: Time _ 0; top, height, x, sc, lastHeight: INTEGER _ 0; Score.BuildCache[]; IF scale=2 THEN sc _ 3 ELSE sc _ 2*scale; [staves, last, next] _ NextStyle[NIL, 0, 0, 100]; IF staves=NIL THEN RETURN; FOR i: CARDINAL IN [0..cacheLength] DO IF i#cacheLength AND cache[i].type NOT IN SheetSwitch THEN LOOP; IF i=cacheLength THEN cacheTime _ LONG[staffLength]*sheetLength ELSE cacheTime _ cache[i].time; WHILE time=break THEN { -- new line height _ height-lastHeight; x_ MAX[8, ABS[8*(sheet[j].key)]]; lastBreak _ break; break _ lastBreak+staffLength-x; [staves, last, next] _ NextStyle[staves, last, next, break-20]; lastHeight _ -staves.staff[staves.sl].y+staves.offset; IF top-height>(650*sc)/2 THEN { -- new page top _ height; sheet[j].page _ page; page _ page+1}}; sheet[j].x _ x; sheet[j].y _ height; sheet[j].staves _ staves; time _ MIN[break, cacheTime]; j _ j + 1; ENDLOOP; IF i=cacheLength THEN EXIT; IF cache[i].type=staves THEN LOOP; Sync.SetStave[staves, cache[i]]; staves _ LOOPHOLE[@cache[i].event]; IF cache[i].type#clef THEN LOOP; IF Sync.Hidden[0, Sync.GetScoreIndex[cache[i]], lastBreak] THEN time _ lastBreak; ENDLOOP; IF scale=2 THEN Paginate[]; Sheet.SetBegin[begin]; FOR i: CARDINAL IN [0..beamHeapLength) DO IF beamHeap[i].sync2.timemax THEN LOOP; Beam.SetStems[beamHeap[i]]; ENDLOOP; }; NextStyle: PROC[old: StavesPTR, last, next: CARDINAL, break: Time] RETURNS[StavesPTR, CARDINAL, CARDINAL] = { temp, new: StavesPTR; newLast, newNext: CARDINAL _ 0; new _ old; newLast _ last; newNext _ next; FOR i: CARDINAL IN [next..cacheLength) DO IF cache[i].time>=break+40 THEN EXIT; IF cache[i].type#staves THEN LOOP; newNext _ i; IF cache[i].time>=break THEN EXIT; temp _ LOOPHOLE[@cache[i].event]; IF temp=old THEN LOOP; IF new#NIL AND i#next AND new.staff[new.sl].y=time+staffLength THEN EXIT; IF cache[i].type#keySignature THEN LOOP; IF cache[i].time