Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't change parameter value from pluginInstanceAddedToDocument method #378

Open
marinoo3 opened this issue Jul 5, 2024 · 10 comments
Open

Comments

@marinoo3
Copy link

marinoo3 commented Jul 5, 2024

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.

@latenitefilms
Copy link
Contributor

latenitefilms commented Jul 5, 2024

Great question! I'll try and reproduce and find the answer for you. In the meantime, have you tried wrapping in a FxCustomParameterActionAPI_v4?

let actionAPI = _apiManager!.api(for: FxCustomParameterActionAPI_v4.self) as! FxCustomParameterActionAPI_v4
let time = actionAPI.currentTime


actionAPI.startAction(_:self)
let settingAPI = _apiManager!.api(for: FxParameterSettingAPI_v5.self) as! FxParameterSettingAPI_v5
settingAPI.setCustomParameterValue(myObject, toParameter: myParameterID, at: time)
actionAPI.endAction(_:self)

@belisoful
Copy link

There are a few bugs like this in the APIs for FCP. I can confirm this bug in my own experience. I didn't know to report it here. Valid.

@marinoo3
Copy link
Author

marinoo3 commented Jul 6, 2024

Great question! I'll try and reproduce and find the answer for you. In the meantime, have you tried wrapping in a FxCustomParameterActionAPI_v4?

let actionAPI = _apiManager!.api(for: FxCustomParameterActionAPI_v4.self) as! FxCustomParameterActionAPI_v4
let time = actionAPI.currentTime


actionAPI.startAction(_:self)
let settingAPI = _apiManager!.api(for: FxParameterSettingAPI_v5.self) as! FxParameterSettingAPI_v5
settingAPI.setCustomParameterValue(myObject, toParameter: myParameterID, at: time)
actionAPI.endAction(_:self)

Thanks for your reply, I tried using a custom parameter and FxCustomParameterActionAPI_v4 as suggested. I got the same error trying to access the setting API. Plus a warning on the console says:

A plugin attempted to call [-FxCustomParameterActionAPI startAction:] at an inappropriate time. Plugins should not call this method when they have been called by the host application.

@marinoo3
Copy link
Author

marinoo3 commented Jul 9, 2024

@belisoful did you find a workaround or a a method from which we can call the FxParameterSettingAPI_v5 API? It returns nil everywhere I try...

@latenitefilms
Copy link
Contributor

Someone on the Final Cut Pro team tells me they can't spot any obvious issues in the code, and it's not a known issue. Are you able to upload a very basic sample project with steps to reproduce?

@marinoo3
Copy link
Author

marinoo3 commented Jul 9, 2024

Sure, here is a simplified project that highlight the error:
StudioUtility.zip

Simply run the xcode project, launch Motion and try to use the effect in Filters > StudioUtility Group > StudioUtility

In the project you can see that retrieving the parameter value works, while trying to set a new value doesn't as the FxParameterSettingAPI_v5 API returns a nil object

@belisoful
Copy link

@belisoful did you find a workaround or a a method from which we can call the FxParameterSettingAPI_v5 API? It returns nil everywhere I try...

No. I didn't. It's why I put that project on hold for FCP 10.7.1.

@marinoo3
Copy link
Author

@latenitefilms Any news on the error?

@belisoful
Copy link

belisoful commented Aug 13, 2024

I have not tested anything in FCP 10.8 yet. Been busy doing edits. :)

ooooo. 10.8.1 is out with bug fixes.... I'll have to check this out.....

@latenitefilms
Copy link
Contributor

I'll test in 10.8.1 and chase up with the Final Cut Pro team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants