Issue opened by @Truba
Opening here because this is an AudioKitEX issue - may be related to #10
Original Ticket: AudioKit/AudioKit#2536
Full description
> Hi guys, Sry for not opening in the stack overflow first, but I'm pretty sure something is wrong here.
>
> **Describe the bug / Expected behavior**
>
> Sequencer doesn't seem to be triggering note off events if the note off event is placed at the end of the track loop. Here we have an example with just that:
>
> ```swift
> let sequencer = Sequencer()
> let track = sequencer.addTrack(for: sampler)
> track.loopEnabled = true
> track.length = 4
> track.sequence.add(noteNumber: someNote, position: 3, duration: 1)
> ```
>
> I'm creating a sequencer that outputs to sampler, and I'm also adding just one note. I'm expecting this one note to trigger 2 events. Note On at position 3 and note Off at position 4. But only the note On at position 3 is triggered, note Off at position 4 is missing.
>
> **To Reproduce is Cookbook**
>
> I can also replicate is by slightly modifying the Shaker example in Cookbook: https://gist.github.com/Truba/d36ee294817446aac082d929cf3adb7d
>
> I've updated both tracks to use longer duration, and I've updated `CallbackInstrument` to print the on/off state as well. In the print you can see that Off event is missing for beat at position 3.
>
> **Where the issue might lie**
>
> I'm pretty sure the issue lies somewhere around here:
>
> https://github.com/AudioKit/AudioKit/blob/4c3f5ef1b7d758609c7cfbc2d1f631fc45da04d1/Sources/CAudioKitEX/Sequencing/SequencerEngine.mm#L178
>
> I've tried tinkering with it a bit, but without success. This was my idea, it seems to work for the first loop, but it doesn't work for any consecutive loops.
>
> ```c++
> int time = (triggerTime >= lengthInSamples()) ? triggerTime - lengthInSamples() : triggerTime;
> if (time < samplesOfBufferForNewLoop) {
> int offset = (int)time + loopRestartInBuffer;
> ```
>
> **Details (please complete the following information):**
>
> * Type: iPhone 12 Pro, iPad Pro 9.7
>
> * OS: iOS 14.5
>
> * AudioKit Version 5.2
@Truba This should be fixed via df20fdce67a85a441664fb0c7c815a144ecaf8cb. Please re-open another ticket here in AudioKitEX if the same behavior is still present.
Issue opened by @Truba Opening here because this is an AudioKitEX issue - may be related to #10 Original Ticket: AudioKit/AudioKit#2536
Full description
> Hi guys, Sry for not opening in the stack overflow first, but I'm pretty sure something is wrong here. > > **Describe the bug / Expected behavior** > > Sequencer doesn't seem to be triggering note off events if the note off event is placed at the end of the track loop. Here we have an example with just that: > > ```swift > let sequencer = Sequencer() > let track = sequencer.addTrack(for: sampler) > track.loopEnabled = true > track.length = 4 > track.sequence.add(noteNumber: someNote, position: 3, duration: 1) > ``` > > I'm creating a sequencer that outputs to sampler, and I'm also adding just one note. I'm expecting this one note to trigger 2 events. Note On at position 3 and note Off at position 4. But only the note On at position 3 is triggered, note Off at position 4 is missing. > > **To Reproduce is Cookbook** > > I can also replicate is by slightly modifying the Shaker example in Cookbook: https://gist.github.com/Truba/d36ee294817446aac082d929cf3adb7d > > I've updated both tracks to use longer duration, and I've updated `CallbackInstrument` to print the on/off state as well. In the print you can see that Off event is missing for beat at position 3. > > **Where the issue might lie** > > I'm pretty sure the issue lies somewhere around here: > > https://github.com/AudioKit/AudioKit/blob/4c3f5ef1b7d758609c7cfbc2d1f631fc45da04d1/Sources/CAudioKitEX/Sequencing/SequencerEngine.mm#L178 > > I've tried tinkering with it a bit, but without success. This was my idea, it seems to work for the first loop, but it doesn't work for any consecutive loops. > > ```c++ > int time = (triggerTime >= lengthInSamples()) ? triggerTime - lengthInSamples() : triggerTime; > if (time < samplesOfBufferForNewLoop) { > int offset = (int)time + loopRestartInBuffer; > ``` > > **Details (please complete the following information):** > > * Type: iPhone 12 Pro, iPad Pro 9.7 > > * OS: iOS 14.5 > > * AudioKit Version 5.2