GPScript parser cannot get passed a for loop

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

Do you write the script?

yes… first attempt (!)

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)

Nevermind, this was supposed to be a rackspace-level script… which it is now!

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.

Ahh ok, now that makes sense.

Ok, so I’m trying to capture the ticks of GP’s internal MIDI clock (quarter notes to be specific).

Then on each quarter note, I want to trigger staccato notes of whatever notes are being held down.

But for now, I just want to be able read the the GP MIDI clock, I’ll work out the rest myself.