Conoscere con le funzioni esterne di PortMidi le porte Midi disponibili nel sistema
Da Gambas-it.org - Wikipedia.
Versione del 13 gen 2024 alle 12:49 di Vuott (Discussione | contributi)
La libreria PortMidi è una libreria per la gestione in tempo reale dei dati Midi in entrata ed in uscita. Essa fa parte di un assortimento di API e librerie create per la musica e per altri media.
E' possibile con alcune funzioni esterne della libreria PortMidi conoscere i dispositivi e le porte presenti ed attivi in quel momento. Per poter ottenere ciò, è necessario aver installato nel proprio sistema la libreria condivisa: "libportmidi.so.2.0.3 ".
Di seguito viene mostrato un esempio per conoscere con le funzioni esterne della libreria PortMidi le porte Midi disponibili nel sistema:
Public Struct PmDeviceInfo structVersion As Integer interf As Pointer name As Pointer inputI As Integer outputI As Integer opened As Integer End Struct Library "libportmidi:2.0.3" ' PmError Pm_Initialize( void ) ' Library initialisation function. Private Extern Pm_Initialize() As Integer ' const char *Pm_GetErrorText( PmError errnum ) ' Translate portmidi error number into human readable message. Private Extern Pm_GetErrorText(errnum As Integer) As String ' int Pm_CountDevices (void) ' Get devices count, ids range from 0 to Pm_CountDevices()-1. Private Extern Pm_CountDevices() As Integer ' const PmDeviceInfo* Pm_GetDeviceInfo( PmDeviceID id ) ' Returns a pointer to a PmDeviceInfo structure referring to the device specified by id. Private Extern Pm_GetDeviceInfo(id As Integer) As PmDeviceInfo ' PmDeviceID Pm_GetDefaultOutputDeviceID( void ) ' Return the default device ID or pmNoDevice if there are no devices. Private Extern Pm_GetDefaultOutputDeviceID() As Integer ' PmDeviceID Pm_GetDefaultInputDeviceID( void ) ' Return the default device ID or pmNoDevice if there are no devices. Private Extern Pm_GetDefaultInputDeviceID() As Integer ' PmError Pm_Terminate( void ) ' Library termination function. Private Extern Pm_Terminate() As Integer Public Sub Main() Dim num_disp, i, d As Integer Dim info As PmDeviceInfo Dim predef As String i = Pm_Initialize() If i <> 0 Then Error.Raise("Impossibile inizializzare la libreria Libportmidi: " & Pm_GetErrorText(i)) num_disp = Pm_CountDevices() If num_disp = 0 Then Print "Nessuna porta Midi presente MIDI !" Return Else Print "\nNum. "; num_disp; " Porte MIDI rilevate:\n" Endif For i = 0 To num_disp - 1 info = Pm_GetDeviceInfo(i) If IsNull(info) Then Error.Raise("Errore alla funzione 'Pm_GetDeviceInfo()' !") predef = Null If info.outputI Then d = Pm_GetDefaultOutputDeviceID() If d = i Then predef = "(predefinita)" Print i; ": "; String@(info.interf); " "; String@(info.name); " Uscita "; predef ' Porta in "scrittura" (dispositivo esterno che scrive su di essa). Endif info = Pm_GetDeviceInfo(i) If IsNull(info) Then Error.Raise("Errore alla funzione 'Pm_GetDeviceInfo()' !") If info.inputI Then d = Pm_GetDefaultInputDeviceID() If d = i Then predef = "(predefinita)" Print i; ": "; String@(info.interf); " "; String@(info.name); " Entrata "; predef ' Porta in "lettura" (dispositivo esterno che legge da essa). Endif Next Pm_Terminate() End