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

Added missing interface bindings #24

Closed
wants to merge 5 commits into from
Closed

Added missing interface bindings #24

wants to merge 5 commits into from

Conversation

demberto
Copy link

Interfaces for 3-6 from issue #15 have been added. Some interfaces need implementing the FUID class.

@m-hilgendorf
Copy link
Member

Thanks for the PR!

We can merge this and #25 . #26 after resolving the compilation and formatting errors.

}

#[inline]
pub unsafe fn allocate_message(host: *mut dyn IHostApplication) -> Option<*mut dyn IMessage> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation won't work, and we should probably write a more idiomatic Rust solution anyway. You can't call a method on *mut dyn Interface, it needs to be wrapped with ComPtr to handle the dispatch. When you pass in the msg argument, it needs to be by reference cast to a void pointer (&mut iid as *mut _ as *mut c_void).

The FUID class doesn't need to be implemented, you can get IMessage's IID using <IMessage as vst3_com::ComInterface>::IID.

I think this method should return ComRc instead of Option<*mut dyn IMessage>.

use vst3_com::interfaces::iunknown::IUnknown;

// Defined elsewhere
struct ViewRect {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewRect is in crate::gui and Event is in crate::vst.

unsafe fn send_remote_control_event(&self, event: u32) -> tresult;
unsafe fn get_host_icon(&self, icon: *mut *mut c_void) -> tresult;
unsafe fn schedule_event_from_ui(&self, event: &mut Event) -> tresult;
unsafe fn create_preset_manager(&self, cid: *const IID) -> Option<*mut IInterAppAudioPresetManager>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return *mut dyn IInterappAudioPresetManager and not an Option.

@@ -0,0 +1,13 @@
use crate::base::tresult;
use crate::vst::{IComponent, IEditController, IStringResult};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IStringResult is in crate::base.

unsafe fn get_component(&self) -> Option<*mut IComponent>;
unsafe fn get_controller(&self) -> Option<*mut IEditController>;
unsafe fn release_plugin(component: *mut IComponent, controller: *mut IEditController) -> tresult;
unsafe const fn get_sub_categories(&self, result: &mut IStringResult) -> tresult;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove const here, not the same thing as const in C++.

change to *mut IStringResult. References can't be used as args in a COM method, it's equivalent to the reference type from the C++ definition.


#[com_interface("BAB58FD6-8F97-6E1E-4E99-430F86BE70EE")]
pub trait ITestPlugProvider: IUnknown {
unsafe fn get_component(&self) -> Option<*mut IComponent>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return *mut dyn IComponent instead of an Option

#[com_interface("BAB58FD6-8F97-6E1E-4E99-430F86BE70EE")]
pub trait ITestPlugProvider: IUnknown {
unsafe fn get_component(&self) -> Option<*mut IComponent>;
unsafe fn get_controller(&self) -> Option<*mut IEditController>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return *mut dyn IEditController instead of an option

Copy link
Member

@MirkoCovizzi MirkoCovizzi Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-hilgendorf Rust's fat pointers don't behave well across language boundaries, these should return *mut c_void pointers. Here there is some more information #23

Copy link
Member

@m-hilgendorf m-hilgendorf Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! For the moment returning fat pointers "works" in that they can be cast to ComPtr or ComRc for dispatching to methods, like we do with the IParameterChanges wrapping in the examples.

I think to be more explicit we should return these as pointers to vtables, which is how ComPtr works under the hood, e.g.

unsafe fn get_component(&self) -> *mut <dyn IComponent as ComInterface>::VTable

Which I believe is what actually goes across the FFI boundary, and keeps the return type explicit so we don't have to cross reference source code every time we call a method.

Copy link
Member

@MirkoCovizzi MirkoCovizzi Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should work and it would be more explicit because it shows the specific interface returned! Very good!

unsafe fn get_controller(&self) -> Option<*mut IEditController>;
unsafe fn release_plugin(component: *mut IComponent, controller: *mut IEditController) -> tresult;
unsafe const fn get_sub_categories(&self, result: &mut IStringResult) -> tresult;
// unsafe const fn get_component_uid(uid: &mut FUID) -> tresult; TODO: FUID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use *mut vst3_com::IID instead of FUID (same thing)

#[com_interface("DDEF3FC9-B4B3-809A-46C9-4E1DADE6FCC4")]
pub trait IInterAppAudioPresetManager: IUnknown {
unsafe fn run_load_preset_browser(&self) -> tresult;
unsafe fn run_save_preset_browser(&self) -> tresult;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

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

Successfully merging this pull request may close these issues.

3 participants