Hosted by
|
with Gray_Images; use Gray_Images;
with Integer_Strings; use Integer_Strings;
with Enum_Strings; use Enum_Strings;
with Messages; use Messages;
package body Boxes.Measures is
function Create
return Measure_Box_Access
is
Result : Measure_Box_Access := new Measure_Box;
begin
Result.Times := Time_Lists.Create;
Result.Chords := Chord_Lists.Create;
return Result;
end Create;
procedure Set_Clef
(This : access Measure_Box;
Clef : in Clef_Box_Access) is
begin
This.Clef := Clef;
end Set_Clef;
function Get_Clef
(This : access Measure_Box)
return Clef_Box_Access is
begin
return This.Clef;
end Get_Clef;
procedure Set_Key
(This : access Measure_Box;
Key : in Key_Box_Access) is
begin
This.Key := Key;
end Set_Key;
function Get_Key
(This : access Measure_Box)
return Key_Box_Access is
begin
return This.Key;
end Get_Key;
function Get_Times
(This : access Measure_Box)
return Time_List_Access is
begin
return This.Times;
end Get_Times;
procedure Set_Arc
(This : access Measure_Box;
Arc : in Arc_Box_Access) is
begin
This.Arc := Arc;
end Set_Arc;
function Get_Arc
(This : access Measure_Box)
return Arc_Box_Access is
begin
return This.Arc;
end Get_Arc;
function Get_Chords
(This : access Measure_Box)
return Chord_List_Access is
begin
return This.Chords;
end Get_Chords;
procedure Set_Barline
(This : access Measure_Box;
Barline : in Bar_Style_Enum) is
begin
This.Barline := Barline;
end Set_Barline;
function Get_Barline
(This : access Measure_Box)
return Bar_Style_Enum is
begin
return This.Barline;
end Get_Barline;
procedure Add_Time
(This : access Measure_Box;
Add : access Time_Box) is
begin
Time_Lists.Push(This.Times, Time_Box_Access(Add));
end Add_Time;
procedure Add_Chord
(This : access Measure_Box;
Add : access Chord_Box) is
begin
Chord_Lists.Push(This.Chords, Chord_Box_Access(Add));
end Add_Chord;
procedure Layout
(This : access Measure_Box;
Font : access Font_Loader)
is
Space : constant Real := 50.0;
Cursor : Vector;
use Time_Lists;
Time : Time_Box_Access;
use Chord_Lists;
Chord : Chord_Box_Access;
begin
if not Quiet then Debug("preparing measure layout"); end if;
Cursor := (0.0, 0.0);
This.Minimum_Width := 0.0;
This.Optimum_Width := 0.0;
if This.Clef /= null then
Layout(This.Clef, Font);
Cursor.X := Cursor.X + Space;
Cursor.X := Cursor.X - Get_Left(This.Clef);
Set_Center(This.Clef, Cursor);
Cursor.X := Cursor.X + Get_Right(This.Clef);
Cursor.X := Cursor.X + Space;
Add_Width(This, This.Clef);
Max_Bounds(This, This.Clef);
end if;
if This.Key /= null then
Layout(This.Key, Font);
Cursor.X := Cursor.X + Space;
Cursor.X := Cursor.X - Get_Left(This.Key);
Set_Center(This.Key, Cursor);
Cursor.X := Cursor.X + Get_Right(This.Key);
Cursor.X := Cursor.X + Space;
Add_Width(This, This.Key);
Max_Bounds(This, This.Key);
end if;
Reset(This.Times);
while Next(This.Times) loop
Time := Current(This.Times);
Layout(Time, Font);
Cursor.X := Cursor.X + Space;
Cursor.X := Cursor.X - Get_Left(Time);
Set_Center(Time, Cursor);
Cursor.X := Cursor.X + Get_Right(Time);
Cursor.X := Cursor.X + Space;
Add_Width(This, Time);
Max_Bounds(This, Time);
end loop;
if This.Arc /= null then
Layout(This.Arc, Font);
Add_Width(This, This.Arc);
end if;
Reset(This.Chords);
while Next(This.Chords) loop
Chord := Current(This.Chords);
Layout(Chord, Font);
Cursor.X := Cursor.X + Space;
Cursor.X := Cursor.X - Get_Left(Chord);
Set_Center(Chord, Cursor);
Cursor.X := Cursor.X + Get_Right(Chord);
Cursor.X := Cursor.X + Space;
Add_Width(This, Chord);
Max_Bounds(This, Chord);
end loop;
case This.Barline is
when Regular =>
Cursor.X := Cursor.X + 100.0;
when Light_Light =>
Cursor.X := Cursor.X + 200.0;
when others => null;
end case;
This.Bounds.Left := 0.0;
This.Bounds.Right := Cursor.X;
end Layout;
procedure Print
(This : access Measure_Box;
To : access Printer'Class;
Center : in Vector)
is
use Chord_Lists;
use Time_Lists;
begin
if This.Clef /= null then
Print(This.Clef, To, Center + This.Center);
end if;
if This.Key /= null then
Print(This.Key, To, Center + This.Center);
end if;
if not Quiet then Debug("printing times"); end if;
Reset(This.Times);
while Next(This.Times) loop
Print(Current(This.Times), To, Center + This.Center);
end loop;
if This.Arc /= null then
Print(This.Arc, To, Center + This.Center);
end if;
if not Quiet then Debug("printing chords"); end if;
Reset(This.Chords);
while Next(This.Chords) loop
Print(Current(This.Chords), To, Center + This.Center);
end loop;
case This.Barline is
when Regular =>
Fill_Box(To, (
This.Bounds.Right - Bar_Line_Width, -200.0,
This.Bounds.Right, 200.0) + Center + This.Center, Black);
when Light_Light =>
Fill_Box(To, (
This.Bounds.Right - Bar_Line_Width - 60.0, -200.0,
This.Bounds.Right - 60.0, 200.0) + Center + This.Center, Black);
Fill_Box(To, (
This.Bounds.Right - Bar_Line_Width, -200.0,
This.Bounds.Right, 200.0) + Center + This.Center, Black);
when others => null;
end case;
end Print;
end Boxes.Measures;
|