2

For a sequencer I'm using ToneJS. I create a new Tone.Sequence and it works great. I can get it to loop by adding a .loop = true at the end. However, is there a way to make the loop start on a different position in the sequence ONLY for the first time you play the sequence back, after which it will just loop it from start to finish? I made a little sequencer and you can put the cursor anywhere in the sequence before you press loop. It would be nice to allow the loop to start on an arbitrary position before it starts to loop from the start again.

I tried Tone.Transport = myStartingPoint; // in seconds and that also works great, but the sequence and transport don't forget the starting point after playing it to the end for the first time, and the loop then keeps starting on that point.

One solution would be to instantiate two sequences: one that only plays once, from an arbitrary starting point to finish, and one that plays from start to finish but is scheduled to start playing after the first one is done. Obviously I don't really like that solution though, because then you instantiate two, and I'd rather just keep it to one.

The function that actually runs the show:

export const scheduleChords = (chords, offset, bars, numerator, denominator, callback) => {
  Tone.Transport.timeSignature = numerator;
  const durationScale = getDurationScale(denominator);

  const part = new Tone.Sequence(((time, value) => {
    playNotes(value.notes, durationScale * (value.duration || 0), time, 0, false);
    Tone.Draw.schedule(() => callback(value), time);
  }), chords, denominator).start(0).loop = true;

  // This will enable playback if it is not first triggered by an attackRelease
  Tone.context.resume();
  Tone.Transport.start();
}

Did anyone have this problem and was anybody able to solve it?

jps
  • 20,041
  • 15
  • 75
  • 79
user68177
  • 21
  • 1

0 Answers0