Sampler
public final class Sampler : SubscriptionManager<SamplerEvent>
This class encapsulates Apple’s AVAudioUnitSampler in order to load MIDI sound bank.
-
Largest MIDI value available for the last key
Declaration
Swift
public static let maxMidiValue: Int
-
The notification that
Declaration
Swift
public static let setTuningNotification: TypedNotification<Float>
-
Undocumented
Declaration
Swift
public static let setPitchBendRangeNotification: TypedNotification<Int>
-
Undocumented
Declaration
Swift
public typealias StartResult = Result<AVAudioUnitSampler?, SamplerStartFailure>
-
Undocumented
See moreDeclaration
Swift
public enum Mode
-
Undocumented
Declaration
Swift
public private(set) var auSampler: AVAudioUnitSampler? { get }
-
Create a new instance of a Sampler.
In
standalone
mode, the sampler will create aAVAudioEngine
to use to host the sampler and to generate sound. InaudioUnit
mode, the sampler will exist on its own and will expect an AUv3 host to provide the appropriate context to generate sound from its output.Declaration
Swift
public init(mode: Mode, activePatchManager: ActivePatchManager, reverb: ReverbEffect?, delay: DelayEffect?)
Parameters
mode
determines how the sampler is hosted.
-
Connect up a sampler and start the audio engine to allow the sampler to make sounds.
Declaration
Swift
public func start() -> StartResult
Return Value
Result value indicating success or failure
-
Stop the existing audio engine. Releases the sampler and engine.
Declaration
Swift
public func stop()
-
Ask the sampler to use the active preset held by the ActivePatchManager.
Declaration
Swift
public func loadActivePreset(_ afterLoadBlock: (() -> Void)? = nil) -> StartResult
Parameters
afterLoadBlock
callback to invoke after the load is successfully done
Return Value
Result instance indicating success or failure
-
Set the AVAudioUnitSampler tuning value
Declaration
Swift
public func setTuning(_ value: Float)
Parameters
value
the value to set in cents (+/- 2400)
-
Set the AVAudioUnitSampler masterGain value
Declaration
Swift
public func setGain(_ value: Float)
Parameters
value
the value to set
-
Set the AVAudioUnitSampler stereoPan value
Declaration
Swift
public func setPan(_ value: Float)
Parameters
value
the value to set
-
Start playing a sound at the given pitch. If given velocity is 0, then stop playing the note.
Declaration
Swift
public func noteOn(_ midiValue: UInt8, velocity: UInt8)
Parameters
midiValue
MIDI value that indicates the pitch to play
velocity
how loud to play the note (1-127)
-
Stop playing a sound at the given pitch.
Declaration
Swift
public func noteOff(_ midiValue: UInt8)
Parameters
midiValue
MIDI value that indicates the pitch to stop
-
After-touch for the given playing note.
Declaration
Swift
public func polyphonicKeyPressure(_ midiValue: UInt8, pressure: UInt8)
Parameters
midiValue
MIDI value that indicates the pitch being played
pressure
the after-touch pressure value for the key
-
After-touch for the whole channel.
Declaration
Swift
public func channelPressure(_ pressure: UInt8)
Parameters
pressure
the after-touch pressure value for all of the playing keys
-
Pitch-bend controller value.
Declaration
Swift
public func pitchBendChange(_ value: UInt16)
Parameters
value
the controller value. Middle is 0x200
-
Undocumented
Declaration
Swift
public func controlChange(_ controller: UInt8, value: UInt8)
-
Undocumented
Declaration
Swift
public func programChange(_ program: UInt8)
-
For the future – AVAudioUnitSampler does not support this
Declaration
Swift
public func setPitchBendRange(_ value: Int)