Skip to content

How to use Note Functions

Domenico Patella edited this page Apr 11, 2025 · 1 revision

There are various functions that allow you to read received MIDI information , modify it or create new messages, and send them. Within the system functions we find a section of specific methods for each type of message received

For the NoteMessage we have two classes of functions.

  • Functions that process the NoteMessage object to read the content
GetNoteNumber
<KeyWord name="GetNoteNumber" func="yes">
    <Overload retVal="int" descr="Returns the note number of a NoteMessage MIDI event">
        <Param name="m : NoteMessage"/>
    </Overload>
</KeyWord>
GetVelocity
<KeyWord name="GetVelocity" func="yes">
    <Overload retVal="int" descr="Returns the velocity of a NoteEvent MIDI message. The value will be between 0 and 127">
      <Param name="m : NoteMessage" />
    </Overload>
  </KeyWord>
GetReleaseVelocity
<KeyWord name="GetReleaseVelocity" func="yes">
    <Overload retVal="int" descr="Returns the release velocity of a NoteOffEvent MIDI message. You need to make sure that the message is in fact a NoteOff or the result will always be 0">
      <Param name="m : NoteMessage" />
    </Overload>
  </KeyWord>
  • Functions that return an object of type NoteMessage
Transpose
<KeyWord name="Transpose" func="yes">
    <Overload retVal="NoteMessage" descr="Returns a note that has been transposed chromatically by the number of steps">
      <Param name="m : NoteMessage" />
      <Param name="steps : int" />
    </Overload>
  </KeyWord>
MakeNoteMessage
<KeyWord name="MakeNoteMessage" func="yes">
    <Overload retVal="NoteMessage" descr="Returns a Note MIDI message with the specified note number and velocity. The MIDI channel is 1">
      <Param name="number : int" />
      <Param name="velocity : int" />
    </Overload>
  </KeyWord>
MakeNoteMessageEx
<KeyWord name="MakeNoteMessageEx" func="yes">
    <Overload retVal="NoteMessage" descr="Returns a Note MIDI message with the specified note number and velocity and MIDI channel">
      <Param name="number : int" />
      <Param name="velocity : int" />
      <Param name="channel : int" />
    </Overload>
  </KeyWord>
MakeNoteOffMessage
<KeyWord name="MakeNoteOffMessage" func="yes">
    <Overload retVal="NoteMessage" descr="Returns a NoteOff MIDI message with the specified note number and release. The MIDI channel is 1">
      <Param name="number : int" />
      <Param name="release : int" />
    </Overload>
  </KeyWord>
MakeNoteOffMessageEx
<KeyWord name="MakeNoteOffMessageEx" func="yes">
    <Overload retVal="NoteMessage" descr="Returns a NoteOff MIDI message with the specified note number and release and MIDI channel">
      <Param name="number : int" />
      <Param name="release : int" />
      <Param name="channel : int" />
    </Overload>
  </KeyWord>
ReinterpretAsNoteOffMessage
<KeyWord name="ReinterpretAsNoteOffMessage" func="yes">
    <Overload retVal="NoteMessage" descr="Reinterpret an arbitrary MIDI message - you need to know what you are doing">
      <Param name="m : MidiMessage" />
    </Overload>
  </KeyWord>
ReinterpretAsNoteOnMessage
<KeyWord name="ReinterpretAsNoteOnMessage" func="yes">
    <Overload retVal="NoteMessage" descr="Reinterpret an arbitrary MIDI message - you need to know what you are doing">
      <Param name="m : MidiMessage" />
    </Overload>
  </KeyWord>

The WithNote.. functions are similar to MakeNoteMessage the difference is that in this case they have an existing NoteMessage object as a function parameter and return it modified. This is useful for example , in case we are processing inside in a NoteEvent event where the NoteMessage object is passed as parameter.

WithNoteNumber
<KeyWord name="WithNoteNumber" func="yes">
    <Overload retVal="NoteMessage" descr="Changes the note number of a NoteMessage MIDI event">
      <Param name="m : NoteMessage" />
      <Param name="number : int" />
    </Overload>
  </KeyWord>
WithNoteNumberAndVelocity
<KeyWord name="WithNoteNumberAndVelocity" func="yes">
    <Overload retVal="NoteMessage" descr="Changes the note number and the velocity value of a NoteMessage MIDI event. Setting to 0 will make the message be a NoteOff">
      <Param name="m : NoteMessage" />
      <Param name="n : int" />
      <Param name="v : int" />
    </Overload>
  </KeyWord>
WithTranspose
<KeyWord name="WithTranspose" func="yes">
    <Overload retVal="NoteMessage" descr="Returns a note that has been transposed chromatically by the number of steps">
      <Param name="m : NoteMessage" />
      <Param name="steps : int" />
    </Overload>
  </KeyWord>
WithVelocity
<KeyWord name="WithVelocity" func="yes">
    <Overload retVal="NoteMessage" descr="Changes the velocity value of a NoteMessage MIDI event. Setting to 0 will make the message be a NoteOff">
      <Param name="m : NoteMessage" />
      <Param name="v : int" />
    </Overload>
  </KeyWord>

Once a NoteMessage or MidiMessage object is constructed there are other functions that allow sending on the different MIDI blocks depending on the context

SendNow
<KeyWord name="SendNow" func="yes">
    <Overload retVal="" descr="Send a MIDI event out immediately">
      <Param name="p : MidiInBlock" />
      <Param name="m : midiMessage" />
    </Overload>
  </KeyWord>
SendNow
<KeyWord name="SendNow" func="yes">
    <Overload retVal="" descr="Send a MIDI event out immediately - only for use in a Scriptlet">
      <Param name="m : midiMessage" />
    </Overload>
  </KeyWord>
SendNowExternal
<KeyWord name="SendNowExternal" func="yes">
    <Overload retVal="" descr="Send a MIDI event out immediately through a MIDI Out block">
      <Param name="p : MidiOutBlock" />
      <Param name="m : midiMessage" />
    </Overload>
  </KeyWord>
SendLater
<KeyWord name="SendLater" func="yes">
    <Overload retVal="" descr="Schedule a MIDI event to be sent out at some specified time in the future">
      <Param name="p : MidiInBlock" />
      <Param name="m : midiMessage" />
      <Param name="delayInMS : double" />
    </Overload>
  </KeyWord>
SendLater
<KeyWord name="SendLater" func="yes">
    <Overload retVal="" descr="Schedule a MIDI event to be sent out in the future - only for use in a Scriptlet">
      <Param name="m : midiMessage" />
      <Param name="delayInMS : double" />
    </Overload>
  </KeyWord>
SendNowToMidiOutDevice
<KeyWord name="SendNowToMidiOutDevice" func="yes">
    <Overload retVal="" descr="Send a MIDI event out immediately through a physical MIDI Out device">
      <Param name="deviceName : String" />
      <Param name="m : midiMessage" />
    </Overload>
  </KeyWord>

In this example in the rackspace script we insert code to catchNoteMessage and process the content with other functions
specifications such as GetNoteNumber , GetVelocity

💡 Tip:
If we add event callbacks in the workspace , we will need to insert a Send function otherwise the message will not be sent
in the current rackspace

/******************************************************
//
// Rackspace Script 
// 
******************************************************/
var KeyboardIn: MidiInBlock

Initialization
	
	Print("Rackspace script ")
	
End



On NoteEvent(m : NoteMessage) from KeyboardIn 
	var 
	note : int 
	vel : int
	rel : int
	noteName: string
	
	note= GetNoteNumber(m) //return a note number 
	noteName= NoteNumberToNoteName(note) // return note name
	vel = GetVelocity(m)  //return a velocity [0..127] 
	Print ("Note Num -> "+ note + " Note Name ->" + noteName + " Vel->" + vel)
	SendNow ( KeyboardIn , m )
	
End

NoteEvent

NoteMessage has two specific events that are processed when the note is pressed NoteOnEvent or released NoteOffEvent

/******************************************************
//
// Rackspace Script 
// 
******************************************************/
var KeyboardIn: MidiInBlock

Initialization
	
	Print("Rackspace script ")
	
End

On NoteOnEvent(m : NoteMessage) from KeyboardIn
	var 
	note : int 
	vel : int
	
	note= GetNoteNumber(m) //return a note number 
	vel = GetVelocity(m)  //return a velocity [0..127] 
	Print ("Note On->" + note + " Vel On->" + vel)
	
End


On NoteOffEvent(m : NoteMessage) from KeyboardIn
	var 
	note : int 
	vel : int
	rel : int
	
	note= GetNoteNumber(m) //return a note number 
	rel = GetReleaseVelocity(m)  //return the release velocity [0..127]
	Print ("Note Off->" + note + " Release Vel->" + rel)
	
End	

Clone this wiki locally