Trigger widgets with note events

This rackspace was specifically designed to solve a problem where a MIDI controller with 16 pads had to be used to trigger sounds from a drum plugin, and to visually show what pad was actually hit.
So the goal for the rackspace panel was to show 16 pad widgets which should be lit when the according note was played (and turn dark at a “note off” again).

Unfortunately the pads of this controller were sending out note events only, which made it impossible to MIDI-learn the widgets with notes and make them behave the expected way.

The workaround for this problem had to be solved by using a short GP-Script which reacts to note events and, if the according note is played, switch the corresponding pad-widget ON or OFF.

To keep the script as short and effective as possible, i used two arrays… one for the widgets and one for the notes, because they have the same number of “members”, the particular element can just be addressed by using the same “index” for both arrays.
In addition to the arrays, the “On NoteEvent()” callback with “range constraint” makes it again easier to only “catch” those notes which were needed.
A very important point is, that every note which is “caught” by this script, must also be send out to the MIDI-block again - otherwise the played notes would trigger the widget, but they would not be sent to drum plugin… no note, no sound! :slight_smile:

This is the script which works in the rackspace:

// ######## definition of the used variables ######## 
var 
morph : MidiInBlock //use the same name which you used in the regarding MIDI-Block itself!
P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16 : widget // use the names like the widgets have

//array for the 16 pad widgets
allthepads : widget Array = [P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16]
//array for the 16 note values
noterange : Integer Array = [C1,C#1,D1,D#1,E1,F1,F#1,G1,G#1,A1,A#1,B1,C2,C#2,D2,D#2]
// ######## end of variable definition ######## 


// On NoteEvent() callback with constraint to only "listen" to the notes C1-D#2
// This callback will be triggered on every incoming note event
// from the MIDI-block named "morph" if the regarding note values are matching
On NoteEvent(m : NoteMessage) Matching [C1..D#2] from morph
var i : Integer //just an auxiliary integer variable for counting through the index of the arrays
    For i=0; i<Size(noterange); i=i+1 Do //a loop which steps from 0 to the length of the notes-array
        If IsNoteOn(m) and GetNoteNumber(m) == noterange[i] Then // check which note is played (note on)
            SetWidgetValue(allthepads[i], 1.0)// turn the regarding widget of the array ON
        Elsif IsNoteOff(m) and GetNoteNumber(m) == noterange[i] Then //check which note is released (note off)
            SetWidgetValue(allthepads[i], 0.0)// turn the regarding widget of the array OFF
        End
    End

// IMPORTANT LINE! -> Send the note out to the MIDI-block again,
// so that a plugin can play the as expected!
    SendNow(morph, m)
End

And here is the gig file:
notepads.gig (200.0 KB)

Maybe this might be helpful for some of you…
(And if there are questions, just ask… :nerd_face: )

11 Likes

Exactly what I was looking for - Thank you!

1 Like

If this is of interest for you you can also have a look at this Scriptlet: