Some kind of refactoring

This commit is contained in:
2026-02-04 19:35:30 +01:00
parent 6cf9d2eec1
commit 82b0668bcf
18 changed files with 688 additions and 772 deletions

View File

@@ -1,5 +1,8 @@
use arc_swap::ArcSwap;
use crossbeam_channel::{bounded, unbounded, Receiver, Sender};
use parking_lot::Mutex;
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::collections::HashMap;
#[cfg(feature = "desktop")]
use std::sync::atomic::AtomicU32;
@@ -120,6 +123,7 @@ pub enum SeqCommand {
soloed: std::collections::HashSet<(usize, usize)>,
},
StopAll,
ResetScriptState,
Shutdown,
}
@@ -274,13 +278,9 @@ pub struct SequencerConfig {
pub mouse_down: Arc<AtomicU32>,
}
#[allow(clippy::too_many_arguments)]
pub fn spawn_sequencer(
link: Arc<LinkState>,
playing: Arc<std::sync::atomic::AtomicBool>,
variables: Variables,
dict: Dictionary,
rng: Rng,
quantum: f64,
live_keys: Arc<LiveKeyState>,
nudge_us: Arc<AtomicI64>,
@@ -329,9 +329,6 @@ pub fn spawn_sequencer(
sequencer_audio_tx,
link,
playing,
variables,
dict,
rng,
quantum,
shared_state_clone,
live_keys,
@@ -667,6 +664,15 @@ impl SequencerState {
self.runs_counter.counts.clear();
self.audio_state.flush_midi_notes = true;
}
SeqCommand::ResetScriptState => {
let variables: Variables = Arc::new(ArcSwap::from_pointee(HashMap::new()));
let dict: Dictionary = Arc::new(Mutex::new(HashMap::new()));
let rng: Rng = Arc::new(Mutex::new(StdRng::seed_from_u64(0)));
self.script_engine =
ScriptEngine::new(Arc::clone(&variables), dict, rng);
self.variables = variables;
self.speed_overrides.clear();
}
SeqCommand::Shutdown => {}
}
}
@@ -1063,9 +1069,6 @@ fn sequencer_loop(
audio_tx: Arc<ArcSwap<Sender<AudioCommand>>>,
link: Arc<LinkState>,
playing: Arc<std::sync::atomic::AtomicBool>,
variables: Variables,
dict: Dictionary,
rng: Rng,
quantum: f64,
shared_state: Arc<ArcSwap<SharedSequencerState>>,
live_keys: Arc<LiveKeyState>,
@@ -1093,6 +1096,9 @@ fn sequencer_loop(
eprintln!("[cagire] Then log out and back in.");
}
let variables: Variables = Arc::new(ArcSwap::from_pointee(HashMap::new()));
let dict: Dictionary = Arc::new(Mutex::new(HashMap::new()));
let rng: Rng = Arc::new(Mutex::new(StdRng::seed_from_u64(0)));
let mut seq_state = SequencerState::new(variables, dict, rng, cc_access);
loop {