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
(Creata pagina con "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 corrispo...")
 
Nessun oggetto della modifica
 
(19 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.
  Public Struct Dati_Nota
  Private Const DIESIS As String = "^"
  codex As String <FONT Color=gray>' ''Il codice ABC relativo alla nota premuta sulla tastiera''</font>
Private Const BEMOLLE As String = "_"
  tempus As Short  <FONT Color=gray>' ''La durata della nota in millesimi di secondo''</font>
  Private notebasse As String[] = ["C", "db", "D", "db", "E", "F", "db", "G", "db", "A", "db", "B"]
End Struct
  Private notealte As String[] = ["c", "db", "d", "db", "e", "f", "db", "g", "db", "a", "db", "b"]
   
  Private FileDevice_Midi As String   <FONT Color=gray>' ''Contiene il percorso del file-device del dispositivo Midi esterno aperto da ALSA''</font>
  Private fl As File
  Private fl As File
  Private nt As String[]
  Private nt As New String[]
  Private f As Float
  Private tmp As Date
   
   
   
   
  '''Public''' Sub Main()
  Public Sub Main()
   
   
   Dim disp As String = "/dev/snd"
   Dim disp As String = "/dev/snd"
  nt = New String[]
   
   
   If Dir(disp, "midi*", gb.Device).Count == 0 Then Return
   If Dir(disp, "midi*", gb.Device).Count == 0 Then Return
   
   
<FONT Color=gray>' ''Contiene il percorso del file-device del dispositivo Midi esterno aperto da ALSA:''</font>
   disp &/= Dir(disp, "midi*", gb.Device)[0]
   disp &/= Dir(disp, "midi*", gb.Device)[0]
   
   
   FileDevice_Midi = disp
<FONT Color=gray>' ''Apre il file-device in "Lettura" e lo pone in "Osservazione":''</font>
   fl = Open disp For Read Watch
   
   
  fl = Open disp For Read Watch
End
   
   
'''End'''
   
   
  '''Public''' Sub File_Read()
  Public Sub File_Read()
   
   
   Dim b As Byte
   Dim b As Byte
  Dim durata As Short
   
   
   Read #fl, b
   Read #fl, b
 
   If b > 249 Then Return
   If b > 249 Then Return
   nt.Add(CStr(b))
   nt.Push(CStr(b))
   If nt.Count = 1 Then f = CFloat(Now)
<FONT Color=gray>' ''Al primo dato midi utile, viene preso l'orario corrente:''</font>
   If nt.Count = 1 Then tmp = Time
<FONT Color=gray>' ''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:''</font>
   If nt.Count = 6 Then
   If nt.Count = 6 Then
     If (Val(nt[0]) > 143) Or (Val(nt[0]) < 160) Then
     If (Val(nt[0]) > 143) Or (Val(nt[0]) < 160) Then
       durata = ElaboraTempo(f, CFloat(Now))
       MostraRisultato(nt[1], ElaboraTempo(Time))
      ElaboraNota(nt[1], durata)
       nt = New String[]
       nt = New String[]
     Endif
     Endif
   Endif
   Endif
   
   
  '''End'''
  End
   
   
  '''Public''' Sub Application_Read()   <FONT Color=gray>' ''Premendo il tasto "Invio" della tastiera, si chiude il programma''</font>
   
Public Sub Application_Read() <FONT Color=gray>' ''Premendo il tasto "Invio" della tastiera, si chiude il programma''</font>
    
    
  fl.Close
   Quit
   Quit
    
    
  '''End'''
  End
   
   
'''Private''' Function ElaboraTempo(TempoPrima As Float, TempoDopo As Float) As Short
   
   
  Return CShort((CSingle(Frac(TempoDopo)) * 100000000) - (CSingle(Frac(TempoPrima)) * 100000000))
Private Function ElaboraTempo(TempoDopo As Date) As Short
   
   
'''End'''
  Return CShort(DateDiff(tmp, TempoDopo, gb.Millisecond))
   
   
  '''Private''' Procedure ElaboraNota(nota As String, risTempo As Short)
  End
   
   
  Dim notaStr As New Dati_Nota
   
   
  With notaStr
Private Procedure MostraRisultato(nota As String, msDurata As Short)
    .codex = Converte(nota, risTempo)
    .tempus = risTempo
  End With
   
   
   With notaStr
<FONT Color=gray>' ''Mostra in console il codice ABC relativo alla nota premuta sulla tastiera:''</font>
    Print .codex,
   Print "Nota = "; Converte(nota),
    Print .tempus
<FONT Color=gray>' ''Mostra in console la durata della nota in millesimi di secondo:''</font>
   End With
  Print "ms "; msDurata
    
End
   
   
'''End'''
   
   
  <FONT Color=gray>' ''Se si tiene premuto un tasto nero della tastiera Midi per una durata inferiore a ms 1000, allora sarà inviato il simbolo della nota unitamente al simbolo ABC del 'diesis': '''''^''''' ; altrimenti sarà inviato il simbolo ABC del 'bemolle': '''_''' ''</font>
  Private Function Converte(nota As Byte) As String
'''Private''' Function Converte(nota As Byte, t As Short) As String
   
   
   Dim alt As String
<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 b As Byte
   
   
   If t < 999 Then
   If nota \ 12 < 5 Then  
     alt = "^"
     If notebasse[nota Mod 12] = "db" Then
   Else
      b = 1
     alt = "_"
      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
   Endif
   
   
  Select Case nota
End
    Case 12
 
      Return "C,,,,"
 
    Case 13
 
      Return alt & "C,,,,"
=Riferimenti=
    Case 14
* [https://it.wikipedia.org/wiki/ABC_(notazione_musicale) Linguaggio notazionale ABC in Wikipedia]
      Return "D,,,,"
* [http://abcplus.sourceforge.net/index.it.html Il progetto ABC Plus]
    Case 15
* [http://abcnotation.com/ Il sito di ''abcnotation'']
      Return alt & "E,,,,"
* [http://abc.sourceforge.net/resources.html Il sito di ABC project]
    Case 16
* [http://www.lesession.co.uk/abc/abc_notation.htm Un manuale di Steve Mansfield]
      Return "E,,,,"
* [http://trillian.mit.edu/~jc/music/ ABC Music Notation]
    Case 17
      Return "F,,,,"
    Case 18
      Return alt & "F,,,,"
    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'''

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