rtmidi_0.1.0_bae317e4/tests/src/tests.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
with AAA.Strings;
with Ada.Text_IO; use Ada.Text_IO;
with System.Storage_Elements; use System.Storage_Elements;

with RtMIDI; use RtMIDI;

procedure Tests is
   Test_Out : MIDI_Out := Create ("Test rtMIDI Out");
   Test_In : MIDI_In := Create ("Test rtMIDI In");

   Port_Found : Integer := -1;
begin

   Create_Virtual_Port (Test_Out, "Test output virt port");
   if Error (Test_Out) then
      raise Program_Error
        with "RtMIDI Error: '" & Error_Message (Test_Out) & "'";
   end if;

   Put_Line ("Available_Port_Count Input:" &
               Available_Port_Count (Test_In)'Img);
   for X in 1 .. Available_Port_Count (Test_In) loop
      declare
         Name : constant String := Port_Name (Test_In, X);
      begin
         if AAA.Strings.Has_Prefix (Name, "Test rtMIDI Out") then
            Port_Found := X;
            exit;
         end if;
      end;
   end loop;

   if Port_Found <= 0 then
      Put_Line ("Cannot find the port we just openned. Use default one...");
      Port_Found := 0;
   end if;

   Open_Port (Test_In, Port_Found, "Test input virt port");

   if Error (Test_In) then
      raise Program_Error
        with "RtMIDI Error: '" & Error_Message (Test_In) & "'";
   end if;

   declare
      Success : Boolean;
   begin
      Send_Message (Test_Out, (16#90#, 16#3C#, 16#40#), Success);
      if not Success then
         raise Program_Error
           with "RtMIDI Error: '" & Error_Message (Test_In) & "'";
      end if;

      delay 0.5;

      declare
         Message : constant Storage_Array := Get_Message (Test_In);
         package MIO is new Ada.Text_IO.Modular_IO (Storage_Element);
      begin
         Put ("Got message: '");
         for Elt of Message loop
            MIO.Put (Elt, Base => 16);
         end loop;
         Put_Line ("'");
      end;

   end;

   Close_Port (Test_Out);
   Close_Port (Test_In);

   Free (Test_Out);
   Free (Test_In);
end Tests;