Hi all - just trying my first script today but the GPScript parser is getting confused (I think).
The aim of the script is to detect what keys are being held down, then upon every beat of the MIDI clock, send note on message for each key, followed shortly after by a note off (a la staccato effect).
It appears the “ if heldNotes[note] then” is getting an unexpected or unrecognised token “If”
Here’s the script:
var heldNotes : boolean[128]
var noteDelayMs : integer = 80
var SL88 : MidiInBlock
initialization
for i = 0; i < 128; i = i + 1 do
heldNotes[i] = false
end
end
// track held notes
on NoteOnEvent(m : NoteMessage) From SL88
var n: integer = GetNoteNumber(m)
if GetVelocity(m) > 0 then
heldNotes[n] = true
else
heldNotes[n] = false
end
end
// fire on each beat
on Timeline EveryBeat
prolog
for note = 0; note < 128; note = note + 1 do
if heldNotes[note] then
var nn: NoteMessage = MakeNoteMessage(note,100,1)
SendNow(SL88, nn)
SendLater(SL88, nn, noteDelayMs)
end
end
end
end
Try this, will not work well, but you can compile it.
var heldNotes : boolean[128]
noteDelayMs : integer = 80
SL88 : MidiInBlock
i : Integer
note : Integer
nn : NoteMessage
initialization
for i = 0; i < 128; i = i + 1 do
heldNotes[i] = false
end
end
// track held notes
on NoteOnEvent(m : NoteMessage) From SL88
var n: integer = GetNoteNumber(m)
if GetVelocity(m) > 0 then
heldNotes[n] = true
else
heldNotes[n] = false
end
end
// Called when beat changes
// Only beat number is valid for now
On BeatChanged(bar : integer, beat : integer)
for note = 0; note < 128; note = note + 1 do
if heldNotes[note] then
nn = MakeNoteMessageEx(note,100,1)
SendNow(SL88, nn)
SendLater(SL88, nn, noteDelayMs)
end
end
End
Hmm, now I get: Semantic error in “Main”: Line 3, Col 12: Allowed in rackspace script only. This type is only allowed in rackspace scripts (I presume the MidiInBlock)
This is happening because you are declaring a variable inside a block. Right now you can only declare variables at the beginning of a function or at global level.