with Text_Io;
use Text_Io;
with Glib;
with Gtk.Scrolled_Window;
with Gtk.Label;
with Gtk.Combo_Box;
with Gtk.Dialog;
with Gtk.Main;
with Gtk.Window;
use Gtk.Window;
with Gtk.Handlers;
pragma Elaborate_All(Gtk.Handlers);
with Gtk.Enums; use Gtk.Enums;
with Gtk.Widget; use Gtk.Widget;
package body Ultrason.Mainwin is
package Simple_Window_Cb is new Gtk.Handlers.Callback (Gtk.Widget.Gtk_Widget_Record);
package Window_Cb is new Gtk.Handlers.User_Callback (Gtk.Widget.Gtk_Widget_Record, Ultra_Address_To_Access.Object_Pointer);
package Return_Window_Cb is new Gtk.Handlers.User_Return_Callback (Gtk.Widget.Gtk_Widget_Record, Boolean, Ultra_Address_To_Access.Object_Pointer);
procedure Exit_Main (Object : access Gtk.Widget.Gtk_Widget_Record'Class;
User_Data : Ultra_Address_To_Access.Object_Pointer);
-- Callbacks when the main window is killed
function Delete_Event
(Object : access Gtk_Widget_Record'Class;
User_Data : Ultra_Address_To_Access.Object_Pointer) return Boolean;
procedure Start (Object : access Gtk_Widget_Record'Class;
User_Data : Ultra_Address_To_Access.Object_Pointer) is
pragma Unreferenced (Object);
begin
User_data.all.Process.Start;
end Start;
procedure Stop (Object : access Gtk_Widget_Record'Class;
User_Data : Ultra_Address_To_Access.Object_Pointer) is
pragma Unreferenced (Object);
begin
User_data.all.Process.Stop;
end Stop;
procedure Plug_Changed (Object : access Gtk_Widget_Record'Class;
User_Data : Ultra_Address_To_Access.Object_Pointer) is
Plug_Id : constant Natural := Natural(Gtk.Combo_Box.Get_Active(Gtk.Combo_Box.Gtk_Combo_Box(Object)));
Plug_Num : Positive := 1;
begin
Plug_Num := Integer'Value(Gtk.Combo_Box.Get_Active_Text(Gtk.Combo_Box.Gtk_Combo_Box(Object))(1..2));
case Plug_Id is
when 0 =>
null;
when 1 =>
User_Data.all.Tracks(Plug_Num) := new Tempo_Generator_Type;
when 2 =>
User_Data.all.Tracks(Plug_Num) := new Voices_2_Generator_Type;
when others =>
null;
end case;
end Plug_Changed;
package Plug_Cb is new Gtk.Handlers.User_Callback (Gtk.Widget.Gtk_Widget_Record, Generator_access);
procedure Plug_Edit (Object : access Gtk_Widget_Record'Class;
User_Data : Generator_Access) is
begin
Text_Io.Put_Line("Plug_edit" );
end Plug_Edit;
-----------------
-- Exit_Main --
-----------------
use Ultra_Address_To_Access;
procedure Exit_Main (Object : access Gtk_Widget_Record'Class;
User_Data : Ultra_Address_To_Access.Object_Pointer) is
pragma Unreferenced (Object);
begin
null; -- Finalization;
User_data.all.Process.Halt;
Destroy (Object);
Gtk.Main.Main_Quit;
end Exit_Main;
------------------
-- Delete_Event --
------------------
function Delete_Event
(Object : access Gtk_Widget_Record'Class;
User_Data : Ultra_Address_To_Access.Object_Pointer) return Boolean
is
Dialog : Gtk.Dialog.Gtk_Dialog;
Yes : Gtk.Widget.Gtk_Widget;
No : Gtk.Widget.Gtk_Widget;
pragma Unreferenced(User_Data);
begin
loop
Gtk.Dialog.Gtk_New(Dialog, "Quit ?", Gtk.Window.Gtk_Window(Object), Gtk.dialog.modal);
Yes := Gtk.Dialog.Add_Button(Dialog, "Yes", Gtk.Dialog.Gtk_Response_Yes);
No := Gtk.Dialog.Add_Button(Dialog, "No", Gtk.Dialog.Gtk_Response_No);
case Gtk.Dialog.Run(Dialog) is
when Gtk.Dialog.Gtk_Response_Yes =>
Gtk.Dialog.Destroy(Dialog);
Gtk.Main.Main_Quit;
return False;
when Gtk.Dialog.Gtk_Response_No =>
Gtk.Dialog.Destroy(Dialog);
return True;
when others =>
Gtk.Dialog.Destroy(Dialog);
end case;
end loop;
return True;
end Delete_Event;
procedure Main_Quit (Action : in System.Address;
Main_Window : in System.Address);
pragma Convention (C, Main_Quit);
-- Called when Quit actions has been selected.
procedure Main_Quit (Action : in System.Address;
Main_Window : in System.Address) is
Dialog : Gtk.Dialog.Gtk_Dialog;
Yes : Gtk.Widget.Gtk_Widget;
No : Gtk.Widget.Gtk_Widget;
Window : Gtk.Window.Gtk_Window;
begin
Window := To_Pointer(Main_Window).all.Window;
if Window = null then
return;
end if;
loop
Gtk.Dialog.Gtk_New(Dialog, "Quit ?", window, Gtk.dialog.modal);
Yes := Gtk.Dialog.Add_Button(Dialog, "Yes", Gtk.Dialog.Gtk_Response_Yes);
No := Gtk.Dialog.Add_Button(Dialog, "No", Gtk.Dialog.Gtk_Response_No);
case Gtk.Dialog.Run(Dialog) is
when Gtk.Dialog.Gtk_Response_Yes =>
Gtk.Dialog.Destroy(Dialog);
null; --Os_Finalization;
To_Pointer(Main_Window).all.Process.Halt;
Gtk.Main.Main_Quit;
exit;
when Gtk.Dialog.Gtk_Response_No =>
Gtk.Dialog.Destroy(Dialog);
exit;
when others =>
Gtk.Dialog.Destroy(Dialog);
end case;
end loop;
end Main_Quit;
procedure Initialize (Mainwin : in out Ultra_Address_To_Access.Object_Pointer) is
Plug_Box : Gtk.Box.Gtk_Hbox;
Combo : Gtk.Combo_Box.Gtk_Combo_Box;
Button : Gtk.Button.Gtk_Button;
Label : Gtk.Label.Gtk_Label;
Scrolled : Gtk.Scrolled_Window.Gtk_Scrolled_Window;
Plug_List: Gtk.Box.Gtk_Vbox;
begin
-- New Object. --
Mainwin := new Mainwin_Record;
-- Process ini. --
Mainwin.Process.Initialize;
-- New Window. --
Gtk.Window.Gtk_New (Mainwin.window);
Gtk.Window.Set_Title(Mainwin.window, "Ultrason 2015 MIDI Composer" );
Gtk.Window.Set_Position(Mainwin.Window, Win_Pos_Center);
Gtk.Window.Set_Default_Size(Mainwin.Window, 300, 200);
-- New Vbox. --
Gtk.Box.Gtk_New_Vbox (Mainwin.Mainbox, False, 0);
-- Exit connect. --
Window_Cb.Connect (Mainwin.window, "destroy",
Window_Cb.To_Marshaller (Exit_Main'Access),
Mainwin);
-- Delete connect. --
Return_Window_Cb.Connect (Mainwin.window, "delete_event",
Return_Window_Cb.To_Marshaller (Delete_Event'Access),
Mainwin);
-- Start button.--
Gtk.Button.Gtk_New(Mainwin.Start_Button, "Start" );
Window_Cb.Connect (Mainwin.Start_Button, "clicked",
Window_Cb.To_Marshaller (Start'Access),
Mainwin);
-- Stop button. --
Gtk.Button.Gtk_New(Mainwin.Stop_Button, "Stop" );
Window_Cb.Connect (Mainwin.Stop_Button, "clicked",
Window_Cb.To_Marshaller (Stop'Access),
Mainwin);
-- New Hbox for Tools. --
Gtk.Box.Gtk_New_Hbox (Mainwin.Tools_Box, False, 1);
Gtk.Box.Pack_Start(Mainwin.Tools_Box, Mainwin.Start_Button, False, True);
Gtk.Box.Pack_start(Mainwin.Tools_Box, Mainwin.Stop_Button, False, True);
-- Plug-in list edit. --
Gtk.Scrolled_Window.Gtk_New(Scrolled);
Gtk.Box.Gtk_New_Vbox(Plug_List, False, 1);
for I in Mainwin.Tracks'Range loop
Gtk.Box.Gtk_New_Hbox(Plug_Box);
Gtk.Label.Gtk_New(Label, Positive'Image(I));
Gtk.Combo_Box.Gtk_New_Text(Combo);
Gtk.Combo_Box.insert_Text(Combo, 0, Positive'Image(I) & " Unused" );
Gtk.Combo_Box.insert_Text(Combo, 1, Positive'Image(I) & " Tempo Sync" );
Gtk.Combo_Box.insert_Text(Combo, 2, Positive'Image(I) & " 2 voices generator" );
Gtk.Combo_Box.Set_Active(Combo, 0);
Window_Cb.Connect (Combo, "changed",
Window_Cb.To_Marshaller (Plug_Changed'Access),
Mainwin);
Gtk.Button.Gtk_New(Button, "Edit" );
Plug_Cb.Connect (button, "clicked",
Plug_Cb.To_Marshaller (Plug_edit'Access),
Mainwin.Tracks(I));
Gtk.Box.Pack_Start(Plug_Box, Label, False, True);
Gtk.Box.Pack_Start(Plug_Box, Combo, False, True);
Gtk.Box.Pack_Start(Plug_Box, Button, False, True);
Gtk.Box.Pack_Start(Plug_List, Plug_Box, false, false);
end loop;
Gtk.Scrolled_Window.Add_With_Viewport(Scrolled, Plug_List);
-- Main pack. --
Gtk.Box.Pack_Start(Mainwin.Mainbox, scrolled, True, True);
Gtk.Box.Pack_Start(Mainwin.Mainbox, Mainwin.Tools_Box, false, false);
Gtk.Window.Add(Mainwin.Window, Mainwin.Mainbox);
-- Show all window.
Gtk.Window.Show_All (Mainwin.window);
end Initialize;
task body Ultraprocess is
End_Of_Task : Boolean := False;
begin
accept Initialize do
null;
end Initialize;
while not End_Of_Task loop
loop
select
accept Start;
for I in Mainwin.Tracks'Range loop
if Mainwin.Tracks(I) /= null then
Mainwin.Tracks(I).Track.Start;
end if;
end loop;
exit;
or
accept Stop;
or
accept Halt;
End_Of_Task := True;
exit;
end select;
end loop;
while not End_Of_Task loop
select
accept Start;
or
accept Stop;
for I in Mainwin.Tracks'Range loop
if Mainwin.Tracks(I) /= null then
Mainwin.Tracks(I).Track.Stop;
end if;
end loop;
exit;
or
accept Halt;
End_Of_Task := True;
exit;
end select;
end loop;
end loop;
for I in Mainwin.Tracks'Range loop
if Mainwin.Tracks(I) /= null then
Mainwin.Tracks(I).Track.Halt;
end if;
end loop;
end Ultraprocess;
task body Gen_Track is
End_Of_Task : Boolean := False;
begin
while not End_Of_Task loop
loop
select
accept Start;
exit;
or
accept Stop;
or
accept Halt;
End_Of_Task := True;
exit;
end select;
end loop;
if not End_Of_Task then
accept Run;
end if;
while not End_Of_Task loop
select
accept Start;
or
accept Stop;
exit;
or
accept Halt;
End_Of_Task := True;
exit;
end select;
end loop;
if not End_Of_Task then
accept Suspend;
end if;
end loop;
accept Quit;
end Gen_Track;
task body Tempo_Sync is
End_Of_Task : Boolean := False;
begin
while not End_Of_Task loop
loop
select
Gen.Track.Quit;
End_Of_Task := True;
exit;
or
delay 0.1;
select
Gen.Track.Run;
exit;
or
delay 0.0;
end select;
end select;
end loop;
while not End_Of_Task loop
select
Gen.Track.Quit;
End_Of_Task := True;
exit;
else
select
Gen.Track.Suspend;
exit;
else
delay 0.25;
Text_Io.Put("Tempo" );
end select;
end select;
end loop;
end loop;
end Tempo_Sync;
task body Voices_2_Process is
End_Of_Task : Boolean := False;
begin
while not End_Of_Task loop
loop
select
Gen.Track.Quit;
End_Of_Task := True;
exit;
or
delay 0.1;
select
Gen.Track.Run;
exit;
or
delay 0.0;
end select;
end select;
end loop;
while not End_Of_Task loop
select
Gen.Track.Quit;
End_Of_Task := True;
exit;
else
select
Gen.Track.Suspend;
exit;
else
delay 0.5;
Text_Io.Put("2 voices generator" );
end select;
end select;
end loop;
end loop;
end Voices_2_Process;
end Ultrason.Mainwin;