AU Instrument Example doesn't handle note off event when DAW playhead skipped ahead

Running the AU Instrument example provided with Xcode (it's a sine wave generator), it doesn't seem to receive the note off event when the playhead is skipped ahead in the DAW (Logic, for me).

I'm running a separate MIDI Monitor application, and it receives a MIDI note off message when I skip ahead, however, the AU Instrument doesn't receive the note off message.

If the AU instrument example DID receive the MIDI note off event, then it would stop playing the sine signal, however it continues to play the note indefinitely.

To reproduce:

  1. Run AU Instrument example code provided by Xcode. When it asks which application to run in, select Logic.
  2. Create an instrument track, and set the instrument to be the AU Instrument
  3. Create a region in the track and add a note
  4. Set the playhead just before the note and press the play button
  5. Click ahead of the note (just after the note ends)

Result: the AU Instrument is still playing

Expected result: The AU Instrument stops playing (i.e. receives the note off event)

For some reason, Logic sends a Program change (bank, program, options) MIDI message type to the AU Instrument whenever the playhead is moved. Though not ideal, I'm experimenting with using this message to turn off all notes currently playing. Reasoning: if I changed the current program on a physical synthesizer, I'd expect the sounds that are currently being played to stop (since the new patch sounds different than the old patch)

Accepted Answer

I think Logic sometimes calls the AU's reset() method instead of note-off, depending on how you are moving the playhead.

Just override AUAudioUnit.reset() and reset the state of your AU (including releasing any held notes).

AU Instrument Example doesn't handle note off event when DAW playhead skipped ahead
 
 
Q