lichen-community-systems / Flocking

Flocking - Creative audio synthesis for the Web
GNU General Public License v2.0
699 stars 60 forks source link

flock.ugen.sequencer will output NaN values when its values/durations input is resized #137

Closed colinbdclark closed 8 years ago

colinbdclark commented 8 years ago

If, during the process of generating a signal, the user updates the values and durations from a longer array to a shorter array, the flock.ugen.sequencer unit generator will output NaNs.

For example, this will fail:

var s = flock.synth({
    id: "seq",
    ugen: "flock.ugen.sequencer",
    values: [1, 2, 3, 4, 5],
    durations: [1, 1, 1, 1, 1]
 });

 s.set({
     "seq.values": [1, 2, 3],
     "seq.durations: [1, 1, 1]
 });

This is due to the fact that we don't reset the sequencer's current index into these arrays when the inputs are changed. As a result, if the sequencer has already read from a higher sequence position than the new input's length, it will fail when trying to read out-of-bounds indices.

We should always reset the sequence index (i.e. model.idx) when the values or durations inputs change.