----------------------------------------
-- Libmy.MIDI --
----------------------------------------
-- Date : dimanche 19 février 2012,
-- 10:12:30 (UTC+0100)
-- Author : Manuel De Girardi
-- Decription: It's my MIDI lib.
----------------------------------------
with Ada.Text_Io; use Ada;
package body Libmy.MIDI.Driver.Radias is
procedure Initialize(Radias : out Radias_Type;
Keyb : Addr_Num;
Input : Addr_Num;
Output : Addr_Num) is
begin
Radias := new Radias_Device_Type;
Radias.Keyb := Keyb;
Radias.Keyb_Driver := new Keyb_Driver_Type(Radias);
Radias.Input := Input;
Radias.Input_Driver := new Input_Driver_Type(Radias);
Radias.Output := Output;
Radias.Output_Driver := new Output_Driver_Type;
Radias.Output_Driver.Set_Output(Output);
Text_Io.Put_Line("output iniitlaized" );
Radias.Radias_Driver := new Radias_Driver_Type(Radias);
Radias.Program := new Radias_Program_Type(Radias);
Radias.Global_Driver := new Global_Driver_Type(Radias);
end Initialize;
procedure Start(Radias : in Radias_Type) is
Date : Time := Clock;
begin
Radias.Output_Driver.Start;
Text_Io.Put_Line("output started" );
Radias.Global_Driver.Start(Radias.Program.Tempo, date + 1.0);
Text_Io.Put_Line("Global started" );
Radias.Radias_Driver.Start(Radias.Program.Tempo, date + 1.0);
Text_Io.Put_Line("Radias started" );
end Start;
procedure Stop(Radias : in Radias_Type) is
begin
null;
end Stop;
procedure Halt(Radias : in Radias_Type) is
begin
null;
end Halt;
task body Drums_Driver_Type is
Suspended, End_Of_Task : Boolean := False;
Message : Message_Type;
Date : Time := Clock;
begin
while not End_Of_Task loop
select
accept Start(Bpm : in Tempo_Type; Top : in Time) do
--if Timbre.Eq /= null then
-- Timbre.Eq.Eq_Driver.Start(Bpm, Top);
--end if;
--Start(Player, Bpm, Top);
Suspended := False;
Date := Top;
--Tempo := Bpm;
end Start;
or
accept Halt do
--if Timbre.Eq /= null then
-- Timbre.Eq.Eq_Driver.Halt;
--end if;
--Halt(Player);
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
delay until Date;
while not Suspended loop
select
accept Stop do
--if Timbre.Eq /= null then
-- Timbre.Eq.Eq_Driver.Stop;
--end if;
--Stop(Player);
Suspended := True;
end Stop;
or
accept Halt do
--if Timbre.Eq /= null then
-- Timbre.Eq.Eq_Driver.Halt;
--end if;
--Halt(Player);
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Receive(Message : in C.Long) do
null;
end Receive;
or
accept Receive(Chord : in MIDI_Ctrl_Type) do
--Receive(Player, Chord);
null;
end Receive;
or
delay 0.3;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put("Exception in Drums" );
end Drums_Driver_Type;
task body Synth_Driver_Type is
Suspended, End_Of_Task : Boolean := False;
Message : Message_Type;
Date : Time := Clock;
begin
while not End_Of_Task loop
select
accept Start(Bpm : in Tempo_Type; Top : in Time) do
Date := Top;
Suspended := False;
end Start;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
delay until Date;
while not Suspended loop
select
accept Stop do
Suspended := True;
end Stop;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Receive(Message : in C.Long) do
null;
end Receive;
or
accept Receive(Chord : in MIDI_Ctrl_Type) do
null;
end Receive;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put("Exception in Synth" );
end Synth_Driver_Type;
type Wave_Type is (Saw, Square, Tri, Sin, Formant,
Noise, Synth_Pcm, Drum_Pcm, Audio_In);
type Osc_Mod1_Type is (Wave, Cross, Unison, Vpm);
task body Osc1_Driver_Type is
Suspended, End_Of_Task : Boolean := False;
Message : Message_Type;
Date : Time := Clock;
Wave : Wave_Type;
Osc_Mod : Osc_Mod1_Type;
Controler_1 : Valu_Num := 0;
Controler_2 : Valu_Num := 0;
begin
while not End_Of_Task loop
select
accept Start(Bpm : in Tempo_Type; Top : in Time) do
Suspended := False;
--Tempo := Bpm;
Date := Top;
end Start;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
delay until Date;
while not Suspended loop
select
accept Stop do
Suspended := True;
end Stop;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Receive(Message : in C.Long) do
null;
end Receive;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put("Exception in Osc1" );
end Osc1_Driver_Type;
subtype Wave2_Type is Wave_Type range Saw .. Sin;
type Osc_Mod2_Type is
record
Ring : Boolean := False;
Sync : Boolean := False;
end record;
task body Osc2_Driver_Type is
Suspended, End_Of_Task : Boolean := False;
Message : Message_Type;
Date : Time := Clock;
Wave : Wave2_Type;
Osc_Mod : Osc_Mod2_Type;
Controler_1 : Valu_Num := 0;
Controler_2 : Valu_Num := 0;
begin
while not End_Of_Task loop
select
accept Start(Bpm : in Tempo_Type; Top : in Time) do
Suspended := False;
Date := Top;
--Tempo := Bpm;
end Start;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
delay until Date;
while not Suspended loop
select
accept Stop do
Suspended := True;
end Stop;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Receive(Message : in C.Long) do
null;
end Receive;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put("Exception in Osc2" );
end Osc2_Driver_Type;
task body Filters_Driver_Type is
Suspended, End_Of_Task : Boolean := False;
Message : Message_Type;
Date : Time := Clock;
begin
while not End_Of_Task loop
select
accept Start(Bpm : in Tempo_Type; Top : in Time) do
Suspended := False;
Date := Top;
--Tempo := Bpm;
end Start;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
delay until Date;
while not Suspended loop
select
accept Stop do
Suspended := True;
end Stop;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Receive(Message : in C.Long) do
null;
end Receive;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put("Exception in Filters" );
end Filters_Driver_Type;
task body Radias_Driver_Type is
The_Status : Status_Type;
The_Control : Control_Type;
Suspended, End_Of_Task : Boolean := False;
date : Time := Clock;
Message : Message_Type;
begin
while not End_Of_Task loop
select
accept Start(Bpm : in Tempo_Type; Top : in Time) do
Text_Io.Put_Line("Starting All timbres..." );
Date := Top;
--Tempo := Bpm;
Suspended := False;
end Start;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
delay until Date;
while not Suspended loop
select
accept Stop do
Text_Io.Put_Line("Stopping All timbre..." );
Text_Io.Put_Line("Driver stopped." );
Suspended := True;
end Stop;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Receive(Message : in C.Long) do
The_Status := Status(Message);
case The_Status is
when Noteon =>
null;
when Noteoff =>
null;
when others =>
The_Control := Control(Message);
end case;
end Receive;
or
accept Receive(Chord : in Score.MIDI_Score_Type;
Channel : in Chan_Num) do
null;
end Receive;
or
delay 0.00025;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put("Exception in Radias_Driver" );
end Radias_Driver_Type;
task body Input_Driver_Type is
task type T_Input(Input_address : Addr_Num) is
entry Initialize;
entry Send(Message : out C.Long);
end T_Input;
task body T_Input is
Pm_Event : PmEvent;
begin
accept Initialize;
loop
Pm_Event.Message := Read_handler(Input_address.All);
accept Send(Message : out C.Long) do
Message := Pm_Event.Message;
end Send;
end loop;
end T_Input;
The_Chord : Score.Midi_Score_Type(1..24);
The_Status : Status_Type;
Step_Time : Time := clock;
Step_Length : Duration := 0.1;
Index : Natural := 0;
Message : C.Long;
Input : T_Input(Radias.input);
End_Of_Task : Boolean := False;
begin
Input.Initialize;
Text_Io.Put_Line("Initialize input" );
while not End_Of_Task loop
select
accept Halt do
End_Of_Task := True;
end Halt;
or
delay 0.0;
end select;
select
Input.Send(Message);
Text_Io.Put("Receive message: " );
The_Status := Status(Message);
case The_Status is
when Noteon =>
if Clock < Step_Time then
if Index < 5 then
Index := Index + 1;
The_Chord(Index) :=
(Valu_Num'Value("16#" & data1(Message) & '#'),
Valu_Num'Value("16#" & data2(Message) & '#' ),
0);
end if;
else
if Index /= 0 then
Radias.Radias_Driver.Receive(The_Chord(1..Index), Channel(Message));
Index := 0;
end if;
Index := 1;
The_Chord(Index) := (Valu_Num'Value("16#" & data1(Message) & '#'),
Valu_Num'Value("16#" & data2(Message) & '#' ),
0);
Step_Time := Clock + 0.125;
end if;
when Noteoff =>
null;
when others =>
Radias.Radias_Driver.Receive(Message);
end case;
or
delay 0.1;
if Index /= 0 then
Radias.Radias_Driver.Receive(The_Chord(1..Index), Channel(message));
Index := 0;
end if;
end select;
end loop;
abort Input;
exception
when others =>
Text_Io.Put_Line("Exception in input driver" );
end Input_Driver_Type;
task body Keyb_Driver_Type is
task type T_Input(Input_address : Addr_Num) is
entry Initialize;
entry Send(Message : out C.Long);
end T_Input;
task body T_Input is
Pm_Event : PmEvent;
begin
accept Initialize;
loop
Pm_Event.Message := Read_handler(Input_address.All);
accept Send(Message : out C.Long) do
Message := Pm_Event.Message;
end Send;
end loop;
end T_Input;
The_Chord : Score.Midi_Score_Type(1..24);
The_Status : Status_Type;
Step_Time : Time := clock;
Step_Length : Duration := 0.1;
Index : Natural := 0;
Message : C.Long;
Input : T_Input(Radias.keyb);
End_Of_Task : Boolean := False;
begin
Input.Initialize;
Text_Io.Put_Line("Initialize Keyb" );
while not End_Of_Task loop
select
accept Halt do
End_Of_Task := True;
end Halt;
or
delay 0.0;
end select;
select
Input.Send(Message);
Text_Io.Put("Receive message: " );
The_Status := Status(Message);
Text_Io.Put_Line("TOTO -1.0" );
case The_Status is
when Noteon =>
Text_Io.Put_Line("TOTO -1.1" );
if Clock < Step_Time then
if Index < 5 then
Index := Index + 1;
Text_Io.Put_Line("TOTO -1.2" );
The_Chord(Index) :=
(Valu_Num'Value("16#" & data1(Message) & '#'),
Valu_Num'Value("16#" & data2(Message) & '#' ),
0);
end if;
else
Text_Io.Put_Line("TOTO -1.3" );
if Index /= 0 then
Text_Io.Put_Line("TOTO 0" );
Radias.Radias_Driver.Receive(The_Chord(1..Index), Channel(Message));
Index := 0;
end if;
Index := 1;
The_Chord(Index) := (Valu_Num'Value("16#" & data1(Message) & '#'),
Valu_Num'Value("16#" & data2(Message) & '#' ),
0);
Step_Time := Clock + 0.125;
end if;
when Noteoff =>
null;
when others =>
Text_Io.Put_Line("TOTO 1" );
Radias.Radias_Driver.Receive(Message);
end case;
or
delay 0.05;
if Index /= 0 then
Text_Io.Put_Line("TOTO 2" );
Radias.Radias_Driver.Receive(The_Chord(1..Index), Channel(message));
Index := 0;
end if;
Step_Time := Clock + 0.125;
end select;
end loop;
abort Input;
exception
when others =>
Text_Io.Put_Line("Exception in keyb driver" );
end Keyb_Driver_Type;
task body Output_Driver_Type is
task Midi_Output is
entry Set_Output(Addr : in Addr_Num);
entry Start;
entry Stop;
entry Halt;
entry Receive(Pm_Event : in PmEvent);
end Midi_Output;
task body Midi_Output is
End_Of_Task : Boolean := False;
Suspended : Boolean := True;
Output_Address : Addr_Num;
Pm_Error : PmError;
begin
while not End_Of_Task loop
select
accept Stop;
or
accept Set_Output(Addr : in Addr_Num) do
if Output_Address /= null then
Pm_Error := Portmidi.Pm_Close(Output_Address.all);
end if;
Output_Address := Addr;
end Set_Output;
or
accept Start do
Text_Io.Put_Line("running output" );
Suspended := False;
end Start;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
while not Suspended loop
select
accept Set_Output(Addr : in Addr_Num) do
if Output_Address /= null then
Pm_Error := Portmidi.Pm_Close(Output_Address.all);
end if;
Output_Address := Addr;
end Set_Output;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Stop do
Suspended := True;
end Stop;
or
accept Receive(Pm_Event : in PmEvent) do
if Output_address /= null then
Pm_Error := Pm_Write(Output_address.All, Pm_Event, 1);
end if;
end Receive;
end select;
end loop;
end loop;
end Midi_Output;
End_Of_Task : Boolean := False;
Suspended : Boolean := True;
Message : Message_Type;
Pm_Event : PmEvent;
begin
while not End_Of_Task loop
select
accept Set_Output(Addr : in Addr_Num) do
Midi_Output.Set_Output(Addr);
end Set_Output;
or
accept Start do
Midi_Output.Start;
Suspended := False;
end Start;
or
accept Halt do
Midi_Output.Halt;
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
while not Suspended loop
select
accept Set_Output(Addr : in Addr_Num) do
Midi_Output.Set_Output(Addr);
end Set_Output;
or
accept Halt do
Midi_Output.Halt;
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Stop do
Midi_Output.stop;
Text_Io.Put_Line("Stop output." );
Suspended := True;
end Stop;
or
accept Receive(Message : in Message_Type) do
Pm_Event.Message := Pm_Message(Message);
Pm_Event.PmTimestamp := Pt_time;
Midi_output.Receive(Pm_event);
end Receive;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put_line("exception in output driver." );
end Output_Driver_Type;
task body Global_Driver_Type is
Suspended, End_Of_Task : Boolean := False;
Message : Message_Type;
Date : Time := Clock;
Sync : Duration;
begin
while not End_Of_Task loop
select
accept Start(Bpm : in Tempo_Type; Top : in Time) do
Suspended := False;
--Tempo := Bpm;
Sync := duration(((60000.0/Float(Bpm))/1000.0)/24.0);
date := Top;
--PC_Timer := Top;
end Start;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
end select;
delay until Date;
while not Suspended loop
select
accept Stop do
Suspended := True;
end Stop;
or
accept Halt do
Suspended := True;
End_Of_Task := True;
end Halt;
or
accept Receive(Message : in C.Long) do
null;
end Receive;
or
delay 0.00025;
if Date <= Clock then
Date := Date + Sync;
Message := (16#F8#, 0, 0);
Radias.Output_Driver.Receive(Message);
end if;
end select;
end loop;
end loop;
exception
when others =>
Text_Io.Put("Exception in Global Driver" );
end Global_Driver_Type;
end Libmy.MIDI.Driver.Radias;