Skip to content

Commit 6776b92

Browse files
committed
Simple CLAP undo extension support
Call change_made() whenever we call mark_dirty() Seems to fix undo behavior in Bitwig at least
1 parent e9a789e commit 6776b92

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

plinth-plugin/src/formats/clap/extensions/gui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl<P: ClapPlugin> Gui<P> {
9292
instance.host_ext_gui,
9393
instance.host_ext_params,
9494
instance.host_ext_state,
95+
instance.host_ext_undo,
9596
instance.parameter_event_map.clone(),
9697
));
9798

plinth-plugin/src/formats/clap/host.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::{sync::{atomic::Ordering, Arc}};
1+
use std::{ptr::null, sync::{Arc, atomic::Ordering}};
22

3-
use clap_sys::{ext::{gui::clap_host_gui, params::clap_host_params, state::clap_host_state}, host::clap_host};
3+
use clap_sys::{ext::{draft::undo::clap_host_undo, gui::clap_host_gui, params::clap_host_params, state::clap_host_state}, host::clap_host};
44

55
use crate::{Host, ParameterId, ParameterValue};
66

@@ -11,6 +11,7 @@ pub struct ClapHost {
1111
host_ext_gui: *const clap_host_gui,
1212
host_ext_params: *const clap_host_params,
1313
host_ext_state: *const clap_host_state,
14+
host_ext_undo: *const clap_host_undo,
1415
parameter_event_map: Arc<ParameterEventMap>,
1516
}
1617

@@ -20,6 +21,7 @@ impl ClapHost {
2021
host_ext_gui: *const clap_host_gui,
2122
host_ext_params: *const clap_host_params,
2223
host_ext_state: *const clap_host_state,
24+
host_ext_undo: *const clap_host_undo,
2325
parameter_event_map: Arc<ParameterEventMap>,
2426
) -> Self {
2527
assert!(!raw.is_null());
@@ -29,6 +31,7 @@ impl ClapHost {
2931
host_ext_gui,
3032
host_ext_params,
3133
host_ext_state,
34+
host_ext_undo,
3235
parameter_event_map,
3336
}
3437
}
@@ -49,7 +52,7 @@ impl Host for ClapHost {
4952

5053
fn start_parameter_change(&self, id: ParameterId) {
5154
self.parameter_event_map.parameter_event_info(id).change_started.store(true, Ordering::Release);
52-
55+
5356
if !self.host_ext_params.is_null() {
5457
unsafe { ((*self.host_ext_params).request_flush.unwrap())(self.raw) };
5558
}
@@ -73,17 +76,29 @@ impl Host for ClapHost {
7376
unsafe { ((*self.host_ext_params).request_flush.unwrap())(self.raw) };
7477
}
7578
}
76-
79+
7780
fn reload_parameters(&self) {
7881
if !self.host_ext_params.is_null() {
7982
unsafe { ((*self.host_ext_params).request_flush.unwrap())(self.raw) };
80-
}
83+
}
8184
}
8285

8386
fn mark_state_dirty(&self) {
8487
if !self.host_ext_state.is_null() {
8588
unsafe { ((*self.host_ext_state).mark_dirty.unwrap())(self.raw) };
8689
}
90+
91+
if !self.host_ext_undo.is_null() {
92+
unsafe {
93+
((*self.host_ext_undo).change_made.unwrap())(
94+
self.raw,
95+
c"".as_ptr(),
96+
null(),
97+
0,
98+
false,
99+
)
100+
};
101+
}
87102
}
88103
}
89104

plinth-plugin/src/formats/clap/plugin_instance.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{collections::BTreeMap, ffi::{CStr, c_char, c_void}, iter::zip, ptr::{null, null_mut}, sync::{Arc, atomic::{AtomicBool, AtomicUsize, Ordering}}};
22

33
use atomic_refcell::AtomicRefCell;
4-
use clap_sys::{events::clap_input_events, ext::{audio_ports::CLAP_EXT_AUDIO_PORTS, gui::{clap_host_gui, CLAP_EXT_GUI}, latency::CLAP_EXT_LATENCY, note_ports::CLAP_EXT_NOTE_PORTS, params::{clap_host_params, CLAP_EXT_PARAMS}, render::CLAP_EXT_RENDER, state::{clap_host_state, CLAP_EXT_STATE}, tail::{clap_host_tail, CLAP_EXT_TAIL}, timer_support::{clap_host_timer_support, CLAP_EXT_TIMER_SUPPORT}}, host::clap_host, plugin::clap_plugin, process::{clap_process, clap_process_status, CLAP_PROCESS_CONTINUE, CLAP_PROCESS_CONTINUE_IF_NOT_QUIET, CLAP_PROCESS_ERROR, CLAP_PROCESS_TAIL}};
4+
use clap_sys::{events::clap_input_events, ext::{audio_ports::CLAP_EXT_AUDIO_PORTS, draft::undo::{CLAP_EXT_UNDO, clap_host_undo}, gui::{CLAP_EXT_GUI, clap_host_gui}, latency::CLAP_EXT_LATENCY, note_ports::CLAP_EXT_NOTE_PORTS, params::{CLAP_EXT_PARAMS, clap_host_params}, render::CLAP_EXT_RENDER, state::{CLAP_EXT_STATE, clap_host_state}, tail::{CLAP_EXT_TAIL, clap_host_tail}, timer_support::{CLAP_EXT_TIMER_SUPPORT, clap_host_timer_support}}, host::clap_host, plugin::clap_plugin, process::{CLAP_PROCESS_CONTINUE, CLAP_PROCESS_CONTINUE_IF_NOT_QUIET, CLAP_PROCESS_ERROR, CLAP_PROCESS_TAIL, clap_process, clap_process_status}};
55
use tracing::error;
66
use plinth_core::signals::{ptr_signal::{PtrSignal, PtrSignalMut}, signal::SignalMut};
77
use raw_window_handle::RawWindowHandle;
@@ -59,6 +59,7 @@ pub struct PluginInstance<P: ClapPlugin> {
5959
pub(super) host_ext_state: *const clap_host_state,
6060
host_ext_tail: *const clap_host_tail,
6161
pub(super) host_ext_timer_support: *const clap_host_timer_support,
62+
pub(super) host_ext_undo: *const clap_host_undo,
6263
}
6364

6465
impl<P: ClapPlugin> PluginInstance<P> {
@@ -148,6 +149,7 @@ impl<P: ClapPlugin> PluginInstance<P> {
148149
host_ext_state: null(),
149150
host_ext_tail: null(),
150151
host_ext_timer_support: null(),
152+
host_ext_undo: null(),
151153
}
152154
}
153155

@@ -193,6 +195,7 @@ impl<P: ClapPlugin> PluginInstance<P> {
193195
instance.host_ext_state = unsafe { ((*instance.host).get_extension.unwrap())(instance.host, CLAP_EXT_STATE.as_ptr()) as _ };
194196
instance.host_ext_tail = unsafe { ((*instance.host).get_extension.unwrap())(instance.host, CLAP_EXT_TAIL.as_ptr()) as _ };
195197
instance.host_ext_timer_support = unsafe { ((*instance.host).get_extension.unwrap())(instance.host, CLAP_EXT_TIMER_SUPPORT.as_ptr()) as _ };
198+
instance.host_ext_undo = unsafe { ((*instance.host).get_extension.unwrap())(instance.host, CLAP_EXT_UNDO.as_ptr()) as _ };
196199

197200
instance.plugin.as_mut().unwrap().init();
198201
});

0 commit comments

Comments
 (0)