Skip to content

Commit

Permalink
Port TFruityPlug->Idle_Public to Rust (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryrec authored Apr 27, 2020
1 parent f7b25c0 commit 86a4e4b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
6 changes: 5 additions & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use simplelog::{ConfigBuilder, WriteLogger};

use fpsdk::host::{Event, GetName, Host, HostMessage};
use fpsdk::plugin::{Plugin, PluginTag};
use fpsdk::{create_plugin, AsRawPtr, AudioBuffer, Info, InfoBuilder, ProcessParamFlags, ValuePtr};
use fpsdk::{create_plugin, AsRawPtr, Info, InfoBuilder, ProcessParamFlags, ValuePtr};

static ONCE: Once = Once::new();
const LOG_PATH: &str = "simple.log";
Expand Down Expand Up @@ -74,6 +74,10 @@ impl Plugin for Test {
trace!("{} receive new tick", self.tag);
}

fn idle(&mut self) {
trace!("{} idle", self.tag);
}

fn process_param(
&mut self,
index: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/cxx/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int _stdcall PluginWrapper::ProcessParam(int Index, int Value, int RECFlags) {
}

void _stdcall PluginWrapper::Idle_Public() {
// if (_editor) _editor->doIdleStuff();
plugin_idle(adapter);
}

void _stdcall PluginWrapper::Eff_Render(PWAV32FS SourceBuffer,
Expand Down
1 change: 1 addition & 0 deletions src/cxx/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ TimeSignature time_sig_from_raw(intptr_t raw_time_sig);
extern "C" intptr_t plugin_dispatcher(PluginAdapter *adapter, Message message);
extern "C" intptr_t plugin_process_event(PluginAdapter *adapter, Message event);
extern "C" intptr_t plugin_process_param(PluginAdapter *adapter, Message event);
extern "C" void plugin_idle(PluginAdapter *adapter);
extern "C" void plugin_tick(PluginAdapter *adapter);
extern "C" void plugin_midi_tick(PluginAdapter *adapter);
extern "C" void plugin_eff_render(PluginAdapter *adapter,
Expand Down
10 changes: 2 additions & 8 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,10 @@ impl From<ffi::Message> for Event {
debug!("Event::from {:?}", message);

let result = match message.id {
0 => Event::Tempo(
f32::from_raw_ptr(message.index),
message.value as u32,
),
0 => Event::Tempo(f32::from_raw_ptr(message.index), message.value as u32),
1 => Event::MaxPoly(message.index as i32),
2 => Event::MidiPan(message.index as u8, message.value as i8),
3 => Event::MidiVol(
message.index as u8,
f32::from_raw_ptr(message.value),
),
3 => Event::MidiVol(message.index as u8, f32::from_raw_ptr(message.value)),
4 => Event::MidiPitch(message.index as i32),
_ => Event::Unknown,
};
Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ pub unsafe extern "C" fn plugin_process_param(
.as_raw_ptr()
}

/// [`Plugin::idle`](plugin/trait.Plugin.html#method.idle) FFI.
///
/// It supposed to be used internally. Don't use it.
///
/// # Safety
///
/// Unsafe
#[doc(hidden)]
#[no_mangle]
pub unsafe extern "C" fn plugin_idle(adapter: *mut PluginAdapter) {
(*adapter).0.idle();
}

/// [`Plugin::tick`](plugin/trait.Plugin.html#tymethod.tick) FFI.
///
/// It supposed to be used internally. Don't use it.
Expand Down
6 changes: 6 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pub trait Plugin: std::fmt::Debug + RefUnwindSafe + Send + Sync + 'static {
) -> Box<dyn AsRawPtr> {
Box::new(0)
}
/// This function is called continuously. It allows the plugin to perform certain tasks that
/// are not time-critical and which do not take up a lot of time either. For example, in this
/// function you may show a hint message when the mouse moves over a control in the editor.
///
/// Called from GUI thread.
fn idle(&mut self) {}
/// The processing function. The input buffer is empty for generator plugins.
///
/// The buffers are in interlaced 32Bit float stereo format.
Expand Down

0 comments on commit 86a4e4b

Please sign in to comment.