Skip to content

Transpose notes example

Domenico Patella edited this page Apr 8, 2025 · 11 revisions

In this example we will see how to set a transport by pressing a note from an external keyboard. We will use some widgets to show the notes and set the transport. Although we have not yet discussed the related functions for these widgets there are methods available to intercept the value change , and modify some properties

The script will be inserted at the local rackspace level. In this example we use a simulated keyboard with TouchOSC that will send the note with midi message via TouchOSC Bridge representing our device connected to the RigManager

In a panel of the workspace we place widgets that will show the received note. With the SET button we activate the transponse function. When we play one of the notes on the keyboard we will calculate the interval and apply the transport for the current rackspace

image

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

In the rackspace there is also the MidiOutBlock which we will use to verify the operation of the transpose

image

Let's look at the code in detail In the first part are the declarations of the variables used by the 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

In the second part, the NoteEvent event is processed, in which the transposition is calculated
WidgetValueChanged is the function used to intercept the ON/OFF button event.

When the message is intercepted we get the note number , the note name and the velocity

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]

When the button is pressed, the variable bTranspose indicates that the note transport calculation can be performed

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

The calculation is performed and stored in the variable 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	

The original note is summed of the calculated step and output to the midi block To change the original message and enter the value of the new note, the function WithNoteNumber

NoteTranspose= note + iNoteTranspCatch
...

MyNoteMessage=WithNoteNumber(m,iNoteTranspose)
SendNow ( KeyboardIn , MyNoteMessage )

Complete code

/******************************************************
//
// 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

NoteTransponse

Clone this wiki locally