Differenze tra le versioni di "Conoscere i Client Midi di ALSA correnti attivi nel sistema"
Da Gambas-it.org - Wikipedia.
Riga 34: | Riga 34: | ||
− | + | Public Sub Main() | |
Dim err, id As Integer | Dim err, id As Integer | ||
Dim handle As Pointer | Dim handle As Pointer | ||
− | + | err = snd_seq_open(VarPtr(handle), "default", SND_SEQ_OPEN_DUPLEX, 0) | |
− | + | If err < 0 Then | |
− | + | Error.Raise("Errore nell'apertura di Alsa: " & snd_strerror(err)) | |
− | + | Else | |
− | + | Print "Apertura di Alsa: regolare" | |
− | + | Endif | |
+ | |||
+ | snd_seq_set_client_name(handle, "Vedi Client Alsa") | ||
+ | Print "Nome del programma: "; "'Vedi Client Alsa'" | ||
+ | id = snd_seq_client_id(handle) | ||
+ | Print "ID del programma: "; id | ||
− | + | err = snd_seq_create_simple_port(handle, "Porta CAlsa Out", 0, SND_SEQ_PORT_CAP_READ + SND_SEQ_PORT_CAP_SUBS_READ) | |
− | + | If err < 0 Then | |
− | + | Error.Raise("Errore nella creazione della porta di Alsa: " & snd_strerror(err)) | |
− | + | Else | |
− | + | Print "Porta del programma: "; err | |
− | + | Endif | |
− | + | ||
− | + | listaClient(handle) | |
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
<FONT color=gray>' ''Va in chiusura:''</font> | <FONT color=gray>' ''Va in chiusura:''</font> | ||
− | + | snd_seq_close(handle) | |
− | + | End | |
Riga 127: | Riga 127: | ||
− | + | Public Procedure listaClient(seq As Pointer) | |
− | + | ||
Dim client As Integer | Dim client As Integer | ||
Dim cinfo, pinfo As Pointer | Dim cinfo, pinfo As Pointer | ||
− | |||
<FONT color=gray>' <B>cinfo = Alloc(snd_seq_client_info_sizeof())</b> '' così, oppure...''</font> | <FONT color=gray>' <B>cinfo = Alloc(snd_seq_client_info_sizeof())</b> '' così, oppure...''</font> | ||
− | + | snd_seq_client_info_malloc(VarPtr(cinfo)) | |
<FONT color=gray>' <B>pinfo = Alloc(snd_seq_port_info_sizeof())</b> '' così, oppure...''</font> | <FONT color=gray>' <B>pinfo = Alloc(snd_seq_port_info_sizeof())</b> '' così, oppure...''</font> | ||
− | + | snd_seq_port_info_malloc(VarPtr(pinfo)) | |
− | + | snd_seq_client_info_set_client(cinfo, -1) ' Set the client id of a client_info container | |
+ | |||
+ | Print "\n-- Client di Alsa attivi --" | ||
− | + | 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 "\nID-CLIENT = "; snd_seq_port_info_get_client(pinfo) <FONT color=gray>' ''ID del Client''</font> | ||
+ | Print "NOME CLIENT = "; snd_seq_client_info_get_name(cinfo) <FONT color=gray>' ''Nome del Client''</font> | ||
+ | Print "PORTA = "; snd_seq_port_info_get_port(pinfo) <FONT color=gray>' ''ID della Porta''</font> | ||
+ | Print "NOME PORTA = "; snd_seq_port_info_get_name(pinfo) <FONT color=gray>' ''Nome della Porta''</font> | ||
+ | If snd_seq_client_info_get_type(cinfo) = 1 Then <FONT color=gray>' ''Tipo di Client''</font> | ||
+ | Print "TIPO CLIENT = [Client Utente]" | ||
+ | Else | ||
+ | Print "TIPO CLIENT = [Client Kernel]" | ||
+ | Endif | ||
+ | Wend | ||
+ | Wend | ||
− | + | End | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Versione attuale delle 12:54, 13 gen 2024
Le funzioni del API di ALSA consentono di individuare quali sono i correnti Client Midi attivi di Alsa, e di vederne le loro caratteristiche.
Mostriamo un possibile codice:
Library "libasound:2.0.0" private Const SND_SEQ_OPEN_DUPLEX As Integer = 3 private Const SND_SEQ_PORT_CAP_READ As Integer = 1 private Const SND_SEQ_PORT_CAP_SUBS_READ As Integer = 32 ' int snd_seq_open (snd_seq_t **handle, const char *name, int streams, int mode) ' Open the ALSA sequencer. Private Extern snd_seq_open(seqP 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(seqP As Pointer, name As String) As Integer ' int snd_seq_create_simple_port(snd_seq_t* seq, const char* name, unsigned int caps, unsigned int type) ' Create a port - simple version. Private Extern snd_seq_create_simple_port(seqP As Pointer, name As String, caps As Integer, type As Integer) As Integer ' int snd_seq_client_id(snd_seq_t * seq) ' Get the client id. Private Extern snd_seq_client_id(seqP As Pointer) As Integer ' const char * snd_strerror (int errnum) ' Returns the message for an error code. Private Extern snd_strerror(err As Integer) As Pointer ' int snd_seq_close (snd_seq_t *handle) ' Close the sequencer. Private Extern snd_seq_close(seqP As Pointer) Public Sub Main() Dim err, id As Integer Dim handle As Pointer err = snd_seq_open(VarPtr(handle), "default", SND_SEQ_OPEN_DUPLEX, 0) If err < 0 Then Error.Raise("Errore nell'apertura di Alsa: " & snd_strerror(err)) Else Print "Apertura di Alsa: regolare" Endif snd_seq_set_client_name(handle, "Vedi Client Alsa") Print "Nome del programma: "; "'Vedi Client Alsa'" id = snd_seq_client_id(handle) Print "ID del programma: "; id err = snd_seq_create_simple_port(handle, "Porta CAlsa Out", 0, SND_SEQ_PORT_CAP_READ + SND_SEQ_PORT_CAP_SUBS_READ) If err < 0 Then Error.Raise("Errore nella creazione della porta di Alsa: " & snd_strerror(err)) Else Print "Porta del programma: "; err Endif listaClient(handle) ' Va in chiusura: snd_seq_close(handle) End ' size_t snd_seq_client_info_sizeof(void) ' Get size of snd_seq_client_info_t. ' Private Extern snd_seq_client_info_sizeof() 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(cinfoP 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(cinfo As Pointer, jey 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(seq As Pointer, cinfo 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(cinfo 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(cinfo As Pointer) As String ' snd_seq_client_type_t snd_seq_client_info_get_type (const snd_seq_client_info_t *info) ' Get client type of a client_info container. Private Extern snd_seq_client_info_get_type(cinfo As Pointer) As Integer ' size_t snd_seq_port_info_sizeof(void) ' Get size of snd_seq_port_info_t. ' Private Extern snd_seq_port_info_sizeof() 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(pinfo 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(pinfoP 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(pinfo As Pointer, i As Integer) ' 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(pinfo As Pointer) As String ' 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(pinfo As Pointer) 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(pinfo As Pointer, i As Integer) 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(seq As Pointer, pinfo As Pointer) As Integer Public Procedure listaClient(seq As Pointer) Dim client As Integer Dim cinfo, pinfo As Pointer ' cinfo = Alloc(snd_seq_client_info_sizeof()) così, oppure... snd_seq_client_info_malloc(VarPtr(cinfo)) ' pinfo = Alloc(snd_seq_port_info_sizeof()) così, oppure... snd_seq_port_info_malloc(VarPtr(pinfo)) snd_seq_client_info_set_client(cinfo, -1) ' Set the client id of a client_info container Print "\n-- Client di Alsa attivi --" 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 "\nID-CLIENT = "; snd_seq_port_info_get_client(pinfo) ' ID del Client Print "NOME CLIENT = "; snd_seq_client_info_get_name(cinfo) ' Nome del Client Print "PORTA = "; snd_seq_port_info_get_port(pinfo) ' ID della Porta Print "NOME PORTA = "; snd_seq_port_info_get_name(pinfo) ' Nome della Porta If snd_seq_client_info_get_type(cinfo) = 1 Then ' Tipo di Client Print "TIPO CLIENT = [Client Utente]" Else Print "TIPO CLIENT = [Client Kernel]" Endif Wend Wend End