I am using AudioKit 5 (develop) with Xcode 12 and iOS 14.
I start by creating an array of 28 Oscillators and an array of 28 AmplitudeEnvelopes.
I initialize the 28 AmplitudeEnvelopes with the corresponding Oscillator, and start all of the oscillators, but do not start the AmplitudeEnvelopes.
I connect every AmplitudeEnvelope to a Mixer and then assign the AudioEngine's output to be that Mixer.
When the user touches 1 of the 28 buttons corresponding to one of the AmplitudeEnvelopes, I start that envelope and I get the correct sound coming from the speakers (attack and release is correct).
However, when the user lifts his/her/their finger from the button, I access the array of AmplitudeEnvelopes and stop the corresponding envelope.
However, if I press and hold one button, and then I start to press another, the first AmplitudeEnvelope cuts out automatically.
Why?
In the touch gesture recognizer, I print out "START" and "STOP" whenever the gesture begins and ends, respectively.
I find that starting one envelope does not stop another, so I don't know what the problem is.
@objc func handletouch(gesture: UILongPressGestureRecognizer) {
if gesture.state == .began {
print("START")
self.soft.impactOccurred()
let theindex = (gesture.view as! BUTTON).theindex
let thefrequency = (gesture.view as! BUTTON).midinumber.midiNoteToFrequency()
let theoscillator = self.oscillators[theindex]
theoscillator.frequency = thefrequency
let theenvelope = self.envelopes[theindex]
theenvelope.start()
}
if gesture.state == .ended {
print("STOP")
let theindex = (gesture.view as! BUTTON).theindex
let theenvelope = self.envelopes[theindex]
theenvelope.stop()
}
}