--Author: John Maxwell
--last modified: November 28, 1981 8:44 AM

DIRECTORY
MusicDefs: FROM "MusicDefs",
Real USING [FixI],
Sheet USING [Height];

Beam: DEFINITIONS IMPORTS MusicDefs, Real, Sheet =
BEGIN
OPEN MusicDefs;

AddBeam:PROCEDURE[b:BeamPTR,new:BeamPTR];
AddChord:PROCEDURE[b:BeamPTR,c:ChordPTR];
AddNote:PROCEDURE[b:BeamPTR,n:NotePTR];
Draw:PROCEDURE[b:BeamPTR] RETURNS[INTEGER,INTEGER];
Drawn:PROCEDURE[b:BeamPTR] RETURNS[BOOLEAN];
Grace:PROCEDURE[b:BeamPTR] RETURNS[BOOLEAN];
InVoice:PROCEDURE[b:BeamPTR,voice:CARDINAL] RETURNS[BOOLEAN];
Remove:PROCEDURE[beam:BeamPTR,n:NotePTR,c:ChordPTR,b:BeamPTR];
SetStems:PROCEDURE[b:BeamPTR];
SetSyncs:PROCEDURE[b:BeamPTR];
Sort:PROCEDURE[b:BeamPTR];

--inline procedures

GetHeapIndex:PUBLIC PROC[p:BeamPTR] RETURNS[CARDINAL] = INLINE
{FOR i:CARDINAL IN [0..beamHeapLength) DO
IF beamHeap[i]=p THEN RETURN[i];
ENDLOOP;
RETURN[beamHeapLength]};

Height:PROCEDURE[b:BeamPTR,time:Time] RETURNS[h:INTEGER] = INLINE
{h ← b.height+Sheet.Height[b.sync1.time,,b.staff];
IF time#b.sync1.time THEN h ← h + Real.FixI[(time-b.sync1.time)*b.tilt]};

Length:PROC[b:BeamPTR] RETURNS[CARDINAL] = INLINE
{FOR i:CARDINAL IN [0..beamLength] DO
IF i=beamLength THEN RETURN[i];
IF b.chord[i]=endOfBeam THEN RETURN[i];
ENDLOOP;
ERROR};

time:PUBLIC PROCEDURE[chord:VariousPTR] RETURNS[Time] = INLINE
{WITH ev:chord SELECT FROM
note => RETURN[ev.n.sync.time];
chord => RETURN[ev.c.note[0].sync.time];
beam => RETURN[IF ev.b.sync1#NIL THEN ev.b.sync1.time ELSE 0];
ENDCASE => ERROR};

END..