Differenze tra le versioni di "Creare 16 Client ciascuno avente 16 porte in Uscita e 16 porte in Entrata"

Da Gambas-it.org - Wikipedia.
 
Riga 1: Riga 1:
Mostriamo un possibile codice per creare 16 Client autonomi, ciascuno avente 16 porte in Uscita e 16 porte in Entrata:
+
#REDIRECT [[ALSA_e_Gambas:_Creare_16_Client_ciascuno_avente_16_porte_in_Uscita_e_16_porte_in_Entrata]]
Library "libasound:2"
 
 
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
 
Private Const SND_SEQ_PORT_CAP_WRITE As Integer = 2
 
Private Const SND_SEQ_PORT_CAP_SUBS_WRITE As Integer = 64
 
<FONT color=gray>''Private Const SND_SEQ_PORT_TYPE_MIDI_GENERIC As Integer = 2''
 
''Private Const SND_SEQ_PORT_TYPE_APPLICATION As Integer = 1048576''</font>
 
 
 
<FONT color=gray>' ''int snd_seq_open (snd_seq_t **handle, const char *name, int streams, int mode)''
 
' ''Open the ALSA sequencer.''</font>
 
Private Extern snd_seq_open(seqP As Pointer, name As String, streams As Integer, mode As Integer) As Integer
 
 
<FONT color=gray>' ''int snd_seq_set_client_name(snd_seq_t * seq, const char * name)''
 
' ''Set client name.''</font>
 
Private Extern snd_seq_set_client_name(seqP As Pointer, name As String) As Integer
 
 
<FONT color=gray>' ''int snd_seq_client_id(snd_seq_t * seq)''
 
' ''Get the client id.''</font>
 
Private Extern snd_seq_client_id(seqP As Pointer) As Integer
 
 
<FONT color=gray>' ''int snd_seq_create_simple_port(snd_seq_t* seq, const char* name, unsigned int caps, unsigned int type)''
 
' ''Create a port - simple version.''</font>
 
Private Extern snd_seq_create_simple_port(seqP As Pointer, name As String, caps As Integer, type As Integer) As Integer
 
 
<FONT color=gray>' ''int snd_seq_connect_to (snd_seq_t *seq, int my_port, int dest_client, int dest_port)''
 
' ''Simple subscription (w/o exclusive & time conversion).''</font>
 
Private Extern snd_seq_connect_to(seq As Pointer, myport As Integer, dest_client As Integer, dest_port As Integer) As Integer
 
 
<FONT color=gray>' ''int snd_seq_connect_from (snd_seq_t *seq, int my_port, int src_client, int src_port)''
 
' ''Simple subscription (w/o exclusive & time conversion).''</font>
 
Private Extern snd_seq_connect_from(seq As Pointer, myport As Integer, src_client As Integer, src_port As Integer) As Integer
 
 
<FONT color=gray>' ''const char * snd_strerror (int errnum)''
 
' ''Returns the message for an error code.''</font>
 
Private Extern snd_strerror(err As Integer) As Pointer
 
 
 
'''Public''' Sub Main()
 
 
  Dim err, id, extra, intra As Integer
 
  Dim hp As New Pointer[]
 
  Dim handle As Pointer
 
  Dim nomen As String
 
  Dim b, c As Byte
 
 
 
 
  For b = 0 To 15
 
 
 
    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))
 
 
 
    hp.Add(handle)
 
 
 
    nomen = "'Client n. " & CStr(b) & "'"
 
    snd_seq_set_client_name(hp[b], nomen)
 
    Print "\nNOME del Client: "; nomen
 
 
    id = snd_seq_client_id(hp[b])
 
    Print "ID del Client: "; id
 
 
 
    For c = 0 To 15
 
<FONT color=gray>' ''Crea la porta in Uscita del Client:''</font>
 
      extra = snd_seq_create_simple_port(hp[b], "Porta di Uscita", 0, SND_SEQ_PORT_CAP_READ + SND_SEQ_PORT_CAP_SUBS_READ) <FONT color=gray>' ''oppure: SND_SEQ_PORT_TYPE_MIDI_GENERIC + SND_SEQ_PORT_TYPE_APPLICATION)''</font>
 
      If extra < 0 Then
 
        Error.Raise("Errore nella creazione della porta in Uscita del Client: " & snd_strerror(extra))
 
      Else
 
        Print "Porta in Uscita del Client: "; extra;
 
      Endif
 
   
 
<FONT color=gray>' ''Crea la porta in Entrata del Client:''</font>
 
      intra = snd_seq_create_simple_port(hp[b], "Porta di Entrata", 0, SND_SEQ_PORT_CAP_WRITE + SND_SEQ_PORT_CAP_SUBS_WRITE) <FONT color=gray>' ''oppure: SND_SEQ_PORT_TYPE_MIDI_GENERIC + SND_SEQ_PORT_TYPE_APPLICATION)''</font>
 
      If intra < 0 Then
 
        Error.Raise("Errore nella creazione della porta in Entrata del Client: " & snd_strerror(intra))
 
      Else
 
        Print "    Porta in Entrata del Client: "; intra
 
      Endif
 
   
 
      impostaConnessioni(hp[b], extra, intra)
 
   
 
    Next
 
 
 
  Next
 
 
  While True
 
    Wait 0.01
 
  Wend
 
 
'''End'''
 
 
 
'''Public''' Sub impostaConnessioni(seq As Pointer, portEx As Integer, portIn As Integer)
 
 
  Dim err As Integer
 
 
<FONT color=gray>' ''Connettiamo la corrente porta di Uscita del nostro Client''
 
' ''ad esempio alla porta n. 0 di entrata del Client avente Id 14 ('Midi Through'):''</font>
 
  err = snd_seq_connect_to(seq, portEx, 14, 0)
 
  If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")
 
 
<FONT color=gray>' ''Connettiamo la corrente porta di Entrata del nostro Client''
 
' ''alla porta di uscita di un dispositivo esterno Midi (ad esempio ad una tastiera Midi):''</font>
 
  err = snd_seq_connect_from(seq, portIn, 24, 0)
 
  If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")
 
 
'''End'''
 

Versione attuale delle 09:43, 12 gen 2022