Differenze tra le versioni di "Alsa e Gambas: Client e porte in Ricezione"
Da Gambas-it.org - Wikipedia.
Riga 1: | Riga 1: | ||
Per la creazione del nostro ''Client'' e delle sue porte e per consentirne il collegamento ad ALSA, nella classe secondaria CAlsa.class richiameremo e porremo sostanzialmente tutte le funzioni, la libreria e le necessarie dichiarazioni di variabili che abbiamo conosciuto nel precedente progetto per l'invio dei dati Midi: | Per la creazione del nostro ''Client'' e delle sue porte e per consentirne il collegamento ad ALSA, nella classe secondaria CAlsa.class richiameremo e porremo sostanzialmente tutte le funzioni, la libreria e le necessarie dichiarazioni di variabili che abbiamo conosciuto nel precedente progetto per l'invio dei dati Midi: | ||
− | ' ''Gambas class file'' | + | ' ''Gambas-3 class file'' |
Export | Export | ||
Riga 7: | Riga 7: | ||
Public handle As Pointer | Public handle As Pointer | ||
Private id As Integer | Private id As Integer | ||
− | |||
Private inport As Integer | Private inport As Integer | ||
− | + | Library "libasound:2" | |
− | |||
− | |||
− | |||
Const SND_SEQ_OPEN_DUPLEX As Integer = 3 | Const SND_SEQ_OPEN_DUPLEX As Integer = 3 | ||
Riga 23: | Riga 19: | ||
Const SND_SEQ_PORT_TYPE_MIDI_GENERIC As Integer = 2 | Const SND_SEQ_PORT_TYPE_MIDI_GENERIC As Integer = 2 | ||
− | + | ' ''#define SND_SEQ_PORT_TYPE_MIDI_GENERIC (1<<20)'' | |
+ | Const SND_SEQ_PORT_TYPE_APPLICATION As Integer = 1048576 | ||
Riga 37: | Riga 34: | ||
' ''int snd_seq_client_id(snd_seq_t * seq)'' | ' ''int snd_seq_client_id(snd_seq_t * seq)'' | ||
Private Extern snd_seq_client_id(seq As Pointer) As Integer | Private Extern snd_seq_client_id(seq As Pointer) As Integer | ||
+ | |||
+ | ' ''int snd_seq_connect_from(seq as pointer, myport as integer, src_client as integer, src_port as integer)'' | ||
+ | Private Extern snd_seq_connect_from(seq As Pointer, myport As Integer, src_client As Integer, src_port As Integer) As Integer | ||
Riga 44: | Riga 44: | ||
err = snd_seq_open(VarPtr(handle), "default", SND_SEQ_OPEN_DUPLEX, 0) | err = snd_seq_open(VarPtr(handle), "default", SND_SEQ_OPEN_DUPLEX, 0) | ||
printerr("Apertura di Alsa regolare !", err) | printerr("Apertura di Alsa regolare !", err) | ||
− | If err < 0 Then error.RAISE("Errore nell'apertura di ALSA !") | + | If err < 0 Then error.RAISE("Errore nell'apertura di ALSA !") ' ''gestione dell'errore'' |
snd_seq_set_client_name(handle, myname) | snd_seq_set_client_name(handle, myname) | ||
id = snd_seq_client_id(handle) | id = snd_seq_client_id(handle) | ||
− | Print "Alsa Client-ID ="; id | + | Print "Alsa Client-ID = "; id |
− | ' ''per poter leggere la propria porta viene posta con capacità "Write", ossia "scrivibile" da parte | + | ' ''per poter leggere la propria porta, essa viene posta con capacità "Write", ossia "scrivibile" da parte dell'Altro dispositivo'' |
err = snd_seq_create_simple_port(handle, "Seq-Out", SND_SEQ_PORT_CAP_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC + SND_SEQ_PORT_TYPE_APPLICATION) | err = snd_seq_create_simple_port(handle, "Seq-Out", SND_SEQ_PORT_CAP_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC + SND_SEQ_PORT_TYPE_APPLICATION) | ||
− | Print "Numero della porta input dell'applicazione | + | Print "Numero della porta input dell'applicazione = "; err |
− | If err < 0 Then error.Raise("Errore nella creazione della porta | + | If err < 0 Then error.Raise("Errore nella creazione della porta !") ' ''gestione dell'errore'' |
inport = err | inport = err | ||
− | + | err = snd_seq_connect_from(handle, inport, id, 0) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | err = snd_seq_connect_from(handle, inport, id, | ||
printerr("Subscribe inport", err) | printerr("Subscribe inport", err) | ||
− | + | If err < 0 Then error.Raise("Error subscribe input device") ' ''gestione dell'errore'' | |
− | If err < 0 Then error.Raise("Error subscribe | ||
'''End''' | '''End''' |
Versione delle 15:31, 30 ago 2011
Per la creazione del nostro Client e delle sue porte e per consentirne il collegamento ad ALSA, nella classe secondaria CAlsa.class richiameremo e porremo sostanzialmente tutte le funzioni, la libreria e le necessarie dichiarazioni di variabili che abbiamo conosciuto nel precedente progetto per l'invio dei dati Midi:
' Gambas-3 class file Export Public handle As Pointer Private id As Integer Private inport As Integer Library "libasound:2" Const SND_SEQ_OPEN_DUPLEX As Integer = 3 ' #define SND_SEQ_PORT_CAP_WRITE (1<<1) Const SND_SEQ_PORT_CAP_WRITE As Integer = 2 ' #define SND_SEQ_PORT_TYPE_MIDI_GENERIC (1<<1) Const SND_SEQ_PORT_TYPE_MIDI_GENERIC As Integer = 2 ' #define SND_SEQ_PORT_TYPE_MIDI_GENERIC (1<<20) Const SND_SEQ_PORT_TYPE_APPLICATION As Integer = 1048576 ' int snd_seq_open(snd_seq_t **seqp, const char * name, Int streams, Int mode); Private Extern snd_seq_open(Pseq 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) Private Extern snd_seq_set_client_name(seq 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) Private Extern snd_seq_create_simple_port(seq As Pointer, name As String, caps As Integer, type As Integer) As Integer ' int snd_seq_client_id(snd_seq_t * seq) Private Extern snd_seq_client_id(seq As Pointer) As Integer ' int snd_seq_connect_from(seq as pointer, myport as integer, src_client as integer, src_port as integer) Private Extern snd_seq_connect_from(seq As Pointer, myport As Integer, src_client As Integer, src_port As Integer) As Integer Public Sub alsa_open(myname As String) Dim err As Integer err = snd_seq_open(VarPtr(handle), "default", SND_SEQ_OPEN_DUPLEX, 0) printerr("Apertura di Alsa regolare !", err) If err < 0 Then error.RAISE("Errore nell'apertura di ALSA !") ' gestione dell'errore snd_seq_set_client_name(handle, myname) id = snd_seq_client_id(handle) Print "Alsa Client-ID = "; id ' per poter leggere la propria porta, essa viene posta con capacità "Write", ossia "scrivibile" da parte dell'Altro dispositivo err = snd_seq_create_simple_port(handle, "Seq-Out", SND_SEQ_PORT_CAP_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC + SND_SEQ_PORT_TYPE_APPLICATION) Print "Numero della porta input dell'applicazione = "; err If err < 0 Then error.Raise("Errore nella creazione della porta !") ' gestione dell'errore inport = err err = snd_seq_connect_from(handle, inport, id, 0) printerr("Subscribe inport", err) If err < 0 Then error.Raise("Error subscribe input device") ' gestione dell'errore End
Quindi inseriremo le funzioni per la gestione degli errori:
### GESTIONE DELL'ERRORE ### Private Extern snd_strerror(err As Integer) As Pointer Public Sub errmsg(err As Integer) As String Return String@(snd_strerror(err)) End Private Sub printerr(operation As String, err As Integer) If err < 0 Then Print operation; ": err="; err; " ("; errmsg(err); ")" End
<< Pagina in costruzione >>