Skip to content

Commit

Permalink
Use plugin's Info from Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-tsurko committed Apr 8, 2020
1 parent 6db2721 commit c0a9edc
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 59 deletions.
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions install.mac.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 100
90 changes: 45 additions & 45 deletions src/cxx/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginAdapter> 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;
Expand All @@ -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 )
{
Expand All @@ -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 )
{
Expand All @@ -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 )
// {
Expand Down Expand Up @@ -115,26 +115,26 @@ 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)
{
strcpy(Name, "Gain");
}
}

int _stdcall Wrapper::ProcessEvent(int EventID, int EventValue, int Flags)
int _stdcall PluginWrapper::ProcessEvent(int EventID, int EventValue, int Flags)
{
return 0;
}

//----------------
//
//----------------
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 )
{
Expand Down Expand Up @@ -182,15 +182,15 @@ 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();
}

//----------------
// 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++)
Expand All @@ -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)
{
}
10 changes: 4 additions & 6 deletions src/cxx/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -46,7 +44,7 @@ class Wrapper : public TFruityPlug
PluginAdapter* adapter;

// parameter
int _params[NumParams];
int _params[1024];

// gain
float _gain;
Expand Down
14 changes: 8 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c0a9edc

Please sign in to comment.