Skip to content

Commit

Permalink
Port TFruityPlug->MIDITick (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-tsurko authored Apr 22, 2020
1 parent 5209e33 commit 8fe2f4c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/cxx/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ int _stdcall PluginWrapper::ProcessEvent(int EventID, int EventValue,
return 0;
}

//----------------
//
//----------------
int _stdcall PluginWrapper::ProcessParam(int Index, int Value, int RECFlags) {
int ret = 0;
if (Index < Info->NumParams) {
Expand Down Expand Up @@ -189,7 +186,7 @@ int _stdcall PluginWrapper::Voice_Render(TVoiceHandle Handle,

void _stdcall PluginWrapper::NewTick() { plugin_tick(adapter); }

void _stdcall PluginWrapper::MIDITick() {}
void _stdcall PluginWrapper::MIDITick() { plugin_midi_tick(adapter); }

void _stdcall PluginWrapper::MIDIIn(int &Msg) {}

Expand Down
1 change: 1 addition & 0 deletions src/cxx/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ 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" void plugin_tick(PluginAdapter *adapter);
extern "C" void plugin_midi_tick(PluginAdapter *adapter);
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ pub unsafe extern "C" fn plugin_tick(adapter: *mut PluginAdapter) {
(*adapter).0.tick();
}

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

/// The result returned from dispatcher function.
pub trait DispatcherResult {
/// Dispatcher result type should implement this method for interoperability with FL API.
Expand Down
14 changes: 12 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Plugin related stuff.
use std::panic::RefUnwindSafe;

use log::warn;

use crate::host::{Event, GetName, Host, HostMessage};
use crate::{DispatcherResult, Info};

Expand Down Expand Up @@ -32,7 +34,7 @@ pub trait Plugin: std::fmt::Debug + RefUnwindSafe {
/// Process an event sent by the host.
///
/// Can be called from GUI or mixer threads.
fn process_event(&mut self, event: Event);
fn process_event(&mut self, _event: Event) {}
/// Gets called before a new tick is mixed (not played), if the plugin added
/// [`PluginBuilder::want_new_tick`](../struct.InfoBuilder.html#method.want_new_tick) into
/// [`Info`](../struct.Info.html).
Expand All @@ -42,5 +44,13 @@ pub trait Plugin: std::fmt::Debug + RefUnwindSafe {
/// here.
///
/// Called from mixer thread.
fn tick(&mut self);
fn tick(&mut self) {}
/// **NOT USED YET, OMIT THIS METHOD**
///
/// This is called before a new midi tick is played (not mixed).
///
/// Can be called from GUI or mixer threads.
fn midi_tick(&mut self) {
warn!("Host doesn't use this method.");
}
}

0 comments on commit 8fe2f4c

Please sign in to comment.