This demo is based off of the work by Jeff Cooper.
Before reading this, we highly recommend you to read the tutorial on Hello World example first. This example is included in AudioKit in the Examples directory with versions for iOS and macOS.
First we create an instance of an Conductor() to follow the principles of MVC (Model-View-Controller):
And then the file Conductor.swift comes where amazing happens. We create the object of AKMIDI() that handles both the MIDI input and output, an instance of AKFMOscillatorBank() to generate audio, and the last property stands for the pointer to Apple’s Reverb2 Audio Unit.
Then we create some instruments, where AKMIDIInstrument() is a version of AKInstrument() specifically targeted to instruments that should be triggerable via MIDI or sequenced with the sequencer.
Finally, we create a basic sequencer, a node that mixes its inputs to a single output, and a dynamic node.
During the init() function we initialize the instruments, mix them to a single output, and then start the AudioKit engine.
And then we're able to generate a new track for our sequence for every instrument we've got so far (bass drum, snare drum, snare ghost):