From 8fe2f4caedd947e42062ca6a8412c9d2dd16df28 Mon Sep 17 00:00:00 2001 From: Ales Tsurko Date: Thu, 23 Apr 2020 02:51:53 +0300 Subject: [PATCH] Port TFruityPlug->MIDITick (#69) --- src/cxx/wrapper.cpp | 5 +---- src/cxx/wrapper.h | 1 + src/lib.rs | 13 +++++++++++++ src/plugin.rs | 14 ++++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/cxx/wrapper.cpp b/src/cxx/wrapper.cpp index de0d464..09f8e21 100644 --- a/src/cxx/wrapper.cpp +++ b/src/cxx/wrapper.cpp @@ -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) { @@ -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) {} diff --git a/src/cxx/wrapper.h b/src/cxx/wrapper.h index 34dfada..570cd83 100644 --- a/src/cxx/wrapper.h +++ b/src/cxx/wrapper.h @@ -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); diff --git a/src/lib.rs b/src/lib.rs index fc37041..09f42c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. diff --git a/src/plugin.rs b/src/plugin.rs index 5881a88..83cacd4 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -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}; @@ -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). @@ -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."); + } }