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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/vst/ivsthostapplication.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::base::{tchar, tresult, TBool};
use crate::vst::IMessage;
use vst3_com::interfaces::iunknown::IUnknown;
use vst3_com::{com_interface, IID};

#[com_interface("E564A636-6A8B-8CAF-DB2D-496958E595CC")]
pub trait IHostApplication: IUnknown {
unsafe fn get_name(&self, name: tchar) -> tresult;
unsafe fn create_instance(
&self,
cid: *mut IID,
_iid: *mut IID,
obj: *mut *mut c_void,
) -> tresult;
}

#[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>.

// TODO: Impl the FUID class first for Interface::iid.to_tuid to work
let mut iid: IID = Default::default;
// IMessage::iid.to_tuid(iid);
let m: *mut IMessage = std::ptr::null_mut();
if (host.createInstance(iid, iid, m as *mut *mut c_void /* or invoke as_mut_ptr()? */) == kResultOk) {
Some(m)
}
None
}

#[com_interface("61AC6ED3-85BB-7BB9-1D1C-47E229633AEC")]
pub trait IVst3ToVst2Wrapper: IUnknown { }

#[com_interface("44AA97B6-91B0-0B6F-C095-4688A3B8C6C5")]
pub trait IVst3ToAUWrapper: IUnknown { }

#[com_interface("C6F4BE93-2CB3-1B95-60C5-62426D319DC6")]
pub trait IVst3ToAAXWrapper: IUnknown { }

#[com_interface("E39F35F7-0088-50B7-42CF-4BF944149067")]
pub trait IVst3WrapperMPESupport: IUnknown {
unsafe fn enable_mpe_input_processing(&self, state: TBool) -> tresult;
unsafe fn set_mpe_input_device_settings(
&self,
master_channel: i32,
member_begin_channel: i32,
member_end_channel: i32
) -> tresult;
}
32 changes: 32 additions & 0 deletions src/vst/ivstinterappaudio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::base::{tresult, TBool};
use vst3_com::com_interface;
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.

struct Event {};

#[com_interface("FDC8CDE2-28AE-D45B-68DF-415E0CE5743D")]
pub trait IInterAppAudioHost: IUnknown {
unsafe fn get_screen_size(&self, size: *mut ViewRect, scale: *mut f32) -> tresult;
unsafe fn connected_to_host(&self) -> tresult;
unsafe fn switch_to_host(&self) -> tresult;
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.

unsafe fn show_settings_view(&self) -> tresult;
}

#[com_interface("CFD5D6D7-95B0-B50D-5FC2-4AA16020C72D")]
pub trait IInterAppAudioConnectionNotification: IUnknown {
unsafe fn on_inter_app_audio_connection_state_change(&self, new_state: TBool) -> tresult;
}

#[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

unsafe fn load_next_preset(&self) -> tresult;
unsafe fn load_previous_preset(&self) -> tresult;
}
13 changes: 13 additions & 0 deletions src/vst/ivsttestplugprovider.rs
Original file line number Diff line number Diff line change
@@ -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.

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

#[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

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 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.

// 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)

}
8 changes: 7 additions & 1 deletion src/vst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod ivstcomponent;
mod ivstcontextmenu;
mod ivsteditcontroller;
mod ivstevents;
mod ivsthostapplication;
mod ivstinterappaudio;
mod ivstmessage;
mod ivstmidicontroller;
mod ivstmidilearn;
Expand All @@ -17,6 +19,7 @@ mod ivstplugview;
mod ivstprefetchablesupport;
mod ivstprocesscontext;
mod ivstrepresentation;
mod ivsttestplugprovider;
mod ivstunits;
mod vsttypes;

Expand All @@ -28,6 +31,8 @@ pub use ivstcomponent::*;
pub use ivstcontextmenu::*;
pub use ivsteditcontroller::*;
pub use ivstevents::*;
pub use ivsthostapplication::*;
pub use ivstinterappaudio::*;
pub use ivstmessage::*;
pub use ivstmidicontroller::*;
pub use ivstmidilearn::*;
Expand All @@ -39,7 +44,8 @@ pub use ivstplugview::*;
pub use ivstprefetchablesupport::*;
pub use ivstprocesscontext::*;
pub use ivstrepresentation::*;
pub use ivsttestplugprovider::*;
pub use ivstunits::*;
pub use vsttypes::*;

//todo: ivsttestplugprovider, test/itest vstspeaker.h,
//todo: test/itest vstspeaker.h,