Skip to content

Instantly share code, notes, and snippets.

@lijon
Last active June 28, 2022 23:30
Show Gist options
  • Save lijon/24b72cddc4964f73e1437cb31dfeb87d to your computer and use it in GitHub Desktop.
Save lijon/24b72cddc4964f73e1437cb31dfeb87d to your computer and use it in GitHub Desktop.
AUM AUv3 init order

When an AUv3 plugin is loaded from a session in AUM, this is the order of things that happens:

  • If there already was a session loaded, it's saved to a hidden file (for Restore Last State).
  • Wait for above state save to finish.
  • The new AUM session is read from file, loading session title, notes, etc.
  • Reads and sets session properties like sample rate, minimumLatency, metronome, and state for all HW and Mix busses.
  • Empty channel objects are created for all channels in the session.
  • Wait for this to finish.
  • Loads the nodes for all channels:
    • Create the node object.
    • For AUv3 plugins, instantiate the AUAudioUnit object.
    • Enable all inputBusses of the AU, also set shouldAllocateBuffer to NO.
    • Enable all outputBusses of the AU, also set shouldAllocateBuffer to NO.
    • Set sample rate for all busses.
    • Set the AU transportStateBlock, musicalContextBlock and MIDIOutputEventBlock.
    • Call AU allocateRenderResources, failing if it returns false or if renderResourcesAllocated is not set after the call.
    • Grab the AU renderBlock and scheduleParameterBlock.
    • Add observer for kAudioComponentInstanceInvalidationNotification,
    • Get the current values of all AUParameters to store their default values.
    • Set AU fullStateForDocument with the state data stored in the session.
    • Get the list of AUParameters with kAudioUnitParameterFlag_IsWritable from AU, creating MIDI Controls for them.
    • Add observers for latency, audioUnitShortName, parameterTree and currentPreset.
    • Implement an iOS bug hackaround: get and show the view for the plugin, hidden from the user, and then close it again.
    • Setup MIDI outputs for each name in the AU MIDIOutputNames array.
    • Grab the AU scheduleMIDIEventBlock.
    • Setup MIDI inputs for each MIDI input. virtualMIDICableCount is checked to know the number of inputs, but if it says 0 we assume the AU has 1 MIDI input if isMusicDeviceOrEffect is true.
    • Repeat for the next node.
  • Wait for the above to finish for all nodes and channels.
  • For each channel, refresh the list of nodes on the audio thread.
  • Load the MIDI matrix state (setting up MIDI routings)
  • Load the MIDI Controls state (setting up all MIDI parameter bindings)
  • Refresh the list of channels on the audio thread, this brings them into the actual audio render process, and will start calling their renderBlocks.
  • Wait for the channel list refresh to finish, then reset the Transport Clock.
@jgusta
Copy link

jgusta commented Feb 17, 2022

This is pretty cool, thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment