Skip to content

Can't change parameter value from pluginInstanceAddedToDocument method #378

@marinoo3

Description

@marinoo3

Apple Feedback Assistant ID: MISSING

DESCRIBE THE BUG:
I can set the value of a int slider parameter like so:

let paramAPISettings = _apiManager!.api(for: FxParameterSettingAPI_v5.self) as! FxParameterSettingAPI_v5
        
let newToken = Int32.random(in: 1...999999) // generate random token
paramAPISettings.setIntValue(newToken, toParameter: 1, at: CMTime.zero)

However, calling this code in the pluginInstanceAddedToDocument method returns the following error:

Thread 3: Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value

TO REPRODUCE:
Create a int slider like so:

func addParameters() throws {
   let paramAPI = _apiManager!.api(for: FxParameterCreationAPI_v5.self) as! FxParameterCreationAPI_v5
   paramAPI.addIntSlider(withName: "token", parameterID: 1, defaultValue: 0, parameterMin: 0, parameterMax: 999999, sliderMin: 0, sliderMax: 999999, delta: 1, parameterFlags: FxParameterFlags(kFxParameterFlag_DEFAULT | kFxParameterFlag_NOT_ANIMATABLE))
}

Programmatically set its value in the pluginInstanceAddedToDocument method:

func pluginInstanceAddedToDocument() {
    let paramAPISettings = _apiManager!.api(for: FxParameterSettingAPI_v5.self) as! FxParameterSettingAPI_v5
        
    let newToken = Int32.random(in: 1...999999) // generate new token
    paramAPISettings.setIntValue(newToken, toParameter: 1, at: CMTime.zero)
}

EXPECTED BEHAVIOUR:
From Apple documentation: "The pluginInstanceAddedToDocument is called when a new plug-in instance is created or a document is loaded and an existing instance is deserialized. When the host calls this method, the plug-in is a part of the document and the various API objects work as expected."

Retrieving the value of the parameter works as expected using the FxParameterRetrievalAPI_v6 protocol, I'm wondering why FxParameterSettingAPI_v5.setIntValue doesn't.

I'm quite new to FxPlugs and swift development, maybe I'm missing something.


SCREENSHOTS:
N/A


SPECS:

  • 2021 14-inch MacBook Pro (M1 Max, 32GB RAM, 2TB SSD)
  • macOS Sonoma 14.3
  • Final Cut Pro 10.7.1
  • Motion 5.7

ADDITIONAL COMMENTS:
I tried to set the parameter value from a pushbutton event, it worked. The issue occurs when using the pluginInstanceAddedToDocument method.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions