Skip to content

Commit

Permalink
clap: notify editor of param changes
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Mar 18, 2024
1 parent d335194 commit 2831bab
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use clap_sys::{events::*, id::*, plugin::*, process::*, stream::*};

use crate::buffers::{BufferData, BufferType, Buffers};
use crate::bus::{BusDir, Format};
use crate::editor::Editor;
use crate::events::{Data, Event, Events};
use crate::params::{ParamId, ParamInfo, ParamValue};
use crate::plugin::{Host, Plugin, PluginInfo};
Expand Down Expand Up @@ -127,10 +128,14 @@ impl<P: Plugin> Instance<P> {
}
}

fn sync_plugin(&self, plugin: &mut P) {
fn sync_plugin(&self, main_thread_state: &mut MainThreadState<P>) {
for (index, value) in self.plugin_params.poll() {
let id = self.info.params[index].id;
plugin.set_param(id, value);
main_thread_state.plugin.set_param(id, value);

if let Some(editor) = &mut main_thread_state.editor {
editor.param_changed(id, value);
}
}
}
}
Expand Down Expand Up @@ -198,7 +203,7 @@ impl<P: Plugin> Instance<P> {

// Apply any remaining processor -> plugin parameter changes. There won't be any more until
// the next call to `activate`.
instance.sync_plugin(&mut main_thread_state.plugin);
instance.sync_plugin(main_thread_state);

process_state.processor = None;
}
Expand Down Expand Up @@ -598,7 +603,7 @@ impl<P: Plugin> Instance<P> {
let main_thread_state = &mut *instance.main_thread_state.get();

if let Some(&index) = instance.param_map.get(&param_id) {
instance.sync_plugin(&mut main_thread_state.plugin);
instance.sync_plugin(main_thread_state);

let param = &instance.info.params[index];
*value = map_param_out(param, main_thread_state.plugin.get_param(param_id));
Expand Down Expand Up @@ -729,6 +734,10 @@ impl<P: Plugin> Instance<P> {
if let Some(&index) = instance.param_map.get(&event.param_id) {
let value = map_param_in(&instance.info.params[index], event.value);
main_thread_state.plugin.set_param(event.param_id, value);

if let Some(editor) = &mut main_thread_state.editor {
editor.param_changed(event.param_id, value);
}
}
}
}
Expand Down Expand Up @@ -776,7 +785,7 @@ impl<P: Plugin> Instance<P> {
let instance = &*(plugin as *const Self);
let main_thread_state = &mut *instance.main_thread_state.get();

instance.sync_plugin(&mut main_thread_state.plugin);
instance.sync_plugin(main_thread_state);
let result = main_thread_state.plugin.save(&mut StreamWriter(stream));
result.is_ok()
}
Expand Down Expand Up @@ -811,11 +820,15 @@ impl<P: Plugin> Instance<P> {
let instance = &*(plugin as *const Self);
let main_thread_state = &mut *instance.main_thread_state.get();

instance.sync_plugin(&mut main_thread_state.plugin);
instance.sync_plugin(main_thread_state);
if let Ok(_) = main_thread_state.plugin.load(&mut StreamReader(stream)) {
for (index, param) in instance.info.params.iter().enumerate() {
let value = main_thread_state.plugin.get_param(param.id);
instance.processor_params.set(index, value);

if let Some(editor) = &mut main_thread_state.editor {
editor.param_changed(param.id, value);
}
}

return true;
Expand Down

0 comments on commit 2831bab

Please sign in to comment.