Skip to content

How to use Midi Functions

Domenico Patella edited this page May 30, 2025 · 14 revisions

We have seen that in GPScript , we have specific functions that deal with NOTE and MIDI type messages. Actually MIDI message contains all the information , so it can also be used to read/write notes

Let us look in detail at the types of MIDI messages that can be processed

PROGRAM CHANGE (PC)
CONTROL CHANGE (CC)
PITCHBEND
POLYPRESSURE (AT)
CHANNELL PRESSURE

Program Change

The program change message is used in GIG and associated automatically to change the selection of Rackspaces and Songs in the SetList PC messages are indexed with offset, this means that if we receive a PC message with value zero the first Rackspace or Song in the list is activated

Rackspace/Songs order numbering is changed with the Option->General->Global Midi setting

image

d

PC 0 Rackspace 1 Song 1
PC 1 Rackspace 2 Song 2
… … …
PC 99 Rackspace 100 Song 100

image

PC 0 Rackspace 0 Song 0
PC 1 Rackspace 1 Song 1
… … …
PC 99 Rackspace 99 Song 99

 

An example of an application that includes intercepting program change messages and manipulating them
Suppose we use a keyboard that has a program range from P001 -- P256 ( example with Numa X Piano )
We decided to keep the programs from P001 - P099 with internal sounds and uses a range to be used with GIG ( P100-P130 )
By default the controller will send the corresponding selected PC. We want to activate our setlist are with the programs including 101-130

image

The purpose is to write a script that is able to:

  1. Intercept PC messages coming from the controller
  2. Change the PC message to high level to convert it into the range (0-30) for GiG

Let's write the code in GiG Script


/******************************************************
//
// Gig Script
//
******************************************************/
var touch : MidiInDevice

Initialization
	
	Print("Hello")
	
End


On ProgramChangeEvent(p : ProgramChangeMessage) from touch 
	var PC : integer
	PC=GetProgramChangeNumber(p)
	Print("Channel " + GetChannel(p) + " Program Change " + PC)  	
	     
End

	

The ProgramChangeEvent callback is triggered upon receiving the PC message from the connected MIDI controller ( touch) The argument contains the MIDI message ProgramChangeMessage.

With the function GetProgramChangeNumber we get the number of the received program

PC_base

We can see that the songlist does not receive the event because it was “blocked” in GiG script
In order to resend we have to use an appropiate method. In this case we have to use InjectMidiEventViaRigManager. With this function the message contained in the variable p is sent via the device alias present in the Rig manager touch

InjectMidiEventViaRigManager
<KeyWord name="InjectMidiEventViaRigManager" func="yes">
    <Overload retVal="" descr="Inject a message to a MidiInDeviceAlias using its Rig Manager name directly">
      <Param name="rmDeviceAliasName : MidiInDeviceAlias" />
      <Param name="m : MidiMessage" />
    </Overload>
  </KeyWord>

PC_adv

💡 Tip: It is possible to use the InjectMidiEvent function, which has the name of the connected physical device as a paramete

image

In this case the function will be used in this way

InjectMidiEvent("TouchOSC Bridge", p)

InjectMidiEvent
<KeyWord name="InjectMidiEvent" func="yes">
    <Overload retVal="" descr="Inject a message to any Midi Input Port with the specified physical device name">
      <Param name="physicalDeviceName : String" />
      <Param name="m : midiMessage" />
    </Overload>
  </KeyWord>

Continuing in the example we are now going to filter the messages and change the program number according to the range received If the program number is between 100-130 , within GIG we will send the program 0-30 With the function WithProgramChangeNumber we will replace the program number with the one calculated

On ProgramChangeEvent(p : ProgramChangeMessage) from touch 
	var PC : integer
	const PC_MIN : integer= 100
	const PC_MAX : integer= 130
	
	PC=GetProgramChangeNumber(p)
	Print("Channel " + GetChannel(p) + " Program Change " + PC)  	
	
	If PC>=PC_MIN && PC<=PC_MAX Then
		PC=PC - PC_MIN
		Notify("PC changed" + PC) 
		p= WithProgramChangeNumber(p, PC)
		InjectMidiEventViaRigManager(touch, p)
		
	end	

	
	
End

Important

In this way all other program change values will be ignored

PC_adv_1

Tip

From GiG we set the Program Change to MIDI Out with the same value in transmission to be synchronized with the external device

Clone this wiki locally