Merge branch 'rust-ui' of https://git.skyler.io/skyler/Lightningbeam into rust-ui

This commit is contained in:
Skyler Lehmkuhl
2026-02-16 10:06:00 -05:00
22 changed files with 2231 additions and 358 deletions
+69
View File
@@ -1426,6 +1426,34 @@ impl Engine {
}
}
Command::GraphSetGroups(track_id, groups) => {
let graph = match self.project.get_track_mut(track_id) {
Some(TrackNode::Midi(track)) => Some(&mut track.instrument_graph),
Some(TrackNode::Audio(track)) => Some(&mut track.effects_graph),
_ => None,
};
if let Some(graph) = graph {
graph.set_frontend_groups(groups);
}
}
Command::GraphSetGroupsInTemplate(track_id, voice_allocator_id, groups) => {
use crate::audio::node_graph::nodes::VoiceAllocatorNode;
let graph = match self.project.get_track_mut(track_id) {
Some(TrackNode::Midi(track)) => Some(&mut track.instrument_graph),
Some(TrackNode::Audio(track)) => Some(&mut track.effects_graph),
_ => None,
};
if let Some(graph) = graph {
let node_idx = NodeIndex::new(voice_allocator_id as usize);
if let Some(graph_node) = graph.get_node_mut(node_idx) {
if let Some(va_node) = graph_node.as_any_mut().downcast_mut::<VoiceAllocatorNode>() {
va_node.template_graph_mut().set_frontend_groups(groups);
}
}
}
}
Command::GraphSavePreset(track_id, preset_path, preset_name, description, tags) => {
let graph = match self.project.get_track(track_id) {
Some(TrackNode::Midi(track)) => Some(&track.instrument_graph),
@@ -1942,6 +1970,18 @@ impl Engine {
))),
}
}
Query::GetVoiceOscilloscopeData(track_id, va_node_id, inner_node_id, sample_count) => {
match self.project.get_voice_oscilloscope_data(track_id, va_node_id, inner_node_id, sample_count) {
Some((audio, cv)) => {
use crate::command::OscilloscopeData;
QueryResponse::OscilloscopeData(Ok(OscilloscopeData { audio, cv }))
}
None => QueryResponse::OscilloscopeData(Err(format!(
"Failed to get voice oscilloscope data from track {} VA {} node {}",
track_id, va_node_id, inner_node_id
))),
}
}
Query::GetMidiClip(_track_id, clip_id) => {
// Get MIDI clip data from the pool
if let Some(clip) = self.project.midi_clip_pool.get_clip(clip_id) {
@@ -3029,6 +3069,16 @@ impl EngineController {
let _ = self.command_tx.push(Command::GraphSetOutputNode(track_id, node_id));
}
/// Set frontend-only group definitions on a track's graph
pub fn graph_set_groups(&mut self, track_id: TrackId, groups: Vec<crate::audio::node_graph::preset::SerializedGroup>) {
let _ = self.command_tx.push(Command::GraphSetGroups(track_id, groups));
}
/// Set frontend-only group definitions on a VA template graph
pub fn graph_set_groups_in_template(&mut self, track_id: TrackId, voice_allocator_id: u32, groups: Vec<crate::audio::node_graph::preset::SerializedGroup>) {
let _ = self.command_tx.push(Command::GraphSetGroupsInTemplate(track_id, voice_allocator_id, groups));
}
/// Save the current graph as a preset
pub fn graph_save_preset(&mut self, track_id: TrackId, preset_path: String, preset_name: String, description: String, tags: Vec<String>) {
let _ = self.command_tx.push(Command::GraphSavePreset(track_id, preset_path, preset_name, description, tags));
@@ -3177,6 +3227,25 @@ impl EngineController {
Err("Query timeout".to_string())
}
/// Query oscilloscope data from a node inside a VoiceAllocator's best voice
pub fn query_voice_oscilloscope_data(&mut self, track_id: TrackId, va_node_id: u32, inner_node_id: u32, sample_count: usize) -> Result<crate::command::OscilloscopeData, String> {
if let Err(_) = self.query_tx.push(Query::GetVoiceOscilloscopeData(track_id, va_node_id, inner_node_id, sample_count)) {
return Err("Failed to send query - queue full".to_string());
}
let start = std::time::Instant::now();
let timeout = std::time::Duration::from_millis(100);
while start.elapsed() < timeout {
if let Ok(QueryResponse::OscilloscopeData(result)) = self.query_response_rx.pop() {
return result;
}
std::thread::sleep(std::time::Duration::from_micros(50));
}
Err("Query timeout".to_string())
}
/// Query automation keyframes from an AutomationInput node
pub fn query_automation_keyframes(&mut self, track_id: TrackId, node_id: u32) -> Result<Vec<crate::command::types::AutomationKeyframeData>, String> {
// Send query
+22
View File
@@ -98,6 +98,9 @@ pub struct AudioGraph {
/// Cached topological sort order (invalidated on graph mutation)
topo_cache: Option<Vec<NodeIndex>>,
/// Frontend-only group definitions (stored opaquely for persistence)
frontend_groups: Vec<crate::audio::node_graph::preset::SerializedGroup>,
}
impl AudioGraph {
@@ -117,6 +120,7 @@ impl AudioGraph {
node_positions: std::collections::HashMap::new(),
playback_time: 0.0,
topo_cache: None,
frontend_groups: Vec::new(),
}
}
@@ -645,6 +649,10 @@ impl AudioGraph {
self.graph.node_weight(idx).map(|n| &*n.node)
}
pub fn get_node_mut(&mut self, idx: NodeIndex) -> Option<&mut (dyn AudioNode + 'static)> {
self.graph.node_weight_mut(idx).map(|n| &mut *n.node)
}
/// Get oscilloscope data from a specific node
pub fn get_oscilloscope_data(&self, idx: NodeIndex, sample_count: usize) -> Option<Vec<f32>> {
self.get_node(idx).and_then(|node| node.get_oscilloscope_data(sample_count))
@@ -729,9 +737,17 @@ impl AudioGraph {
}
}
// Clone frontend groups
new_graph.frontend_groups = self.frontend_groups.clone();
new_graph
}
/// Set frontend-only group definitions (stored opaquely for persistence)
pub fn set_frontend_groups(&mut self, groups: Vec<crate::audio::node_graph::preset::SerializedGroup>) {
self.frontend_groups = groups;
}
/// Serialize the graph to a preset
pub fn to_preset(&self, name: impl Into<String>) -> crate::audio::node_graph::preset::GraphPreset {
use crate::audio::node_graph::preset::{GraphPreset, SerializedConnection, SerializedNode};
@@ -897,6 +913,9 @@ impl AudioGraph {
// Output node
preset.output_node = self.output_node.map(|idx| idx.index() as u32);
// Frontend groups (stored opaquely)
preset.groups = self.frontend_groups.clone();
preset
}
@@ -1118,6 +1137,9 @@ impl AudioGraph {
}
}
// Restore frontend groups (stored opaquely)
graph.frontend_groups = preset.groups.clone();
Ok(graph)
}
}
+1 -1
View File
@@ -6,5 +6,5 @@ pub mod preset;
pub use graph::{Connection, GraphNode, AudioGraph};
pub use node_trait::{AudioNode, cv_input_or_default};
pub use preset::{GraphPreset, PresetMetadata, SerializedConnection, SerializedNode};
pub use preset::{GraphPreset, PresetMetadata, SerializedConnection, SerializedNode, SerializedGroup, SerializedBoundaryConnection};
pub use types::{ConnectionError, NodeCategory, NodePort, Parameter, ParameterUnit, SignalType};
@@ -29,6 +29,8 @@ pub struct FilterNode {
resonance: f32,
filter_type: FilterType,
sample_rate: u32,
/// Last cutoff frequency applied to filter coefficients (for change detection with CV modulation)
last_applied_cutoff: f32,
inputs: Vec<NodePort>,
outputs: Vec<NodePort>,
parameters: Vec<Parameter>,
@@ -62,6 +64,7 @@ impl FilterNode {
resonance: 0.707,
filter_type: FilterType::Lowpass,
sample_rate: 44100,
last_applied_cutoff: 1000.0,
inputs,
outputs,
parameters,
@@ -150,11 +153,20 @@ impl AudioNode for FilterNode {
output[..len].copy_from_slice(&input[..len]);
// Check for CV modulation (modulates cutoff)
// CV input (0..1) scales the cutoff: 0 = 20 Hz, 1 = base cutoff * 2
// Sample CV at the start of the buffer - per-sample would be too expensive
let cutoff_cv = cv_input_or_default(inputs, 1, 0, self.cutoff);
if (cutoff_cv - self.cutoff).abs() > 0.01 {
// CV changed significantly, update filter
let new_cutoff = cutoff_cv.clamp(20.0, 20000.0);
let cutoff_cv_raw = cv_input_or_default(inputs, 1, 0, f32::NAN);
let effective_cutoff = if cutoff_cv_raw.is_nan() {
self.cutoff
} else {
// Map CV (0..1) to frequency range around the base cutoff
// 0.5 = base cutoff, 0 = cutoff / 4, 1 = cutoff * 4 (two octaves each way)
let octave_shift = (cutoff_cv_raw.clamp(0.0, 1.0) - 0.5) * 4.0;
self.cutoff * 2.0_f32.powf(octave_shift)
};
if (effective_cutoff - self.last_applied_cutoff).abs() > 0.01 {
let new_cutoff = effective_cutoff.clamp(20.0, 20000.0);
self.last_applied_cutoff = new_cutoff;
match self.filter_type {
FilterType::Lowpass => {
self.filter.set_lowpass(new_cutoff, self.resonance, self.sample_rate as f32);
@@ -202,6 +214,7 @@ impl AudioNode for FilterNode {
resonance: self.resonance,
filter_type: self.filter_type,
sample_rate: self.sample_rate,
last_applied_cutoff: self.cutoff,
inputs: self.inputs.clone(),
outputs: self.outputs.clone(),
parameters: self.parameters.clone(),
@@ -176,6 +176,35 @@ impl VoiceAllocatorNode {
.unwrap_or(0)
}
/// Get oscilloscope data from the most relevant voice's subgraph.
/// Priority: first active voice → first releasing voice → first voice.
pub fn get_voice_oscilloscope_data(&self, node_id: u32, sample_count: usize) -> Option<(Vec<f32>, Vec<f32>)> {
let voice_idx = self.best_voice_index();
let graph = &self.voice_instances[voice_idx];
let node_idx = petgraph::stable_graph::NodeIndex::new(node_id as usize);
let audio = graph.get_oscilloscope_data(node_idx, sample_count)?;
let cv = graph.get_oscilloscope_cv_data(node_idx, sample_count).unwrap_or_default();
Some((audio, cv))
}
/// Find the best voice index to observe: first active → first releasing → 0
fn best_voice_index(&self) -> usize {
// First active (non-releasing) voice
for (i, v) in self.voices[..self.voice_count].iter().enumerate() {
if v.active && !v.releasing {
return i;
}
}
// First releasing voice
for (i, v) in self.voices[..self.voice_count].iter().enumerate() {
if v.active && v.releasing {
return i;
}
}
// Fallback to first voice
0
}
/// Find all voices playing a specific note (held, not yet releasing)
fn find_voices_for_note_off(&self, note: u8) -> Vec<usize> {
self.voices[..self.voice_count]
@@ -67,6 +67,10 @@ pub struct GraphPreset {
/// Which node index is the audio output (None if not set)
pub output_node: Option<u32>,
/// Frontend-only group definitions (backend stores opaquely, does not interpret)
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub groups: Vec<SerializedGroup>,
}
/// Metadata about the preset
@@ -121,6 +125,32 @@ pub struct SerializedNode {
pub sample_data: Option<SampleData>,
}
/// Serialized group definition (frontend-only visual grouping, stored opaquely by backend)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SerializedGroup {
pub id: u32,
pub name: String,
pub member_nodes: Vec<u32>,
pub position: (f32, f32),
pub boundary_inputs: Vec<SerializedBoundaryConnection>,
pub boundary_outputs: Vec<SerializedBoundaryConnection>,
/// Parent group ID for nested groups (None = top-level group)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub parent_group_id: Option<u32>,
}
/// Serialized boundary connection for group definitions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SerializedBoundaryConnection {
pub external_node: u32,
pub external_port: usize,
pub internal_node: u32,
pub internal_port: usize,
pub port_name: String,
/// Signal type as string ("Audio", "Midi", "CV")
pub data_type: String,
}
/// Serialized connection between nodes
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SerializedConnection {
@@ -152,6 +182,7 @@ impl GraphPreset {
connections: Vec::new(),
midi_targets: Vec::new(),
output_node: None,
groups: Vec::new(),
}
}
+12
View File
@@ -228,6 +228,18 @@ impl Project {
None
}
/// Get oscilloscope data from a node inside a VoiceAllocator's best voice
pub fn get_voice_oscilloscope_data(&self, track_id: TrackId, va_node_id: u32, inner_node_id: u32, sample_count: usize) -> Option<(Vec<f32>, Vec<f32>)> {
if let Some(TrackNode::Midi(track)) = self.tracks.get(&track_id) {
let graph = &track.instrument_graph;
let va_idx = petgraph::stable_graph::NodeIndex::new(va_node_id as usize);
let node = graph.get_node(va_idx)?;
let va = node.as_any().downcast_ref::<crate::audio::node_graph::nodes::VoiceAllocatorNode>()?;
return va.get_voice_oscilloscope_data(inner_node_id, sample_count);
}
None
}
/// Get all root-level track IDs
pub fn root_tracks(&self) -> &[TrackId] {
&self.root_tracks
+8
View File
@@ -163,6 +163,11 @@ pub enum Command {
/// Set which node is the audio output (track_id, node_index)
GraphSetOutputNode(TrackId, u32),
/// Set frontend-only group definitions on a track's graph (track_id, serialized groups)
GraphSetGroups(TrackId, Vec<crate::audio::node_graph::preset::SerializedGroup>),
/// Set frontend-only group definitions on a VA template graph (track_id, voice_allocator_id, serialized groups)
GraphSetGroupsInTemplate(TrackId, u32, Vec<crate::audio::node_graph::preset::SerializedGroup>),
/// Save current graph as a preset (track_id, preset_path, preset_name, description, tags)
GraphSavePreset(TrackId, String, String, String, Vec<String>),
/// Load a preset into a track's graph (track_id, preset_path)
@@ -314,6 +319,9 @@ pub enum Query {
GetTemplateState(TrackId, u32),
/// Get oscilloscope data from a node (track_id, node_id, sample_count)
GetOscilloscopeData(TrackId, u32, usize),
/// Get oscilloscope data from a node inside a VoiceAllocator's best voice
/// (track_id, va_node_id, inner_node_id, sample_count)
GetVoiceOscilloscopeData(TrackId, u32, u32, usize),
/// Get MIDI clip data (track_id, clip_id)
GetMidiClip(TrackId, MidiClipId),
/// Get keyframes from an AutomationInput node (track_id, node_id)