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 un plugin interno che useremo per testare il funzionamento all'uscita del blocco MidiInBlock (KeyboardIn)

Vediamo in dettaglio il codice
/******************************************************
//
// 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
octave= Ceiling (note/12 )
iNoteTranspCatch = note - (octave * 12 )
bTransposeDone = true
end
If bTranspose Then
//statements here
iNoteTranspose= note + iNoteTranspCatch
SetWidgetValue(wLedTr,127 )
Print( "Catch " + iNoteTranspCatch )
Notify( "Catch " + iNoteTranspCatch )
else
iNoteTranspose= note
SetWidgetValue(wLedTr,0 )
iNoteTranspCatch = 0
Print("Transpose false")
end
//MyNoteMessage= MakeNoteMessage(iNoteTranspose , vel)
MyNoteMessage=WithNoteNumber(m,iNoteTranspose)
SendNow ( KeyboardIn , MyNoteMessage )
SetWidgetLabel(wLabTr, NoteNumberToNoteName (iNoteTranspose))
SetWidgetLabel(wLabTrNum, iNoteTranspCatch )
End
On WidgetValueChanged(newValue : double) from wbtnTrs
If newValue>0 Then
//statements here
bTranspose= true
Print("Transpose true")
else
bTranspose= false
bTransposeDone = false
SetWidgetValue(wLedTr,0 )
Print("Transpose false")
End
End