Repository navigation
Transpose notes example
In questo esempio vedremo come impostare un trasporto premendo una nota da una tastiera esterna
Useremo alcuni widget per mostrare le note ed impostare il trasporto. Anche se non abbiamo ancora parlato delle
funzioni relative a questi oggetti sono disponibili metodi per intercettare il cambio di valore , e modificare alcune proprietà
Lo script verrà inserito a livello di rackspace locale In questo esempio usiamo una tastiera simulata con TouchOSC che invierà la nota con messaggio midi tramite TouchOSC Bridge che rappresenta il nostro device collegato al RigManager
In un pannello del workspace posizioniamo dei widget che mostreranno la nota ricevuta Con il pulsante SET attiviamo la funzione transponse. Quando suoneremo una delle note sulla tastiera calcoleremo l'intervallo e applicheremo il trasporto per il rackspace corrente

| Widget | Handle | Description |
|---|---|---|
| TextLabel | Caption NOTE | |
| TextLabel | wNote | Display name of the played note |
| TextLabel | Caption VELOCITY | |
| TextLabel | wVel | Display Velocity of the played note |
| TextLabel | Caption RELEASE Velocity | |
| TextLabel | wRel | Release velocity of the played note |
| TextLabel | Caption SET | |
| Buitton | wbtnTrs | When the button is ON, the first note played is used to calculate the transpose interval. When the button is OFF, the transpose is erased. |
| TextLabel | Caption ACTIVE ( Light mean the transpose is active ) | |
| TextLabel | wLabTr | Display name of the transposed note |
| TextLabel | wLabTrNum | Display value of the transposed range |
Nel rackspace è presente anche il blocco MidiOutBlock che utilizzeremo per verificare il funzionamento del transpose

Vediamo in dettaglio il codice Nella prima parte sono presenti le dichiarazioni delle variabili usate dallo script
/******************************************************
//
// Rackspace Script
//
******************************************************/
Var
KeyboardIn : MidiInBlock
KeyboardOut : MidiOutBlock
wNote : Widget
wVel : Widget
wRel : Widget
wbtnTrs : Widget
wLedTr : Widget
wLabTr : Widget
wLabTrNum : widget
bTranspose ,bTransposeDone : boolean
iNoteTranspCatch : integer
iNoteTranspose : integer
Initialization
Print("Rackspace Transpose script ")
End
Nella seconda parte vengono elaborati due eventi NoteEvent dove viene calcolato il transpose WidgetValueChanged che serve per intercettare l'evento del pulsante ON/OFF
Quando viene intercettato il messaggio si ottiene il numero della nota , il nome della nota e la velocità in entrata e uscita
note= GetNoteNumber(m) //return a note number
noteName= NoteNumberToNoteName(note) // return note name
vel = GetVelocity(m) //return a velocity [0..127]
rel = GetReleaseVelocity(m) //return the release velocity [0..127]
Quando è premuto il pulsante la variabile bTranspose indica che viene richiesto di eseguire il calcolo del transponse
On WidgetValueChanged(newValue : double) from wbtnTrs
// Button ON newValue= 127
// Button OFF newValue= 0
If newValue>0 Then
bTranspose= true
Print("Transpose true")
else
bTranspose= false
bTransposeDone = false
SetWidgetValue(wLedTr,0 )
Print("Transpose false")
End
End
Il calcolo viene eseguito e memorizzato nella variabile iNoteTranspCatch
// Catch note and transponse calculation
If bTranspose and not bTransposeDone Then
// Get octave from note
octave= Ceiling (note/12 )
// Get the note number within range ) 0..12
iNoteTranspCatch = note - (octave * 12 )
bTransposeDone = true
end
La nota originale viene sommata dello step calcolato e inviata in uscita al blocco midi Per modificare il messaggio originale ed inserire il valore della nuova nota si è usata la funzione WithNoteNumber
NoteTranspose= note + iNoteTranspCatch
...
MyNoteMessage=WithNoteNumber(m,iNoteTranspose)
SendNow ( KeyboardIn , MyNoteMessage )
Codice completo
/******************************************************
//
// Rackspace Script
//
******************************************************/
Var
KeyboardIn : MidiInBlock
KeyboardOut : MidiOutBlock
wNote : Widget
wVel : Widget
wRel : Widget
wbtnTrs : Widget
wLedTr : Widget
wLabTr : Widget
wLabTrNum : widget
bTranspose ,bTransposeDone : boolean
iNoteTranspCatch : integer
iNoteTranspose : integer
Initialization
Print("Rackspace Transpose script ")
End
On NoteEvent(m : NoteMessage) from KeyboardIn
var
note : int
vel : int
rel : int
octave : int
noteName: string
MyNoteMessage: NoteMessage
note= GetNoteNumber(m) //return a note number
noteName= NoteNumberToNoteName(note) // return note name
vel = GetVelocity(m) //return a velocity [0..127]
rel = GetReleaseVelocity(m) //return the release velocity [0..127]
Print ("Note Num -> "+ note + " Note Name ->" + noteName + " Vel->" + vel + "Relase Vel->" + rel)
SetWidgetLabel(wNote, noteName)
SetWidgetLabel(wVel, vel)
SetWidgetLabel(wRel, rel)
// Catch note and transponse calculation
If bTranspose and not bTransposeDone Then
// Get octave from note
octave= Ceiling (note/12 )
// Get the note number within range ) 0..12
iNoteTranspCatch = note - (octave * 12 )
Notify( "Catch " + iNoteTranspCatch )
bTransposeDone = true
end
If bTranspose Then
//Add transpone note
iNoteTranspose= note + iNoteTranspCatch
// Led Active
SetWidgetValue(wLedTr,127 )
Print( "Catch " + iNoteTranspCatch )
else
//PAsstrought note message
iNoteTranspose= note
SetWidgetValue(wLedTr,0 )
iNoteTranspCatch = 0
Print("Transpose false")
end
MyNoteMessage=WithNoteNumber(m,iNoteTranspose)
SendNow ( KeyboardIn , MyNoteMessage )
SetWidgetLabel(wLabTr, NoteNumberToNoteName (iNoteTranspose))
SetWidgetLabel(wLabTrNum, iNoteTranspCatch )
End
On WidgetValueChanged(newValue : double) from wbtnTrs
// Button ON newValue= 127
// Button OFF newValue= 0
If newValue>0 Then
bTranspose= true
Print("Transpose true")
else
bTranspose= false
bTransposeDone = false
SetWidgetValue(wLedTr,0 )
Print("Transpose false")
End
End
