From 2d734c471f8e9d57f900d4a32ff45905387d45dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Forment?= Date: Fri, 20 Feb 2026 22:26:35 +0100 Subject: [PATCH] WIP: fix VST3 version --- crates/clap/src/editor.rs | 3 +-- crates/clap/src/lib.rs | 1 + crates/forth/src/vm.rs | 4 ++-- src/app/mod.rs | 18 +++++++++++++----- src/engine/sequencer.rs | 6 +++--- src/state/audio.rs | 22 ++++++++++++++++++++++ 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/crates/clap/src/editor.rs b/crates/clap/src/editor.rs index 75d690d..c4e8cbb 100644 --- a/crates/clap/src/editor.rs +++ b/crates/clap/src/editor.rs @@ -132,12 +132,11 @@ pub fn create_editor( cagire::state::ColorScheme::default().to_palette(); theme::set(cagire_ratatui::theme::build::build(&palette)); - let mut app = App::with_shared( + let mut app = App::new_plugin( Arc::clone(&variables), Arc::clone(&dict), Arc::clone(&rng), ); - app.plugin_mode = true; app.audio.section = cagire::state::EngineSection::Settings; app.audio.setting_kind = cagire::state::SettingKind::Polyphony; diff --git a/crates/clap/src/lib.rs b/crates/clap/src/lib.rs index b6a1532..8e0dc2a 100644 --- a/crates/clap/src/lib.rs +++ b/crates/clap/src/lib.rs @@ -119,6 +119,7 @@ impl Plugin for CagirePlugin { }, }]; + const MIDI_INPUT: MidiConfig = MidiConfig::MidiCCs; const MIDI_OUTPUT: MidiConfig = MidiConfig::MidiCCs; fn params(&self) -> Arc { diff --git a/crates/forth/src/vm.rs b/crates/forth/src/vm.rs index e10d607..f3c3db9 100644 --- a/crates/forth/src/vm.rs +++ b/crates/forth/src/vm.rs @@ -69,7 +69,7 @@ impl Forth { if writes.is_empty() { return; } - let mut new_vars = (**self.vars.load()).clone(); + let mut new_vars = (*self.vars.load_full()).clone(); for (k, v) in writes { new_vars.insert(k, v); } @@ -99,7 +99,7 @@ impl Forth { let mut stack = self.stack.lock(); let mut outputs: Vec = Vec::with_capacity(8); let mut cmd = CmdRegister::new(); - let vars_snapshot = self.vars.load(); + let vars_snapshot = self.vars.load_full(); let mut var_writes: HashMap = HashMap::new(); self.execute_ops( diff --git a/src/app/mod.rs b/src/app/mod.rs index 10495ff..ddb6eec 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -83,15 +83,19 @@ impl App { let variables = Arc::new(ArcSwap::from_pointee(HashMap::new())); let dict = Arc::new(Mutex::new(HashMap::new())); let rng = Arc::new(Mutex::new(StdRng::seed_from_u64(0))); - Self::build(variables, dict, rng) + Self::build(variables, dict, rng, false) } #[allow(dead_code)] pub fn with_shared(variables: Variables, dict: Dictionary, rng: Rng) -> Self { - Self::build(variables, dict, rng) + Self::build(variables, dict, rng, false) } - fn build(variables: Variables, dict: Dictionary, rng: Rng) -> Self { + pub fn new_plugin(variables: Variables, dict: Dictionary, rng: Rng) -> Self { + Self::build(variables, dict, rng, true) + } + + fn build(variables: Variables, dict: Dictionary, rng: Rng, plugin_mode: bool) -> Self { let script_engine = ScriptEngine::new(Arc::clone(&variables), Arc::clone(&dict), Arc::clone(&rng)); let live_keys = Arc::new(LiveKeyState::new()); @@ -119,11 +123,15 @@ impl App { undo: UndoHistory::default(), - audio: AudioSettings::default(), + audio: if plugin_mode { + AudioSettings::new_plugin() + } else { + AudioSettings::default() + }, options: OptionsState::default(), panel: PanelState::default(), midi: MidiState::new(), - plugin_mode: false, + plugin_mode, } } diff --git a/src/engine/sequencer.rs b/src/engine/sequencer.rs index 700c937..5ff62f3 100644 --- a/src/engine/sequencer.rs +++ b/src/engine/sequencer.rs @@ -867,7 +867,7 @@ impl SequencerState { self.speed_overrides.clear(); { - let vars = self.variables.load(); + let vars = self.variables.load_full(); for id in self.audio_state.active_patterns.keys() { let key = format_speed_key(&mut self.key_buf.speed, id.bank, id.pattern); if let Some(v) = vars.get(key).and_then(|v: &Value| v.as_float().ok()) { @@ -998,7 +998,7 @@ impl SequencerState { }; } - let vars = self.variables.load(); + let vars = self.variables.load_full(); let new_tempo = vars .get("__tempo__") .and_then(|v: &Value| v.as_float().ok()); @@ -1026,7 +1026,7 @@ impl SequencerState { } if needs_removal { - let mut new_vars = (**vars).clone(); + let mut new_vars = (*vars).clone(); new_vars.remove("__tempo__"); for id in completed { new_vars.remove(format_chain_key(&mut buf, id.bank, id.pattern)); diff --git a/src/state/audio.rs b/src/state/audio.rs index da0904c..78cfa08 100644 --- a/src/state/audio.rs +++ b/src/state/audio.rs @@ -253,6 +253,28 @@ impl Default for AudioSettings { } impl AudioSettings { + pub fn new_plugin() -> Self { + Self { + config: AudioConfig::default(), + section: EngineSection::default(), + device_kind: DeviceKind::default(), + setting_kind: SettingKind::default(), + output_devices: Vec::new(), + input_devices: Vec::new(), + output_list: ListSelectState { + cursor: 0, + scroll_offset: 0, + }, + input_list: ListSelectState { + cursor: 0, + scroll_offset: 0, + }, + restart_pending: false, + error: None, + sample_registry: None, + } + } + pub fn refresh_devices(&mut self) { self.output_devices = doux::audio::list_output_devices(); self.input_devices = doux::audio::list_input_devices();