Ok I think saving a preset inside the plugin goes something like this:
In order for the preset to be saved inside your AUv3 app container you'll need to override the currentPreset property in which the selected preset gets passed to the fullStateForDocument property, see code below:
override var supportsUserPresets: Bool{ get{ return true } }
private var _currentPreset: AUAudioUnitPreset?
override var currentPreset: AUAudioUnitPreset? {
get { return _currentPreset }
set {
// If the newValue is nil, return.
guard let preset = newValue else {
_currentPreset = nil
return
}
// Factory presets need to always have a number >= 0.
if preset.number >= 0 {
_currentPreset = preset
// User presets are always negative.
}else {
// Attempt to restore the archived state for this user preset.
do {
fullStateForDocument = try presetState(for: preset)
// Set the currentPreset after successfully restoring the state.
_currentPreset = preset
} catch {
print("Unable to restore set for preset \(preset.name)")
}
}
}
}
override var fullState: [String: Any]? {
get {
// save preset
var state = super.fullState ?? [:]
state["fullStateParams"] = [:] // your dictionary here
return state
}
set {
// load preset
if let state:[String:Any] = newValue{
if let stateFullParams:[String:[String:Any]] = state["fullStateParams"] as? [String:[String:Any]]{
loadPreset(array: stateFullParams) // do something with your dictionary
}
}
}
}
More information can be found here:
https://developer.apple.com/videos/play/wwdc2019/509/
https://developer.apple.com/documentation/audiotoolbox/audio_unit_v3_plug-ins/incorporating_audio_effects_and_instruments
https://developer.apple.com/documentation/audiotoolbox/audio_unit_v3_plug-ins/creating_custom_audio_effects
Topic:
Media Technologies
SubTopic:
Audio
Tags: