Convertire i dati grezzi delle note del messaggio Midi "NoteOn" nei corrispondenti simboli del protocollo ABC di notazione musicale: differenze tra le versioni

Da Gambas-it.org - Wikipedia.
Vai alla navigazione Vai alla ricerca
Nessun oggetto della modifica
Nessun oggetto della modifica
 
(3 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
Per trasformare i dati grezzi, relativi alla nota, del Messaggio Midi "NoteOn", provenienti da un dispositivo Midi esterno (ad esempio una tastiera Midi esterna), nel corrispondente simbolo notazionale previsto dal protocollo ABC, è possibile adottare il seguente codice.
Per trasformare i dati grezzi, relativi alla nota, del Messaggio Midi "NoteOn", provenienti in modalità ''monofonica'' da un dispositivo Midi esterno (ad esempio una tastiera Midi esterna), nel corrispondente simbolo notazionale previsto dal protocollo ABC, è possibile adottare il seguente codice.
  Private Const DIESIS As String = "^"  
  Private Const DIESIS As String = "^"  
  Private Const BEMOLLE As String = "_"
  Private Const BEMOLLE As String = "_"
Private notebasse As String[] = ["C", "db", "D", "db", "E", "F", "db", "G", "db", "A", "db", "B"]
Private notealte As String[] = ["c", "db", "d", "db", "e", "f", "db", "g", "db", "a", "db", "b"]
  Private fl As File
  Private fl As File
  Private nt As New String[]
  Private nt As New String[]
Riga 61: Riga 63:
   
   
  <FONT Color=gray>' ''Mostra in console il codice ABC relativo alla nota premuta sulla tastiera:''</font>
  <FONT Color=gray>' ''Mostra in console il codice ABC relativo alla nota premuta sulla tastiera:''</font>
   Print Converte(nota)
   Print "Nota = "; Converte(nota),
  <FONT Color=gray>' ''Mostra in console la durata della nota in millesimi di secondo:''</font>
  <FONT Color=gray>' ''Mostra in console la durata della nota in millesimi di secondo:''</font>
   Print msDurata
   Print "ms "; msDurata
    
    
  End
  End
Riga 72: Riga 74:
  <FONT Color=gray>' ''Si deve scegliere se, premendo un tasto nero della tastiera musicale, si deve inviare unitamente al simbolo della nota anche il simbolo ABC del 'diesis' ('''^'''), oppure se si deve inviare anche il simbolo ABC del 'bemolle' ('''_'''):''</font>
  <FONT Color=gray>' ''Si deve scegliere se, premendo un tasto nero della tastiera musicale, si deve inviare unitamente al simbolo della nota anche il simbolo ABC del 'diesis' ('''^'''), oppure se si deve inviare anche il simbolo ABC del 'bemolle' ('''_'''):''</font>
   Dim alt As String = DIESIS  <FONT Color=gray>' ''oppure: '''BEMOLLE'''''</font>
   Dim alt As String = DIESIS  <FONT Color=gray>' ''oppure: '''BEMOLLE'''''</font>
  Dim b As Byte
   
   
   Select Case nota
   If nota \ 12 < 5 Then
     Case 12
     If notebasse[nota Mod 12] = "db" Then
      Return "C,,,,"
       b = 1
    Case 13
       Return Replace(notebasse[nota Mod 12], "db", altera) & notebasse[(nota Mod 12) - b] & String(4 - (nota \ 12), ",")
       Return alt & "C,,,,"
     Else
    Case 14
       Return notebasse[nota Mod 12] & String(4 - (nota \ 12), ",")
       Return "D,,,,"
     Endif
    Case 15
  Else
      Return alt & "E,,,,"
     If notealte[nota Mod 12] = "db" Then
    Case 16
       b = 1
      Return "E,,,,"
       Return Replace(notealte[nota Mod 12], "db", altera) & notealte[(nota Mod 12) - b] & String((nota \ 12) - 5, ",")
    Case 17
     Else
      Return "F,,,,"
       Return notealte[(nota Mod 12) - b] & String((nota \ 12) - 5, ",")
    Case 18
     Endif
      Return alt & "F,,,,"
   Endif
    Case 19
      Return "G,,,,"
    Case 20
      Return alt & "G,,,,"
    Case 21
      Return "A,,,,"
     Case 22
       Return alt & "B,,,,"
    Case 23
      Return "B,,,,"
     Case 24
      Return "C,,,"
     Case 25
      Return alt & "C,,,"
    Case 26
       Return "D,,,"
    Case 27
       Return alt & "E,,,"
    Case 28
      Return "E,,,"
    Case 29
      Return "F,,,"
    Case 30
      Return alt & "F,,,"
    Case 31
      Return "G,,,"
    Case 32
      Return alt & "G,,,"
    Case 33
      Return "A,,,"
     Case 34
       Return alt & "B,,,"
    Case 35
      Return "B,,,"
    Case 36
      Return "C,,"
    Case 37
      Return alt & "C,,"
    Case 38
      Return "D,,"
    Case 39
      Return alt & "E,,"
    Case 40
      Return "E,,"
    Case 41
      Return "F,,"
    Case 42
      Return alt & "F,,"
    Case 43
      Return "G,,"
    Case 44
      Return alt & "G,,"
    Case 45
      Return "A,,"
    Case 46
      Return alt & "B,,"
    Case 47
      Return "B,,"
    Case 48
      Return "C,"
    Case 49
      Return alt & "C,"
    Case 50
      Return "D,"
    Case 51
      Return alt & "E,"
    Case 52
      Return "E,"
    Case 53
      Return "F,"
    Case 54
      Return alt & "F,"
     Case 55
      Return "G,"
    Case 56
      Return alt & "G,"
    Case 57
      Return "A,"
    Case 58
      Return alt & "B,"
    Case 59
      Return "B,"
    Case 60
      Return "C"      <FONT Color=gray>' '''Do centrale'''</font>
    Case 61
      Return alt & "C"
    Case 62
      Return "D"
    Case 63
      Return alt & "E"
    Case 64
      Return "E"
    Case 65
      Return "F"
    Case 66
      Return alt & "F"
    Case 67
      Return "G"
    Case 68
      Return alt & "G"
    Case 69
      Return "A"
    Case 70
      Return alt & "B"
    Case 71
      Return "B"
    Case 72
      Return "c"
    Case 73
      Return alt & "c"
    Case 74
      Return "d"
    Case 75
      Return alt & "e"
    Case 76
      Return "e"
    Case 77
      Return "f"
    Case 78
      Return alt & "f"
    Case 79
      Return "g"
    Case 80
      Return alt & "g"
    Case 81
      Return "a"
    Case 82
      Return alt & "b"
    Case 83
      Return "b"
    Case 84
      Return "c'"
    Case 85
      Return alt & "c'"
    Case 86
      Return "d'"
    Case 87
      Return alt & "e'"
    Case 88
      Return "e'"
    Case 89
      Return "f'"
    Case 90
      Return alt & "f'"
    Case 91
      Return "g'"
    Case 92
      Return alt & "g'"
    Case 93
      Return "a'"
    Case 94
      Return alt & "b'"
    Case 95
      Return "b'"
    Case 96
      Return "c''"
    Case 97
      Return alt & "c''"
    Case 98
      Return "d''"
    Case 99
      Return alt & "e''"
    Case 100
      Return "e''"
    Case 101
      Return "f''"
    Case 102
      Return alt & "f''"
    Case 103
      Return "g''"
    Case 104
      Return alt & "g''"
    Case 105
      Return "a''"
    Case 106
      Return alt & "b''"
    Case 107
      Return "b''"
    Case 108
      Return "c'''"
    Case 109
      Return alt & "c'''"
    Case 110
      Return "d'''"
    Case 111
      Return alt & "e'''"
    Case 112
      Return "e'''"
    Case 113
      Return "f'''"
    Case 114
      Return alt & "f'''"
    Case 115
      Return "g'''"
    Case 116
      Return alt & "g'''"
    Case 117
      Return "a'''"
    Case 118
      Return alt & "b'''"
    Case 119
      Return "b'''"
    Case 120
      Return "c''''"
   End Select
   
   
  End
  End

Versione attuale delle 07:17, 6 lug 2023

Per trasformare i dati grezzi, relativi alla nota, del Messaggio Midi "NoteOn", provenienti in modalità monofonica da un dispositivo Midi esterno (ad esempio una tastiera Midi esterna), nel corrispondente simbolo notazionale previsto dal protocollo ABC, è possibile adottare il seguente codice.

Private Const DIESIS As String = "^" 
Private Const BEMOLLE As String = "_"
Private notebasse As String[] = ["C", "db", "D", "db", "E", "F", "db", "G", "db", "A", "db", "B"]
Private notealte As String[] = ["c", "db", "d", "db", "e", "f", "db", "g", "db", "a", "db", "b"]
Private fl As File
Private nt As New String[]
Private tmp As Date


Public Sub Main()

 Dim disp As String = "/dev/snd"

 If Dir(disp, "midi*", gb.Device).Count == 0 Then Return

' Contiene il percorso del file-device del dispositivo Midi esterno aperto da ALSA:
 disp &/= Dir(disp, "midi*", gb.Device)[0]

' Apre il file-device in "Lettura" e lo pone in "Osservazione":
 fl = Open disp For Read Watch

End


Public Sub File_Read()

 Dim b As Byte

 Read #fl, b

 If b > 249 Then Return
 nt.Push(CStr(b))
' Al primo dato midi utile, viene preso l'orario corrente:
 If nt.Count = 1 Then tmp = Time
' Dopo i tre Messaggi Midi "Note-On" di accensione della nota e dopo gli altri tre Messaggi Midi di spegnimento della nota, viene preso nuovamente l'orario corrente:
 If nt.Count = 6 Then
   If (Val(nt[0]) > 143) Or (Val(nt[0]) < 160) Then
     MostraRisultato(nt[1], ElaboraTempo(Time))
     nt = New String[]
   Endif
 Endif

End


Public Sub Application_Read() ' Premendo il tasto "Invio" della tastiera, si chiude il programma
 
 fl.Close
 Quit
 
End


Private Function ElaboraTempo(TempoDopo As Date) As Short

 Return CShort(DateDiff(tmp, TempoDopo, gb.Millisecond))

End


Private Procedure MostraRisultato(nota As String, msDurata As Short)

' Mostra in console il codice ABC relativo alla nota premuta sulla tastiera:
 Print "Nota = "; Converte(nota),
' Mostra in console la durata della nota in millesimi di secondo:
 Print "ms "; msDurata
 
End


Private Function Converte(nota As Byte) As String

' Si deve scegliere se, premendo un tasto nero della tastiera musicale, si deve inviare unitamente al simbolo della nota anche il simbolo ABC del 'diesis' (^), oppure se si deve inviare anche il simbolo ABC del 'bemolle' (_):
 Dim alt As String = DIESIS  ' oppure: BEMOLLE
 Dim b As Byte

 If nota \ 12 < 5 Then 
   If notebasse[nota Mod 12] = "db" Then
     b = 1
     Return Replace(notebasse[nota Mod 12], "db", altera) & notebasse[(nota Mod 12) - b] & String(4 - (nota \ 12), ",")
   Else
     Return notebasse[nota Mod 12] & String(4 - (nota \ 12), ",")
   Endif 
 Else 
   If notealte[nota Mod 12] = "db" Then
     b = 1
     Return Replace(notealte[nota Mod 12], "db", altera) & notealte[(nota Mod 12) - b] & String((nota \ 12) - 5, ",")
   Else
     Return notealte[(nota Mod 12) - b] & String((nota \ 12) - 5, ",")
   Endif 
 Endif

End


Riferimenti