Differenze tra le versioni di "Convertire i dati grezzi delle note del messaggio Midi "NoteOn" nei corrispondenti simboli del protocollo ABC di notazione musicale"
Da Gambas-it.org - Wikipedia.
(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...") |
|||
(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. |
− | + | 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 | ||
Private fl As File | Private fl As File | ||
− | Private nt As String[] | + | Private nt As New String[] |
− | Private | + | Private tmp As Date |
− | + | Public Sub Main() | |
Dim disp As String = "/dev/snd" | Dim disp As String = "/dev/snd" | ||
− | |||
− | |||
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] | ||
− | + | <FONT Color=gray>' ''Apre il file-device in "Lettura" e lo pone in "Osservazione":''</font> | |
+ | fl = Open disp For Read Watch | ||
− | + | End | |
− | |||
− | + | Public Sub File_Read() | |
Dim b As Byte | Dim b As Byte | ||
− | |||
Read #fl, b | Read #fl, b | ||
− | + | ||
If b > 249 Then Return | If b > 249 Then Return | ||
− | nt. | + | nt.Push(CStr(b)) |
− | If nt.Count = 1 Then | + | <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 | ||
− | + | MostraRisultato(nt[1], ElaboraTempo(Time)) | |
− | |||
nt = New String[] | nt = New String[] | ||
Endif | Endif | ||
Endif | Endif | ||
− | + | End | |
− | + | ||
+ | Public Sub Application_Read() <FONT Color=gray>' ''Premendo il tasto "Invio" della tastiera, si chiude il programma''</font> | ||
+ | fl.Close | ||
Quit | 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) | |
− | |||
− | |||
− | |||
− | + | <FONT Color=gray>' ''Mostra in console il codice ABC relativo alla nota premuta sulla tastiera:''</font> | |
− | + | Print "Nota = "; Converte(nota), | |
− | + | <FONT Color=gray>' ''Mostra in console la durata della nota in millesimi di secondo:''</font> | |
− | End | + | Print "ms "; msDurata |
+ | |||
+ | End | ||
− | |||
− | + | Private Function Converte(nota As Byte) 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 | + | If nota \ 12 < 5 Then |
− | + | If notebasse[nota Mod 12] = "db" Then | |
− | Else | + | 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 | Endif | ||
− | + | End | |
− | + | ||
− | + | ||
− | + | ||
− | + | =Riferimenti= | |
− | + | * [https://it.wikipedia.org/wiki/ABC_(notazione_musicale) Linguaggio notazionale ABC in Wikipedia] | |
− | + | * [http://abcplus.sourceforge.net/index.it.html Il progetto ABC Plus] | |
− | + | * [http://abcnotation.com/ Il sito di ''abcnotation''] | |
− | + | * [http://abc.sourceforge.net/resources.html Il sito di ABC project] | |
− | + | * [http://www.lesession.co.uk/abc/abc_notation.htm Un manuale di Steve Mansfield] | |
− | + | * [http://trillian.mit.edu/~jc/music/ ABC Music Notation] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
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