From c0a9edcd6b0d24ec304615a96e97c6428908ebf7 Mon Sep 17 00:00:00 2001 From: Ales Tsurko Date: Wed, 8 Apr 2020 19:23:16 +0300 Subject: [PATCH] Use plugin's Info from Rust --- build.rs | 3 +- examples/simple.rs | 2 +- install.mac.sh | 13 +++++++ rustfmt.toml | 1 + src/cxx/wrapper.cpp | 90 ++++++++++++++++++++++----------------------- src/cxx/wrapper.h | 10 ++--- src/lib.rs | 14 ++++--- 7 files changed, 74 insertions(+), 59 deletions(-) create mode 100755 install.mac.sh create mode 100644 rustfmt.toml diff --git a/build.rs b/build.rs index 53d803d..ecb45a3 100644 --- a/build.rs +++ b/build.rs @@ -5,9 +5,10 @@ fn main() { .file("src/cxx/fp_plugclass.cpp") .file("src/cxx/wrapper.cpp") .flag("-std=c++11") - .compile("pocrs"); + .compile("fpsdk"); println!("cargo:rerun-if-changed=src/lib.rs"); println!("cargo:rerun-if-changed=src/cxx/fp_plugclass.h"); + println!("cargo:rerun-if-changed=src/cxx/wrapper.h"); println!("cargo:rerun-if-changed=src/cxx/wrapper.cpp"); } diff --git a/examples/simple.rs b/examples/simple.rs index 0e0fdcd..40fe7d8 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -12,7 +12,7 @@ impl Plugin for Test { } fn info(&self) -> Info { - InfoBuilder::new_effect("Simple", "Simple", 1).build() + InfoBuilder::new_effect("Simple Rs", "Simple Rs", 1).build() } fn create_instance(&mut self, host: Host, tag: i32) { diff --git a/install.mac.sh b/install.mac.sh new file mode 100755 index 0000000..605b300 --- /dev/null +++ b/install.mac.sh @@ -0,0 +1,13 @@ +#! /bin/sh + +# installs release build into FL effects folder +# Usage: +# install.mac.sh name destination_name + +name=$1 +dest_name=$2 +PLUG_PATH="/Applications/FL Studio 20.app/Contents/Resources/FL/Plugins/Fruity" + +rm -rf "${PLUG_PATH}/Effects/${dest_name}" +mkdir "${PLUG_PATH}/Effects/${dest_name}" +mv "target/release/examples/lib${name}.dylib" "${PLUG_PATH}/Effects/${dest_name}/${dest_name}_x64.dylib" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..758d417 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 100 diff --git a/src/cxx/wrapper.cpp b/src/cxx/wrapper.cpp index 0954de2..0a7022e 100644 --- a/src/cxx/wrapper.cpp +++ b/src/cxx/wrapper.cpp @@ -2,31 +2,31 @@ #include "wrapper.h" #include "../../target/cxxbridge/src/lib.rs.h" -//--------------------- -// Plug-in information -//--------------------- -char dllname[] = "Pocrs"; -char name[] = "Pocrs"; -TFruityPlugInfo PlugInfo = -{ - CurrentSDKVersion, - dllname, - name, - FPF_Type_Effect, - 1 // the amount of parameters -}; - TFruityPlug& create_plug_instance_c(TFruityPlugHost& Host, int Tag, rust::Box adapter) { - Wrapper* wrapper = new Wrapper(&Host, Tag, *adapter); + Info info = plugin_info(*adapter); + + char* lname = new char[info.long_name.size()+1]; + std::strcpy(lname, info.long_name.data()); + char* sname = new char[info.short_name.size()+1]; + std::strcpy(sname, info.short_name.data()); + + PFruityPlugInfo c_info = new TFruityPlugInfo { + info.sdk_version, + lname, + sname, + info.flags, + info.num_params, + info.def_poly, + info.num_out_ctrls, + info.num_out_voices + }; + PluginWrapper* wrapper = new PluginWrapper(&Host, Tag, *adapter, c_info); return *((TFruityPlug*) wrapper); } -//---------------- -// constructor -//---------------- -Wrapper::Wrapper(TFruityPlugHost *Host, int Tag, PluginAdapter& adap) +PluginWrapper::PluginWrapper(TFruityPlugHost *Host, int Tag, PluginAdapter& adap, PFruityPlugInfo info) { - Info = &PlugInfo; + Info = info; HostTag = Tag; EditorHandle = 0; _host = Host; @@ -38,18 +38,18 @@ Wrapper::Wrapper(TFruityPlugHost *Host, int Tag, PluginAdapter& adap) _params[0] = (1<<16); } -//---------------- -// destructor -//---------------- -Wrapper::~Wrapper() +PluginWrapper::~PluginWrapper() { delete _editor; + delete Info->LongName; + delete Info->ShortName; + delete Info; } //------------------------- // save or load parameter //------------------------- -void _stdcall Wrapper::SaveRestoreState(IStream *Stream, BOOL Save) +void _stdcall PluginWrapper::SaveRestoreState(IStream *Stream, BOOL Save) { if( Save ) { @@ -62,7 +62,7 @@ void _stdcall Wrapper::SaveRestoreState(IStream *Stream, BOOL Save) // load paremeters unsigned long length = 0; Stream->Read(_params, sizeof(_params), &length); - for( int ii = 0; ii < NumParams; ii++ ) + for( int ii = 0; ii < Info->NumParams; ii++ ) { if( ii == 0 ) { @@ -81,7 +81,7 @@ void _stdcall Wrapper::SaveRestoreState(IStream *Stream, BOOL Save) //---------------- // //---------------- -intptr_t _stdcall Wrapper::Dispatcher(intptr_t ID, intptr_t Index, intptr_t Value) +intptr_t _stdcall PluginWrapper::Dispatcher(intptr_t ID, intptr_t Index, intptr_t Value) { // if( ID == FPD_ShowEditor ) // { @@ -115,7 +115,7 @@ intptr_t _stdcall Wrapper::Dispatcher(intptr_t ID, intptr_t Index, intptr_t Valu //---------------- // //---------------- -void _stdcall Wrapper::GetName(int Section, int Index, int Value, char *Name) +void _stdcall PluginWrapper::GetName(int Section, int Index, int Value, char *Name) { if(Section == FPN_Param) { @@ -123,7 +123,7 @@ void _stdcall Wrapper::GetName(int Section, int Index, int Value, char *Name) } } -int _stdcall Wrapper::ProcessEvent(int EventID, int EventValue, int Flags) +int _stdcall PluginWrapper::ProcessEvent(int EventID, int EventValue, int Flags) { return 0; } @@ -131,10 +131,10 @@ int _stdcall Wrapper::ProcessEvent(int EventID, int EventValue, int Flags) //---------------- // //---------------- -int _stdcall Wrapper::ProcessParam(int Index, int Value, int RECFlags) +int _stdcall PluginWrapper::ProcessParam(int Index, int Value, int RECFlags) { int ret = 0; - if( Index < NumParams ) + if( Index < Info->NumParams ) { if( RECFlags & REC_UpdateValue ) { @@ -182,7 +182,7 @@ int _stdcall Wrapper::ProcessParam(int Index, int Value, int RECFlags) //---------------- // idle //---------------- -void _stdcall Wrapper::Idle_Public() +void _stdcall PluginWrapper::Idle_Public() { // if (_editor) _editor->doIdleStuff(); } @@ -190,7 +190,7 @@ void _stdcall Wrapper::Idle_Public() //---------------- // effect //---------------- -void _stdcall Wrapper::Eff_Render(PWAV32FS SourceBuffer, PWAV32FS DestBuffer, int Length) +void _stdcall PluginWrapper::Eff_Render(PWAV32FS SourceBuffer, PWAV32FS DestBuffer, int Length) { float gain = _gain; for (int ii = 0; ii < Length; ii++) @@ -200,54 +200,54 @@ void _stdcall Wrapper::Eff_Render(PWAV32FS SourceBuffer, PWAV32FS DestBuffer, in } } -void _stdcall Wrapper::Gen_Render(PWAV32FS DestBuffer, int& Length) +void _stdcall PluginWrapper::Gen_Render(PWAV32FS DestBuffer, int& Length) { } -TVoiceHandle _stdcall Wrapper::TriggerVoice(PVoiceParams VoiceParams, intptr_t SetTag) +TVoiceHandle _stdcall PluginWrapper::TriggerVoice(PVoiceParams VoiceParams, intptr_t SetTag) { return TVoiceHandle(); } -void _stdcall Wrapper::Voice_Release(TVoiceHandle Handle) +void _stdcall PluginWrapper::Voice_Release(TVoiceHandle Handle) { } -void _stdcall Wrapper::Voice_Kill(TVoiceHandle Handle) +void _stdcall PluginWrapper::Voice_Kill(TVoiceHandle Handle) { } -int _stdcall Wrapper::Voice_ProcessEvent(TVoiceHandle Handle, int EventID, int EventValue, int Flags) +int _stdcall PluginWrapper::Voice_ProcessEvent(TVoiceHandle Handle, int EventID, int EventValue, int Flags) { return 0; } -int _stdcall Wrapper::Voice_Render(TVoiceHandle Handle, PWAV32FS DestBuffer, int& Length) +int _stdcall PluginWrapper::Voice_Render(TVoiceHandle Handle, PWAV32FS DestBuffer, int& Length) { return 0; } -void _stdcall Wrapper::NewTick() +void _stdcall PluginWrapper::NewTick() { } -void _stdcall Wrapper::MIDITick() +void _stdcall PluginWrapper::MIDITick() { } -void _stdcall Wrapper::MIDIIn(int& Msg) +void _stdcall PluginWrapper::MIDIIn(int& Msg) { } -void _stdcall Wrapper::MsgIn(intptr_t Msg) +void _stdcall PluginWrapper::MsgIn(intptr_t Msg) { } -int _stdcall Wrapper::OutputVoice_ProcessEvent(TOutVoiceHandle Handle, int EventID, int EventValue, int Flags) +int _stdcall PluginWrapper::OutputVoice_ProcessEvent(TOutVoiceHandle Handle, int EventID, int EventValue, int Flags) { return 0; } -void _stdcall Wrapper::OutputVoice_Kill(TVoiceHandle Handle) +void _stdcall PluginWrapper::OutputVoice_Kill(TVoiceHandle Handle) { } diff --git a/src/cxx/wrapper.h b/src/cxx/wrapper.h index 784f75d..1dafa5b 100644 --- a/src/cxx/wrapper.h +++ b/src/cxx/wrapper.h @@ -3,17 +3,15 @@ #include "fp_plugclass.h" #include "../../target/cxxbridge/rust/cxx.h" -const int NumParams = 1; // the amount of parameters - struct PluginAdapter; class sample_editor {}; -class Wrapper : public TFruityPlug +class PluginWrapper : public TFruityPlug { public: - Wrapper(TFruityPlugHost *Host, int Tag, PluginAdapter& adapter); - virtual ~Wrapper(); + PluginWrapper(TFruityPlugHost *Host, int Tag, PluginAdapter& adapter, PFruityPlugInfo info); + virtual ~PluginWrapper(); // from TFruityPlug virtual intptr_t _stdcall Dispatcher(intptr_t ID, intptr_t Index, intptr_t Value); @@ -46,7 +44,7 @@ class Wrapper : public TFruityPlug PluginAdapter* adapter; // parameter - int _params[NumParams]; + int _params[1024]; // gain float _gain; diff --git a/src/lib.rs b/src/lib.rs index 9395cb3..e02e370 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,17 +42,18 @@ #[doc(hidden)] #[cxx::bridge] pub mod ffi { - /// This structure holds some information about the plugin that is used by the host. It is the same - /// for all instances of the same plugin. + /// This structure holds some information about the plugin that is used by the host. It is the + /// same for all instances of the same plugin. /// /// Instantiate it using [`InfoBuilder`](struct.InfoBuilder.html). pub struct Info { - /// This has to be the version of the SDK used to create the plugin. This value is available in - /// the constant CurrentSDKVersion + /// This has to be the version of the SDK used to create the plugin. This value is + /// available in the constant CurrentSDKVersion pub sdk_version: i32, /// The name of the plugin dll, without the extension (.dll) pub long_name: String, - /// Short plugin name, to be used in labels to tell the user which plugin he is working with + /// Short plugin name, to be used in labels to tell the user which plugin he is working + /// with pub short_name: String, flags: i32, /// The number of parameters for this plugin @@ -276,7 +277,8 @@ impl InfoBuilder { self } - /// The plugin will send delayed messages to itself (will require the internal sync clock to be enabled). + /// The plugin will send delayed messages to itself (will require the internal sync clock to be + /// enabled). pub fn msg_out(mut self) -> Self { self.flags |= 1 << 17; self