vamos de nuevo con la... MIDI-mania
Este código muestra los Client y las puertas MIDI actualmente activos del sistema ALSA:
Private seq As Pointer
Library "libasound:2.0.0"
Private Const SND_SEQ_OPEN_DUPLEX As Integer = 3
' const char * snd_strerror(int errnum)
' Returns the message for an error code.
Private Extern snd_strerror(errnum As Integer) As String
' int snd_seq_open (snd_seq_t **handle, const char *name, int streams, int mode)
' Open the ALSA sequencer.
Private Extern snd_seq_open(handle As Pointer, name As String, streams As Integer, mode As Integer) As Integer
' int snd_seq_set_client_name(snd_seq_t* seq, const char* name)
' Set client name.
Private Extern snd_seq_set_client_name(handle As Pointer, name As String) As Integer
' int snd_seq_client_info_malloc (snd_seq_client_info_t **ptr)
' Allocate an empty snd_seq_client_info_t using standard malloc
Private Extern snd_seq_client_info_malloc(ptr As Pointer) As Integer
' int snd_seq_port_info_malloc (snd_seq_port_info_t **ptr)
' Allocate an empty snd_seq_port_info_t using standard malloc
Private Extern snd_seq_port_info_malloc(ptr As Pointer) As Integer
' void snd_seq_client_info_set_client (snd_seq_client_info_t *info, int client)
' Set the client id of a client_info container.
Private Extern snd_seq_client_info_set_client(snd_seq_client_info_t As Pointer, clientI As Integer)
' int snd_seq_query_next_client (snd_seq_t *handle, snd_seq_client_info_t *info)
' Query the next client.
Private Extern snd_seq_query_next_client(handle As Pointer, snd_seq_client_info_t As Pointer) As Integer
' int snd_seq_client_info_get_client (const snd_seq_client_info_t *info)
' Get client id of a client_info container.
Private Extern snd_seq_client_info_get_client(snd_seq_client_info_t As Pointer) As Integer
' void snd_seq_port_info_set_client (snd_seq_port_info_t *info, int client)
' Set the client id of a port_info container.
Private Extern snd_seq_port_info_set_client(snd_seq_port_info_t As Pointer, clientI As Integer)
' void snd_seq_port_info_set_port (snd_seq_port_info_t *info, int port)
' Set the port id of a port_info container.
Private Extern snd_seq_port_info_set_port(snd_seq_port_info_t As Pointer, portI As Integer)
' int snd_seq_query_next_port (snd_seq_t *handle, snd_seq_port_info_t *info)
' Query the next matching port.
Private Extern snd_seq_query_next_port(handle As Pointer, snd_seq_port_info_t As Pointer) As Integer
' int snd_seq_port_info_get_client (const snd_seq_port_info_t *info)
' Get client id of a port_info container.
Private Extern snd_seq_port_info_get_client(snd_seq_port_info_t As Pointer) As Integer
' int snd_seq_port_info_get_port (const snd_seq_port_info_t *info)
' Get port id of a port_info container.
Private Extern snd_seq_port_info_get_port(snd_seq_port_info_t As Pointer) As Integer
' const char * snd_seq_client_info_get_name (snd_seq_client_info_t *info)
' Get the name of a client_info container.
Private Extern snd_seq_client_info_get_name(snd_seq_client_info_t As Pointer) As String
' const char * snd_seq_port_info_get_name (const snd_seq_port_info_t *info)
' Get the name of a port_info container.
Private Extern snd_seq_port_info_get_name(snd_seq_port_info_t As Pointer) As String
Public Sub Main()
Dim err As Integer
' Inicializa la libreria ALSA:
err = snd_seq_open(VarPtr(seq), "default", SND_SEQ_OPEN_DUPLEX, 0)
gest_err_Alsa(err, "inizializar el subsistema 'Seq' de Alsa: ")
' Impone el nombre del Client Alsa:
err = snd_seq_set_client_name(seq, "Muestra_Portas_MIDI")
gest_err_Alsa(err, "asignar un nombre a el Client aplicativo de ALSA: ")
lista_puertas()
End
Private Procedure lista_puertas()
Dim cinfo, pinfo As Pointer
Dim client As Integer
snd_seq_client_info_malloc(VarPtr(cinfo))
snd_seq_port_info_malloc(VarPtr(pinfo))
Print "=== Client actualmente activos==="
snd_seq_client_info_set_client(cinfo, -1)
While snd_seq_query_next_client(seq, cinfo) >= 0
client = snd_seq_client_info_get_client(cinfo)
snd_seq_port_info_set_client(pinfo, client)
snd_seq_port_info_set_port(pinfo, -1)
While snd_seq_query_next_port(seq, pinfo) >= 0
Print "\nPuerta: "; snd_seq_port_info_get_client(pinfo); ":"; snd_seq_port_info_get_port(pinfo)
Print "Nombre Client: "; snd_seq_client_info_get_name(cinfo)
Print "Nombre Puerta: "; snd_seq_port_info_get_name(pinfo)
Wend
Wend
End
'' Proceso de gestión de los errores de Alsa
Private Procedure gest_err_Alsa(errorAlsa As Integer, comentario As String)
If errorAlsa < 0 Then Error.Raise("Imposible " & comentario & snd_strerror(errorAlsa))
End
Library "libasound:2.0.0"
Private Const SND_SEQ_OPEN_DUPLEX As Integer = 3
' const char * snd_strerror(int errnum)
' Returns the message for an error code.
Private Extern snd_strerror(errnum As Integer) As String
' int snd_seq_open (snd_seq_t **handle, const char *name, int streams, int mode)
' Open the ALSA sequencer.
Private Extern snd_seq_open(handle As Pointer, name As String, streams As Integer, mode As Integer) As Integer
' int snd_seq_set_client_name(snd_seq_t* seq, const char* name)
' Set client name.
Private Extern snd_seq_set_client_name(handle As Pointer, name As String) As Integer
' int snd_seq_client_info_malloc (snd_seq_client_info_t **ptr)
' Allocate an empty snd_seq_client_info_t using standard malloc
Private Extern snd_seq_client_info_malloc(ptr As Pointer) As Integer
' int snd_seq_port_info_malloc (snd_seq_port_info_t **ptr)
' Allocate an empty snd_seq_port_info_t using standard malloc
Private Extern snd_seq_port_info_malloc(ptr As Pointer) As Integer
' void snd_seq_client_info_set_client (snd_seq_client_info_t *info, int client)
' Set the client id of a client_info container.
Private Extern snd_seq_client_info_set_client(snd_seq_client_info_t As Pointer, clientI As Integer)
' int snd_seq_query_next_client (snd_seq_t *handle, snd_seq_client_info_t *info)
' Query the next client.
Private Extern snd_seq_query_next_client(handle As Pointer, snd_seq_client_info_t As Pointer) As Integer
' int snd_seq_client_info_get_client (const snd_seq_client_info_t *info)
' Get client id of a client_info container.
Private Extern snd_seq_client_info_get_client(snd_seq_client_info_t As Pointer) As Integer
' void snd_seq_port_info_set_client (snd_seq_port_info_t *info, int client)
' Set the client id of a port_info container.
Private Extern snd_seq_port_info_set_client(snd_seq_port_info_t As Pointer, clientI As Integer)
' void snd_seq_port_info_set_port (snd_seq_port_info_t *info, int port)
' Set the port id of a port_info container.
Private Extern snd_seq_port_info_set_port(snd_seq_port_info_t As Pointer, portI As Integer)
' int snd_seq_query_next_port (snd_seq_t *handle, snd_seq_port_info_t *info)
' Query the next matching port.
Private Extern snd_seq_query_next_port(handle As Pointer, snd_seq_port_info_t As Pointer) As Integer
' int snd_seq_port_info_get_client (const snd_seq_port_info_t *info)
' Get client id of a port_info container.
Private Extern snd_seq_port_info_get_client(snd_seq_port_info_t As Pointer) As Integer
' int snd_seq_port_info_get_port (const snd_seq_port_info_t *info)
' Get port id of a port_info container.
Private Extern snd_seq_port_info_get_port(snd_seq_port_info_t As Pointer) As Integer
' const char * snd_seq_client_info_get_name (snd_seq_client_info_t *info)
' Get the name of a client_info container.
Private Extern snd_seq_client_info_get_name(snd_seq_client_info_t As Pointer) As String
' const char * snd_seq_port_info_get_name (const snd_seq_port_info_t *info)
' Get the name of a port_info container.
Private Extern snd_seq_port_info_get_name(snd_seq_port_info_t As Pointer) As String
Public Sub Main()
Dim err As Integer
' Inicializa la libreria ALSA:
err = snd_seq_open(VarPtr(seq), "default", SND_SEQ_OPEN_DUPLEX, 0)
gest_err_Alsa(err, "inizializar el subsistema 'Seq' de Alsa: ")
' Impone el nombre del Client Alsa:
err = snd_seq_set_client_name(seq, "Muestra_Portas_MIDI")
gest_err_Alsa(err, "asignar un nombre a el Client aplicativo de ALSA: ")
lista_puertas()
End
Private Procedure lista_puertas()
Dim cinfo, pinfo As Pointer
Dim client As Integer
snd_seq_client_info_malloc(VarPtr(cinfo))
snd_seq_port_info_malloc(VarPtr(pinfo))
Print "=== Client actualmente activos==="
snd_seq_client_info_set_client(cinfo, -1)
While snd_seq_query_next_client(seq, cinfo) >= 0
client = snd_seq_client_info_get_client(cinfo)
snd_seq_port_info_set_client(pinfo, client)
snd_seq_port_info_set_port(pinfo, -1)
While snd_seq_query_next_port(seq, pinfo) >= 0
Print "\nPuerta: "; snd_seq_port_info_get_client(pinfo); ":"; snd_seq_port_info_get_port(pinfo)
Print "Nombre Client: "; snd_seq_client_info_get_name(cinfo)
Print "Nombre Puerta: "; snd_seq_port_info_get_name(pinfo)
Wend
Wend
End
'' Proceso de gestión de los errores de Alsa
Private Procedure gest_err_Alsa(errorAlsa As Integer, comentario As String)
If errorAlsa < 0 Then Error.Raise("Imposible " & comentario & snd_strerror(errorAlsa))
End