Generator Bug or Operator Error?

So I decided to improve the script I used in this clock generator and remove the Local GP MIDI loop. I have found the loop technique to be fairly predictable and stable in the past and preferred it over the free running generator, which I had previously only had partial success with. But thought I should try again with a generator.

However, I run into the same problem with generators as I have in the past. So decided to try and work through the problem. When developing and I do multiple compiles the generators seem to be unstable. It is though the last generator remains active. Here is a very simple scriptlet that demonstrates the problem. Simply load/copy it into a scriptlet block and connect a MIDI monitor on the output. When you compile the MIDI message will be sent at 1Hz. When you click compile for a second time a second generator is started and the ouput is two messages per second? Compile again then three messages etc…

// Cyclic generator
var clockGen : Ramp

// Static MIDI messages
var cc : midiMessage

// Called when ramp finishes
On GeneratorEndCycle(x : integer) from clockGen
    SendNow(cc)
End

// Called automatically after script is loaded
Initialization
    cc = MakeControlChangeMessage(119,127)
    SetGeneratorOneShot(clockGen, false)
    SetGeneratorFrequency(clockGen,1)
    EnableGenerator(clockGen, true)
    SetTimersRunning(true)
End

Further, if I delete the code in the scriptlet and compile an empty scriptlet, the output obviously stops. If I then copy the code back into the script and compile I have multiple output per second. Deleting the scriptlet block loading a new block and copying the code in reverts the output to one message per second.

TIA

The generators are in my experience not easy to handle and rather quirky. Maybe first calling SetTimersRunning(false) before the remainder of the initialization helps?

Thanks for the thoughts. I have already tried stopping the timer but it made no difference. As I understand, the timer is global and in my “real” gig file the timer is already running so can’t unilaterally be stopped. This was just a minimal code example to show the problem, and the timer needed to be started somewhere. I guess moving the timer start to the beginning of the initialisation is more representative of my final use case.

I don’t know whether it’s technically a “bug” or not, but I followed your example and got the same result. It seems like undesirable behavior.

What appears to be happening is that every time you re-compile it creates a new instance of “clockGen” but you lose the ability to reference anything but the most recent one, or something along those lines.

Deleting the scriptlet block, then adding a new one and pasting in the code seems like an easy enough workaround, but my guess is it should not be behaving this way.

No it shouldn’t behave that way – thanks for reporting this.

I’ve never been happy with the way I implemented generators in GPScript – I want to rethink them but in the meantime, I’ll look at addressing that issue.

1 Like

Deleting the scriptlet block, then adding a new one and pasting in the code seems like an easy enough workaround

I believe scripts are compiled at various times when working with GP, not just when building the script. Opening and closing options, applying rigs etc… it may be very easy to compile multiple times and not realise.