2

An example of how to set up the latest version of AKSequencer is not available, so I had to assume a few things based in the previous version.

I have the following implementation for the AKAppleSequencer that works and there's audio output:

let track = sequencer.newTrack()
track?.setMIDIOutput(sampler.midiIn)
track?.add(noteNumber: 60, velocity: 100, position: AKDuration(beats: 1), duration: AKDuration(beats: 0.25))
sequencer.enableLooping(AKDuration(beats: 4))
sequencer.setTempo(self.defaultTempo)
sequencer.play()

Meanwhile, what I supposed to be enough for the latest AKSequencer has no audio output:

let track: AKSequencerTrack = self.sequencer.addTrack(for: self.sampler)
track.add(noteNumber: 60, velocity: 100, position: 1, duration: 1)
sequencer.length = 4
sequencer.loopEnabled = true
sequencer.tempo = 60
sequencer.play()

Both cases have the sampler connected to the mainMixer and are assigned to the AudioKit.output.

Since this doesn't work for the latest AKSequencer, I thought that the maybe plugging the AKSequencerTrack to the mainMixer and unplugging the sampler to the mainMixer could do? But didn't work!

mainMixer.connect(input: track)

Running out of alternatives! So, after looking for AKSequencerTrack found someone else reporting the same issue (Why is the new AKSequencer not producing any sound?), so tried:

        mainMixer.connect(input: sampler)
        mainMixer.connect(input: track)

Again, no sound! There's also a link to this related topic, which is similar to my previous attempt, which there's no output (How to play MIDI with AudioKit's new AKSequencer), but just to make sure changed to use the AKSampler and loaded a local sound:

sampler.loadSFZ(url: Bundle.main.url(forResource: "clock", withExtension: "wav")!)

Another failure...! There's no sound.

I'm running AudioKit 4.9.5

Just to keep my sanity, there's a method .play in AKSequencerTrack, what happens if I call it?

track.play()

No sound! Ok, what if I change the sampler back to AKSnareSynth?

let t: AKSynthSnare = AKSynthSnare()
sequencer.addTrack(for: t)

Did it play? Nope!

Do I have output at all in non AKSequencer? Yes:

        let t: AKSynthSnare = AKSynthSnare()
        self.mainMixer.connect(input: t)
        t.play(noteNumber: 60,
        velocity: MIDIVelocity(127),
        channel: MIDIChannel(1))

What about the .isPlaying is it Truthy?

        for track in self.sequencer.tracks {
             mainMixer.connect(input: track)
             track.play()
             print("> > > > track.isPlaying: \(track.isPlaying)")
         }

Yes, the isPlaying returns true:

> > > > track.isPlaying: true

But, nope, there's no sound!

I think the AKSequencer is a dark box for now and shouldn't be used unless someone posts an example in Github (which I searched for in source-codes but nothing at the time of writing). Or maybe I'm doing something wrong I don't know, just wasted a day of my life trying different things.

punkbit
  • 7,347
  • 10
  • 55
  • 89

1 Answers1

1

@c_booth provided the answer in the following post ( AudioKit: Using the new AKSequencer with any variety of the callback instruments )

Seems that the loop, tempo are set in the track not the sequencer itself,

// set up a track
let track = seq.addTrack(for: cbInst)
for i in 0 ..< 4 {
    track.add(noteNumber: 60, position: Double(i), duration: 0.5)
}
track.length = 4.0
track.loopEnabled = true
punkbit
  • 7,347
  • 10
  • 55
  • 89