Skip to content

Commit

Permalink
Port TFruityPlugHost->OnControllerChanged (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryrec authored May 21, 2020
1 parent 59bb6fd commit 5563990
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 43 deletions.
16 changes: 12 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ impl Plugin for Simple {

InfoBuilder::new_full_gen("Simple", "Simple", self.param_names.len() as u32)
// InfoBuilder::new_effect("Simple", "Simple", self.param_names.len() as u32)
// .want_new_tick()
.want_new_tick()
.with_out_ctrls(1)
.with_out_voices(1)
.loop_out()
// .loop_out()
// Looks like MIDI out doesn't work :(
// https://forum.image-line.com/viewtopic.php?f=100&t=199371
// https://forum.image-line.com/viewtopic.php?f=100&t=199258
.midi_out()
// .midi_out()
.build()
}

Expand Down Expand Up @@ -143,7 +144,8 @@ impl Plugin for Simple {
}

fn tick(&mut self) {
trace!("{} receive new tick", self.tag);
// assign to itself to see it in log
self.host.on_controller(self.tag, 0, 12345_u16);
}

fn idle(&mut self) {
Expand All @@ -168,6 +170,12 @@ impl Plugin for Simple {
value.get::<f32>(),
flags
);

if flags.contains(ProcessParamFlags::INTERNAL_CTRL | ProcessParamFlags::UPDATE_VALUE) {
// will work if assigned to itself
info!("internall control value {}", value.get::<u16>());
}

Box::new(0)
}

Expand Down
5 changes: 5 additions & 0 deletions src/cxx/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ void host_on_parameter(void *host, TPluginTag tag, int index, int value) {
((TFruityPlugHost *)host)->OnParamChanged(tag, index, value);
}

void host_on_controller(void *host, TPluginTag tag, intptr_t index,
intptr_t value) {
((TFruityPlugHost *)host)->OnControllerChanged(tag, index, value);
}

void host_on_hint(void *host, TPluginTag tag, char *text) {
((TFruityPlugHost *)host)->OnHint(tag, text);
}
Expand Down
2 changes: 2 additions & 0 deletions src/cxx/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ extern "C" intptr_t host_on_message(void *host, TPluginTag tag,
Message message);
extern "C" void host_on_parameter(void *host, TPluginTag tag, int index,
int value);
extern "C" void host_on_controller(void *host, TPluginTag tag, intptr_t index,
intptr_t value);
extern "C" void host_on_hint(void *host, TPluginTag tag, char *text);
extern "C" void host_midi_out(void *host, TPluginTag tag, unsigned char status,
unsigned char data1, unsigned char data2,
Expand Down
94 changes: 55 additions & 39 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ impl Host {
}
}

/// Get the version of FL Studio. It is stored in one integer. If the version of FL Studio
/// would be 1.2.3 for example, `version` would be 1002003
pub fn version(&self) -> i32 {
todo!()
}
// Get the version of FL Studio. It is stored in one integer. If the version of FL Studio
// would be 1.2.3 for example, `version` would be 1002003
// pub fn version(&self) -> i32 {
// todo!()
// }

/// Send message to host.
///
Expand Down Expand Up @@ -70,6 +70,21 @@ impl Host {
};
}

/// Notify the host that an internal controller has changed.
///
/// Check out [this](https://forum.image-line.com/viewtopic.php?p=26368#p26368) post for more
/// info about an internal controller implemenation.
pub fn on_controller(&mut self, tag: plugin::Tag, index: usize, value: u16) {
unsafe {
host_on_controller(
*self.host_ptr.get_mut(),
tag.0,
index as intptr_t,
value.as_raw_ptr(),
)
};
}

/// Let the host show a hint, as specified by the parameters.
///
/// - `tag` - the plugin's tag
Expand Down Expand Up @@ -296,6 +311,41 @@ impl Host {
}
}

extern "C" {
fn host_on_parameter(host: *mut c_void, tag: intptr_t, index: c_int, value: c_int);
fn host_on_controller(host: *mut c_void, tag: intptr_t, index: intptr_t, value: intptr_t);
fn host_on_hint(host: *mut c_void, tag: intptr_t, text: *mut c_char);
fn host_midi_out(
host: *mut c_void,
tag: intptr_t,
status: c_uchar,
data1: c_uchar,
data2: c_uchar,
port: c_uchar,
);
fn host_midi_out_del(
host: *mut c_void,
tag: intptr_t,
status: c_uchar,
data1: c_uchar,
data2: c_uchar,
port: c_uchar,
);
fn host_loop_out(host: *mut c_void, tag: intptr_t, message: intptr_t);
fn host_loop_kill(host: *mut c_void, tag: intptr_t, message: intptr_t);
fn host_lock_mix(host: *mut c_void);
fn host_unlock_mix(host: *mut c_void);
fn host_lock_plugin(host: *mut c_void, tag: intptr_t);
fn host_unlock_plugin(host: *mut c_void, tag: intptr_t);
fn host_suspend_out(host: *mut c_void);
fn host_resume_out(host: *mut c_void);
fn host_get_input_buf(host: *mut c_void, tag: intptr_t, offset: intptr_t) -> TIOBuffer;
fn host_get_output_buf(host: *mut c_void, tag: intptr_t, offset: intptr_t) -> TIOBuffer;
fn host_get_insert_buf(host: *mut c_void, tag: intptr_t, offset: intptr_t) -> *mut c_void;
fn host_get_mix_buf(host: *mut c_void, offset: intptr_t) -> *mut c_void;
fn host_get_send_buf(host: *mut c_void, offset: intptr_t) -> *mut c_void;
}

/// Type of the write-only buffer you want to get, using
/// [`Host::buf_write`](../struct.Host.html#method.buf_write).
#[derive(Debug)]
Expand Down Expand Up @@ -336,40 +386,6 @@ pub enum Buffer {
SendWrite(usize),
}

extern "C" {
fn host_on_parameter(host: *mut c_void, tag: intptr_t, index: c_int, value: c_int);
fn host_on_hint(host: *mut c_void, tag: intptr_t, text: *mut c_char);
fn host_midi_out(
host: *mut c_void,
tag: intptr_t,
status: c_uchar,
data1: c_uchar,
data2: c_uchar,
port: c_uchar,
);
fn host_midi_out_del(
host: *mut c_void,
tag: intptr_t,
status: c_uchar,
data1: c_uchar,
data2: c_uchar,
port: c_uchar,
);
fn host_loop_out(host: *mut c_void, tag: intptr_t, message: intptr_t);
fn host_loop_kill(host: *mut c_void, tag: intptr_t, message: intptr_t);
fn host_lock_mix(host: *mut c_void);
fn host_unlock_mix(host: *mut c_void);
fn host_lock_plugin(host: *mut c_void, tag: intptr_t);
fn host_unlock_plugin(host: *mut c_void, tag: intptr_t);
fn host_suspend_out(host: *mut c_void);
fn host_resume_out(host: *mut c_void);
fn host_get_input_buf(host: *mut c_void, tag: intptr_t, offset: intptr_t) -> TIOBuffer;
fn host_get_output_buf(host: *mut c_void, tag: intptr_t, offset: intptr_t) -> TIOBuffer;
fn host_get_insert_buf(host: *mut c_void, tag: intptr_t, offset: intptr_t) -> *mut c_void;
fn host_get_mix_buf(host: *mut c_void, offset: intptr_t) -> *mut c_void;
fn host_get_send_buf(host: *mut c_void, offset: intptr_t) -> *mut c_void;
}

#[repr(C)]
struct TIOBuffer {
buffer: *mut c_void,
Expand Down

0 comments on commit 5563990

Please sign in to comment.