Remove old SimpleSynth and effect system
This commit is contained in:
@@ -330,61 +330,6 @@ impl MultiSamplerNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate playback speed from pitch difference
|
||||
fn calculate_speed(&self, layer: &SampleLayer, note: u8) -> f32 {
|
||||
let semitone_diff = note as i16 - layer.root_key as i16;
|
||||
2.0_f32.powf(semitone_diff as f32 / 12.0)
|
||||
}
|
||||
|
||||
/// Read sample at playhead with linear interpolation
|
||||
fn read_sample(&self, playhead: f32, sample: &[f32]) -> f32 {
|
||||
if sample.is_empty() || playhead < 0.0 {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
let index = playhead.floor() as usize;
|
||||
if index >= sample.len() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
let frac = playhead - playhead.floor();
|
||||
let sample1 = sample[index];
|
||||
let sample2 = if index + 1 < sample.len() {
|
||||
sample[index + 1]
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
sample1 + (sample2 - sample1) * frac
|
||||
}
|
||||
|
||||
/// Process envelope for a voice
|
||||
fn process_envelope(&self, voice: &mut Voice, sample_rate: f32) -> f32 {
|
||||
match voice.envelope_phase {
|
||||
EnvelopePhase::Attack => {
|
||||
let attack_samples = self.attack_time * sample_rate;
|
||||
voice.envelope_value += 1.0 / attack_samples;
|
||||
if voice.envelope_value >= 1.0 {
|
||||
voice.envelope_value = 1.0;
|
||||
voice.envelope_phase = EnvelopePhase::Sustain;
|
||||
}
|
||||
}
|
||||
EnvelopePhase::Sustain => {
|
||||
voice.envelope_value = 1.0;
|
||||
}
|
||||
EnvelopePhase::Release => {
|
||||
let release_samples = self.release_time * sample_rate;
|
||||
voice.envelope_value -= 1.0 / release_samples;
|
||||
if voice.envelope_value <= 0.0 {
|
||||
voice.envelope_value = 0.0;
|
||||
voice.is_active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
voice.envelope_value.clamp(0.0, 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioNode for MultiSamplerNode {
|
||||
|
||||
@@ -28,7 +28,7 @@ impl TriggerMode {
|
||||
}
|
||||
|
||||
/// Circular buffer for storing audio samples
|
||||
struct CircularBuffer {
|
||||
pub struct CircularBuffer {
|
||||
buffer: Vec<f32>,
|
||||
write_pos: usize,
|
||||
capacity: usize,
|
||||
@@ -75,7 +75,7 @@ impl CircularBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Oscilloscope node for visualizing audio signals
|
||||
/// Oscilloscope node for visualizing audio and CV signals
|
||||
pub struct OscilloscopeNode {
|
||||
name: String,
|
||||
time_scale: f32, // Milliseconds to display (10-1000ms)
|
||||
@@ -86,8 +86,9 @@ pub struct OscilloscopeNode {
|
||||
sample_counter: usize, // Counter for V/oct triggering
|
||||
trigger_period: usize, // Period in samples for V/oct triggering
|
||||
|
||||
// Shared buffer for reading from Tauri commands
|
||||
buffer: Arc<Mutex<CircularBuffer>>,
|
||||
// Shared buffers for reading from Tauri commands
|
||||
buffer: Arc<Mutex<CircularBuffer>>, // Audio buffer
|
||||
cv_buffer: Arc<Mutex<CircularBuffer>>, // CV buffer
|
||||
|
||||
inputs: Vec<NodePort>,
|
||||
outputs: Vec<NodePort>,
|
||||
@@ -101,6 +102,7 @@ impl OscilloscopeNode {
|
||||
let inputs = vec![
|
||||
NodePort::new("Audio In", SignalType::Audio, 0),
|
||||
NodePort::new("V/oct", SignalType::CV, 1),
|
||||
NodePort::new("CV In", SignalType::CV, 2),
|
||||
];
|
||||
|
||||
let outputs = vec![
|
||||
@@ -123,6 +125,7 @@ impl OscilloscopeNode {
|
||||
sample_counter: 0,
|
||||
trigger_period: 480, // Default to ~100Hz at 48kHz
|
||||
buffer: Arc::new(Mutex::new(CircularBuffer::new(BUFFER_SIZE))),
|
||||
cv_buffer: Arc::new(Mutex::new(CircularBuffer::new(BUFFER_SIZE))),
|
||||
inputs,
|
||||
outputs,
|
||||
parameters,
|
||||
@@ -143,11 +146,23 @@ impl OscilloscopeNode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read CV samples from the CV buffer (for Tauri commands)
|
||||
pub fn read_cv_samples(&self, count: usize) -> Vec<f32> {
|
||||
if let Ok(buffer) = self.cv_buffer.lock() {
|
||||
buffer.read(count)
|
||||
} else {
|
||||
vec![0.0; count]
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear the buffer
|
||||
pub fn clear_buffer(&self) {
|
||||
if let Ok(mut buffer) = self.buffer.lock() {
|
||||
buffer.clear();
|
||||
}
|
||||
if let Ok(mut cv_buffer) = self.cv_buffer.lock() {
|
||||
cv_buffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert V/oct to frequency in Hz (matches oscillator convention)
|
||||
@@ -155,23 +170,6 @@ impl OscilloscopeNode {
|
||||
fn voct_to_frequency(voct: f32) -> f32 {
|
||||
440.0 * 2.0_f32.powf(voct)
|
||||
}
|
||||
|
||||
/// Check if trigger condition is met
|
||||
fn is_triggered(&self, current_sample: f32) -> bool {
|
||||
match self.trigger_mode {
|
||||
TriggerMode::FreeRunning => true,
|
||||
TriggerMode::RisingEdge => {
|
||||
self.last_sample <= self.trigger_level && current_sample > self.trigger_level
|
||||
}
|
||||
TriggerMode::FallingEdge => {
|
||||
self.last_sample >= self.trigger_level && current_sample < self.trigger_level
|
||||
}
|
||||
TriggerMode::VoltPerOctave => {
|
||||
// Trigger at the start of each period
|
||||
self.sample_counter == 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioNode for OscilloscopeNode {
|
||||
@@ -242,11 +240,19 @@ impl AudioNode for OscilloscopeNode {
|
||||
// Pass through audio (copy input to output)
|
||||
output[..len].copy_from_slice(&input[..len]);
|
||||
|
||||
// Capture samples to buffer
|
||||
// Capture audio samples to buffer
|
||||
if let Ok(mut buffer) = self.buffer.lock() {
|
||||
buffer.write(&input[..len]);
|
||||
}
|
||||
|
||||
// Capture CV samples if CV input is connected (input 2)
|
||||
if inputs.len() > 2 && !inputs[2].is_empty() {
|
||||
let cv_input = inputs[2];
|
||||
if let Ok(mut cv_buffer) = self.cv_buffer.lock() {
|
||||
cv_buffer.write(&cv_input[..len.min(cv_input.len())]);
|
||||
}
|
||||
}
|
||||
|
||||
// Update last sample for trigger detection (use left channel, frame 0)
|
||||
if !input.is_empty() {
|
||||
self.last_sample = input[0];
|
||||
@@ -279,6 +285,7 @@ impl AudioNode for OscilloscopeNode {
|
||||
sample_counter: 0,
|
||||
trigger_period: 480,
|
||||
buffer: Arc::new(Mutex::new(CircularBuffer::new(BUFFER_SIZE))),
|
||||
cv_buffer: Arc::new(Mutex::new(CircularBuffer::new(BUFFER_SIZE))),
|
||||
inputs: self.inputs.clone(),
|
||||
outputs: self.outputs.clone(),
|
||||
parameters: self.parameters.clone(),
|
||||
@@ -288,4 +295,8 @@ impl AudioNode for OscilloscopeNode {
|
||||
fn get_oscilloscope_data(&self, sample_count: usize) -> Option<Vec<f32>> {
|
||||
Some(self.read_samples(sample_count))
|
||||
}
|
||||
|
||||
fn get_oscilloscope_cv_data(&self, sample_count: usize) -> Option<Vec<f32>> {
|
||||
Some(self.read_cv_samples(sample_count))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ impl AudioNode for PanNode {
|
||||
if inputs.len() > 1 && frame < inputs[1].len() {
|
||||
let cv = inputs[1][frame]; // CV is mono
|
||||
// CV is 0-1, map to -1 to +1 range
|
||||
pan += (cv * 2.0 - 1.0);
|
||||
pan += cv * 2.0 - 1.0;
|
||||
pan = pan.clamp(-1.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::audio::node_graph::{AudioNode, NodeCategory, NodePort, Parameter, ParameterUnit, SignalType};
|
||||
use crate::audio::node_graph::{AudioNode, NodeCategory, NodePort, Parameter, SignalType};
|
||||
use crate::audio::midi::MidiEvent;
|
||||
|
||||
/// Splitter node - copies input to multiple outputs for parallel routing
|
||||
|
||||
Reference in New Issue
Block a user