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

Da Gambas-it.org - Wikipedia.
(Creata pagina con "Mostriamo un possibile codice per creare 16 Client autonomi, ciascuno avente 16 porte in Uscita e 16 porte in Entrata: Library "libasound:2" Private Const SND_SEQ_OPEN_DUP...")
 
 
Riga 1: Riga 1:
 
Mostriamo un possibile codice per creare 16 Client autonomi, ciascuno avente 16 porte in Uscita e 16 porte in Entrata:
 
Mostriamo un possibile codice per creare 16 Client autonomi, ciascuno avente 16 porte in Uscita e 16 porte in Entrata:
  Library "libasound:2"
+
  Library "libasound:2.0.0"
 
   
 
   
 
  Private Const SND_SEQ_OPEN_DUPLEX As Integer = 3
 
  Private Const SND_SEQ_OPEN_DUPLEX As Integer = 3
Riga 40: Riga 40:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
  Dim err, id, extra, intra As Integer
+
  Dim err, id, extra, intra As Integer
  Dim hp As New Pointer[]
+
  Dim hp As New Pointer[]
  Dim handle As Pointer
+
  Dim handle As Pointer
  Dim nomen As String
+
  Dim nomen As String
  Dim b, c As Byte
+
  Dim b, c As Byte
 
 
 
   
 
   
 
   For b = 0 To 15
 
   For b = 0 To 15
Riga 80: Riga 79:
 
       Endif
 
       Endif
 
      
 
      
       impostaConnessioni(hp[b], extra, intra)
+
       ImpostaConnessioni(hp[b], extra, intra)
 
      
 
      
 
     Next
 
     Next
Riga 90: Riga 89:
 
   Wend
 
   Wend
 
   
 
   
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Public''' Sub impostaConnessioni(seq As Pointer, portEx As Integer, portIn As Integer)
+
  Private Procedure ImpostaConnessioni(seq As Pointer, portEx As Integer, portIn As Integer)
 
   
 
   
  Dim err As Integer
+
  Dim err As Integer
 
   
 
   
  <FONT color=gray>' ''Connettiamo la corrente porta di Uscita del nostro Client''
+
  <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>
' ''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)
 
   err = snd_seq_connect_to(seq, portEx, 14, 0)
 
   If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")
 
   If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")
 
   
 
   
  <FONT color=gray>' ''Connettiamo la corrente porta di Entrata del nostro Client''
+
  <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>
' ''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)
 
   err = snd_seq_connect_from(seq, portIn, 24, 0)
 
   If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")
 
   If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")
 
   
 
   
  '''End'''
+
  End

Versione attuale delle 15:02, 19 giu 2024

Mostriamo un possibile codice per creare 16 Client autonomi, ciascuno avente 16 porte in Uscita e 16 porte in Entrata:

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
Private Const SND_SEQ_PORT_CAP_WRITE As Integer = 2
Private Const SND_SEQ_PORT_CAP_SUBS_WRITE As Integer = 64
Private Const SND_SEQ_PORT_TYPE_MIDI_GENERIC As Integer = 2
Private Const SND_SEQ_PORT_TYPE_APPLICATION As Integer = 1048576


' 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_client_id(snd_seq_t * seq)
' Get the client id.
Private Extern snd_seq_client_id(seqP As Pointer) 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_connect_to (snd_seq_t *seq, int my_port, int dest_client, int dest_port)
' Simple subscription (w/o exclusive & time conversion).
Private Extern snd_seq_connect_to(seq As Pointer, myport As Integer, dest_client As Integer, dest_port As Integer) As Integer

' 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).
Private Extern snd_seq_connect_from(seq As Pointer, myport As Integer, src_client As Integer, src_port As Integer) As Integer

' const char * snd_strerror (int errnum)
' Returns the message for an error code.
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
' Crea la porta in Uscita del Client:
      extra = snd_seq_create_simple_port(hp[b], "Porta di Uscita", 0, SND_SEQ_PORT_CAP_READ + SND_SEQ_PORT_CAP_SUBS_READ) ' oppure: SND_SEQ_PORT_TYPE_MIDI_GENERIC + SND_SEQ_PORT_TYPE_APPLICATION)
      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
   
' Crea la porta in Entrata del Client:
      intra = snd_seq_create_simple_port(hp[b], "Porta di Entrata", 0, SND_SEQ_PORT_CAP_WRITE + SND_SEQ_PORT_CAP_SUBS_WRITE) ' oppure: SND_SEQ_PORT_TYPE_MIDI_GENERIC + SND_SEQ_PORT_TYPE_APPLICATION)
      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


Private Procedure ImpostaConnessioni(seq As Pointer, portEx As Integer, portIn As Integer)

  Dim err As Integer

' Connettiamo la corrente porta di Uscita del nostro Client ad esempio alla porta n. 0 di entrata del Client avente Id 14 ('Midi Through'):
  err = snd_seq_connect_to(seq, portEx, 14, 0)
  If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")

' Connettiamo la corrente porta di Entrata del nostro Client alla porta di uscita di un dispositivo esterno Midi (ad esempio ad una tastiera Midi):
  err = snd_seq_connect_from(seq, portIn, 24, 0)
  If err < 0 Then error.Raise("Errore nella sottoscrizione del dispositivo !")

End