[01;34mwith[m Ada[31m.[mInteger_Text_Io[31m;[m
   
[01;34mwith[m Ada[31m.[mText_Io[31m;[m
[01;34muse[m Ada[31m;[m


[01;34mwith[m Libsens[31m.[mMIDI[31m.[mPorttime[31m;[m
[01;34muse[m Libsens[31m.[mMIDI[31m.[mPorttime[31m;[m

[01;34mpackage[m [01;34mbody[m Libsens[31m.[mMIDI[31m.[mDevices [01;34mis[m   
   
      [01;34muse[m ErrorText_Conversion[31m,[m DeviceInfo_Conversion[31m;[m
   [01;34mprocedure[m [01;30mInitialize[m [31m([mDevice [31m:[m [01;34min[m [01;34mout[m Device_Type[31m;[m Mode [31m:[m [01;34min[m Mode_type[31m)[m [01;34mis[m
      
   [01;34mbegin[m
      [01;34mcase[m Mode [01;34mis[m
         [01;34mwhen[m MIDI_Out [31m=>[m
            Device[31m.[mThe_DeviceInfo [31m:=[m [01;34mnew[m Portmidi[31m.[mDeviceInfo[31m;[m
            Device[31m.[mAddr [31m:=[m [01;34mnew[m System[31m.[mAddress[31m;[m
            [01;34mloop[m
               [01;34mbegin[m        
		  Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"Select output device :"[m [31m);[m
		  Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"ID, Name"[m [31m);[m
		  [01;34mfor[m I [01;34min[m [35m0[m[31m..[mPortmidi[31m.[mPm_CountDevices[31m-[m[35m1[m [01;34mloop[m
		     [01;34mdeclare[m
			Name [31m:[m Portmidi[31m.[mT_ErrorText[31m;[m
		     [01;34mbegin[m
			Device[31m.[mThe_DeviceInfo[31m.[m[01;34mall[m [31m:=[m
			  [01;30mTo_pointer[m[31m([mPortmidi[31m.[m[01;30mPm_GetDeviceInfo[m[31m([mI[31m)).[m[01;34mall[m[31m;[m
			[01;34mif[m Device[31m.[mThe_Deviceinfo[31m.[mOutput [31m=[m [35m1[m [01;34mthen[m
			   Name [31m:=[m [01;30mTo_Pointer[m[31m([mDevice[31m.[mThe_Deviceinfo[31m.[mname[31m).[m[01;34mall[m[31m;[m
			   Text_Io[31m.[m[01;30mPut_Line[m[31m([m[32mInteger[m'[01;30mImage[m[31m([mI[31m)[m [31m&[m [31m", "[m [31m&[m Interfaces[31m.[mC[31m.[m[01;30mTo_Ada[m[31m([mName[31m));[m
			[01;34mend[m [01;34mif[m[31m;[m
		     [01;34mend[m[31m;[m
		  [01;34mend[m [01;34mloop[m[31m;[m
		  Text_Io[31m.[m[01;30mPut[m[31m([m[31m"Entre device ID : "[m [31m);[m
		  Integer_Text_Io[31m.[m[01;30mGet[m[31m([mDevice[31m.[mId[31m);[m
		  Device[31m.[mThe_DeviceInfo[31m.[m[01;34mall[m [31m:=[m
		    [01;30mTo_pointer[m[31m([mPortmidi[31m.[m[01;30mPm_GetDeviceInfo[m[31m([mDevice[31m.[mid[31m)).[m[01;34mall[m[31m;[m
		  [01;34mif[m Device[31m.[mThe_Deviceinfo[31m.[mOutput [31m=[m [35m1[m [01;34mThen[m
		     [01;34mdeclare[m
			Name [31m:[m Portmidi[31m.[mT_ErrorText[31m;[m
		     [01;34mbegin[m
			Device[31m.[mInitialized [31m:=[m True[31m;[m
			
			Device[31m.[mMode [31m:=[m MIDI_Out[31m;[m
			Name [31m:=[m [01;30mTo_Pointer[m[31m([mDevice[31m.[mThe_Deviceinfo[31m.[mname[31m).[m[01;34mall[m[31m;[m
			Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"Your selected device :"[m [31m);[m
			Text_Io[31m.[m[01;30mPut[m[31m([mInterfaces[31m.[mC[31m.[m[01;30mTo_Ada[m[31m([mName[31m));[m        
		     [01;34mend[m[31m;[m
		     [01;34mexit[m[31m;[m
		  [01;34melse[m
		     Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"!! ********************** !!"[m [31m);[m
		     Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"!! Device not initialized !!"[m [31m);[m
		     Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"!! ********************** !!"[m [31m);[m
		  [01;34mend[m [01;34mif[m[31m;[m
		  
               [01;34mexception[m
		  [01;34mwhen[m Text_Io[31m.[mEnd_Error [31m=>[m
		     [01;34mreturn[m[31m;[m
               [01;34mend[m[31m;[m
            [01;34mend[m [01;34mloop[m[31m;[m            
         [01;34mwhen[m MIDI_In [31m=>[m
            Device[31m.[mThe_DeviceInfo [31m:=[m [01;34mnew[m Portmidi[31m.[mDeviceInfo[31m;[m
            Device[31m.[mAddr [31m:=[m [01;34mnew[m System[31m.[mAddress[31m;[m
	    
            [01;34mloop[m
               [01;34mbegin[m        
		  Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"Select input device :"[m [31m);[m
		  Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"ID, Name"[m [31m);[m
		  [01;34mfor[m I [01;34min[m [35m0[m[31m..[mPortmidi[31m.[mPm_CountDevices[31m-[m[35m1[m [01;34mloop[m
		     [01;34mdeclare[m
			Name [31m:[m Portmidi[31m.[mT_ErrorText[31m;[m
		     [01;34mbegin[m
			Device[31m.[mThe_DeviceInfo[31m.[m[01;34mall[m [31m:=[m
			  [01;30mTo_pointer[m[31m([mPortmidi[31m.[m[01;30mPm_GetDeviceInfo[m[31m([mI[31m)).[m[01;34mall[m[31m;[m
			[01;34mif[m Device[31m.[mThe_Deviceinfo[31m.[mInput [31m=[m [35m1[m [01;34mthen[m
			   Name [31m:=[m [01;30mTo_Pointer[m[31m([mDevice[31m.[mThe_Deviceinfo[31m.[mname[31m).[m[01;34mall[m[31m;[m
			   Text_Io[31m.[m[01;30mPut_Line[m[31m([m[32mInteger[m'[01;30mImage[m[31m([mI[31m)[m [31m&[m [31m", "[m [31m&[m Interfaces[31m.[mC[31m.[m[01;30mTo_Ada[m[31m([mName[31m));[m
			[01;34mend[m [01;34mif[m[31m;[m
		     [01;34mend[m[31m;[m
		  [01;34mend[m [01;34mloop[m[31m;[m
		  Text_Io[31m.[m[01;30mPut[m[31m([m[31m"Entre device ID : "[m [31m);[m
		  Integer_Text_Io[31m.[m[01;30mGet[m[31m([mDevice[31m.[mId[31m);[m
		  Device[31m.[mThe_DeviceInfo[31m.[m[01;34mall[m [31m:=[m
		    [01;30mTo_pointer[m[31m([mPortmidi[31m.[m[01;30mPm_GetDeviceInfo[m[31m([mDevice[31m.[mid[31m)).[m[01;34mall[m[31m;[m
		  [01;34mif[m Device[31m.[mThe_Deviceinfo[31m.[mInput [31m=[m [35m1[m [01;34mThen[m
		     [01;34mdeclare[m
			Name [31m:[m Portmidi[31m.[mT_ErrorText[31m;[m
		     [01;34mbegin[m            
			Device[31m.[mInitialized [31m:=[m True[31m;[m
			Device[31m.[mMode [31m:=[m MIDI_In[31m;[m
			Name [31m:=[m [01;30mTo_Pointer[m[31m([mDevice[31m.[mThe_Deviceinfo[31m.[mname[31m).[m[01;34mall[m[31m;[m
			Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"Your selected device :"[m [31m);[m
			Text_Io[31m.[m[01;30mPut[m[31m([mInterfaces[31m.[mC[31m.[m[01;30mTo_Ada[m[31m([mName[31m));[m        
		     [01;34mend[m[31m;[m
		     [01;34mexit[m[31m;[m
		  [01;34melse[m
		     Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"!! ********************** !!"[m [31m);[m
		     Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"!! Device not initialized !!"[m [31m);[m
		     Text_Io[31m.[m[01;30mPut_Line[m[31m([m[31m"!! ********************** !!"[m [31m);[m
		  [01;34mend[m [01;34mif[m[31m;[m
		  
               [01;34mexception[m
		  [01;34mwhen[m Text_Io[31m.[mEnd_Error [31m=>[m
		     [01;34mreturn[m[31m;[m
               [01;34mend[m[31m;[m
            [01;34mend[m [01;34mloop[m[31m;[m            
      [01;34mend[m [01;34mcase[m[31m;[m
   [01;34mend[m Initialize[31m;[m
   
   [01;34mfunction[m  [01;30mInitialized[m[31m([mDevice [31m:[m [01;34min[m     Device_Type[31m)[m [01;34mreturn[m [32mBoolean[m [01;34mis[m
   [01;34mbegin[m
      [01;34mreturn[m Device[31m.[mInitialized[31m;[m
   [01;34mend[m Initialized[31m;[m
   
   [01;34mprocedure[m [01;30mOpen[m       [31m([mDevice [31m:[m [01;34min[m [01;34mout[m Device_Type[31m)[m [01;34mis[m
      
      Pm_Error   [31m:[m PmError[31m;[m
      Time_Proc  [31m:[m [01;34mconstant[m Porttime[31m.[mTime_Access [31m:=[m Pt_Time'[01;34mAccess[m[31m;[m
      Time_Info  [31m:[m System[31m.[mAddress[31m;[m
      Buffer [31m:[m [01;34mconstant[m [32mInteger[m [31m:=[m [35m4096[m[31m;[m
      latency    [31m:[m [01;34mconstant[m Long_Integer [31m:=[m [35m0[m[31m;[m      
   [01;34mbegin[m
      [01;34mif[m [01;34mnot[m [01;30mInitialized[m[31m([mDevice[31m)[m [01;34mthen[m
	 [01;34mraise[m Not_Initialized[31m;[m
      [01;34mend[m [01;34mif[m[31m;[m
      [01;34mcase[m Device[31m.[mMode [01;34mis[m
         
         [01;34mwhen[m MIDI_In [31m=>[m
            Pm_Error [31m:=[m [01;30mPm_OpenInput[m[31m([mDevice[31m.[mAddr[31m,[m Device[31m.[mId[31m,[m Device[31m.[mThe_DeviceInfo[31m,[m
				     buffer[31m,[m Time_Proc[31m,[m Time_Info[31m);[m
	    Pm_Error [31m:=[m [01;30mPm_SetFilter[m[31m([mDevice[31m.[mAddr[31m.[m[01;34mall[m[31m,[m Pm_Filt_Active [01;34mor[m Pm_Filt_Clock[31m);[m
         [01;34mwhen[m MIDI_Out [31m=>[m
            
            Pm_Error [31m:=[m [01;30mPm_OpenOutput[m[31m([mDevice[31m.[mAddr[31m,[m Device[31m.[mId[31m,[m Device[31m.[mThe_DeviceInfo[31m,[m
				      [35m0[m[31m,[m Time_Proc[31m,[m Time_Info[31m,[m Latency[31m);[m
      [01;34mend[m [01;34mcase[m[31m;[m
   [01;34mend[m Open[31m;[m
   
   
   [01;34mprocedure[m [01;30mWrite[m      [31m([mDevice [31m:[m [01;34min[m     Device_Type[31m;[m Message [31m:[m [01;34min[m C[31m.[mLong[31m)[m [01;34mis[m
      
      Pm_Error [31m:[m PmError[31m;[m
      Pm_Event [31m:[m [01;34mconstant[m PmEvent [31m:=[m [31m([mMessage[31m,[m [35m0[m[31m);[m
   [01;34mbegin[m
      [01;34mif[m [01;34mnot[m Device[31m.[mInitialized [01;34mthen[m
         [01;34mraise[m Not_Initialized[31m;[m
      [01;34mend[m [01;34mif[m[31m;[m
      [01;34mif[m Device[31m.[mMode [31m/=[m MIDI_Out [01;34mthen[m
         [01;34mraise[m Mode_Error[31m;[m
      [01;34mend[m [01;34mif[m[31m;[m      
      Pm_Error [31m:=[m [01;30mPm_Write[m[31m([mDevice[31m.[mAddr[31m.[m[01;34mall[m[31m,[m Pm_Event[31m,[m [35m1[m[31m);[m
   [01;34mend[m Write[31m;[m
   
      
   [01;34mprocedure[m [01;30mRead[m       [31m([mDevice [31m:[m [01;34min[m     Device_Type[31m;[m Message [31m:[m [01;34mout[m C[31m.[mLong[31m)[m [01;34mis[m
      Pm_Error [31m:[m PmError [31m:=[m PmNoError[31m;[m
      Pm_Event [31m:[m [01;34mconstant[m PmEvent_Access [31m:=[m [01;34mnew[m PmEvent[31m;[m
      
   [01;34mbegin[m     
      [01;34mif[m [01;34mnot[m Device[31m.[mInitialized [01;34mthen[m
         [01;34mraise[m Not_Initialized[31m;[m
      [01;34mend[m [01;34mif[m[31m;[m
      [01;34mif[m Device[31m.[mMode [31m/=[m MIDI_In [01;34mthen[m
         [01;34mraise[m MODE_Error[31m;[m
      [01;34mend[m [01;34mif[m[31m;[m
      Message [31m:=[m [35m0[m[31m;[m
      [01;34mloop[m
	 
   	 Pm_Error [31m:=[m [01;30mPm_Poll[m[31m([mDevice[31m.[mAddr[31m.[m[01;34mall[m[31m);[m      	 
   	 [01;34mif[m Pm_Error [31m/=[m PmNoError [01;34mthen[m
   	    Pm_Error [31m:=[m [01;30mPm_Read[m[31m([mDevice[31m.[mAddr[31m.[m[01;34mAll[m[31m,[m Pm_Event[31m,[m [35m1[m[31m);[m            	    		  	       		  	    	    
   	 [01;34melse[m
   	    [01;34mexit[m[31m;[m
   	 [01;34mend[m [01;34mif[m[31m;[m
      [01;34mend[m [01;34mloop[m[31m;[m	   
      [01;34mloop[m
   	 Pm_Error [31m:=[m [01;30mPm_Poll[m[31m([mDevice[31m.[mAddr[31m.[m[01;34mall[m[31m);[m                  
   	 [01;34mif[m Pm_Error [31m/=[m Pmnoerror  [01;34mthen[m	    	    	    
   	    Pm_Error [31m:=[m [01;30mPm_Read[m[31m([mDevice[31m.[mAddr[31m.[m[01;34mAll[m[31m,[m Pm_Event[31m,[m [35m1[m[31m);[m           
   	    [01;34mif[m Pm_Error [31m/=[m Pmnoerror [01;34mthen[m
   	       Message [31m:=[m Pm_Event[31m.[mMessage[31m;[m	    	    	       	 
   	       [01;34mreturn[m[31m;[m
   	    [01;34mend[m [01;34mif[m[31m;[m	 
   	 [01;34mend[m [01;34mif[m[31m;[m      
   	 [01;34mdelay[m [35m0.0005[m[31m;[m
      [01;34mend[m [01;34mloop[m[31m;[m
   [01;34mend[m Read[31m;[m
   
   [01;34mprocedure[m [01;30mClose[m      [31m([mDevice [31m:[m [01;34min[m [01;34mout[m Device_Type[31m)[m [01;34mis[m
      Pm_Error [31m:[m PmError[31m;[m
   [01;34mbegin[m      
      Pm_Error [31m:=[m [01;30mPm_Close[m[31m([mDevice[31m.[mAddr[31m.[m[01;34mall[m[31m);[m      
   [01;34mend[m Close[31m;[m
   
   [01;34mfunction[m [01;30mName[m[31m([mDevice [31m:[m [01;34min[m Device_Type[31m)[m [01;34mreturn[m [32mString[m [01;34mis[m
   [01;34mbegin[m
      [01;34mreturn[m C[31m.[m[01;30mTo_Ada[m[31m([m[01;30mTo_Pointer[m[31m([mDevice[31m.[mThe_Deviceinfo[31m.[mname[31m).[m[01;34mall[m[31m);[m
   [01;34mend[m Name[31m;[m
   Pm_Error [31m:[m PmError[31m;[m
[01;34mbegin[m      
   Pm_Error [31m:=[m Pm_Initialize[31m;[m

[01;34mend[m Libsens[31m.[mMIDI[31m.[mDevices[31m;[m
