mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
fix reexport mess + document modules
This commit is contained in:
parent
7d6bdcca99
commit
317547c6b2
14 changed files with 383 additions and 350 deletions
|
|
@ -83,6 +83,7 @@ impl Sampler {
|
|||
Control::Continue
|
||||
}
|
||||
|
||||
/// Create [Voice]s from [Sample]s in response to MIDI input.
|
||||
fn process_midi_in (&mut self, scope: &ProcessScope) {
|
||||
for RawMidi { time, bytes } in self.ports.midi_ins.get("midi").unwrap().iter(scope) {
|
||||
if let LiveEvent::Midi { message, .. } = LiveEvent::parse(bytes).unwrap() {
|
||||
|
|
@ -95,22 +96,26 @@ impl Sampler {
|
|||
}
|
||||
}
|
||||
|
||||
/// Zero the output buffer.
|
||||
fn clear_output_buffer (&mut self) {
|
||||
for buffer in self.buffer.iter_mut() {
|
||||
buffer.fill(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Mix all currently playing samples into the output.
|
||||
fn process_audio_out (&mut self, scope: &ProcessScope) {
|
||||
let channel_count = self.buffer.len();
|
||||
self.voices.retain_mut(|voice|{
|
||||
for index in 0..scope.n_frames() as usize {
|
||||
if let Some(frame) = voice.next() {
|
||||
for (channel, sample) in frame.iter().enumerate() {
|
||||
// Averaging mixer:
|
||||
//self.buffer[channel % channel_count][index] = (
|
||||
//(self.buffer[channel % channel_count][index] + sample * self.output_gain) / 2.0
|
||||
//);
|
||||
self.buffer[channel % channel_count][index] += sample * self.output_gain;
|
||||
self.buffer[channel % channel_count][index] +=
|
||||
sample * self.output_gain;
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
|
|
@ -142,6 +147,7 @@ impl Sampler {
|
|||
}};
|
||||
}
|
||||
|
||||
/// Read WAV from file
|
||||
pub fn read_sample_data (src: &str) -> Usually<(usize, Vec<Vec<f32>>)> {
|
||||
let mut channels: Vec<wavers::Samples<f32>> = vec![];
|
||||
for channel in wavers::Wav::from_path(src)?.channels() {
|
||||
|
|
@ -157,6 +163,7 @@ pub fn read_sample_data (src: &str) -> Usually<(usize, Vec<Vec<f32>>)> {
|
|||
Ok((end, data))
|
||||
}
|
||||
|
||||
/// A sound sample.
|
||||
pub struct Sample {
|
||||
pub name: String,
|
||||
pub start: usize,
|
||||
|
|
@ -178,6 +185,7 @@ impl Sample {
|
|||
}
|
||||
}
|
||||
|
||||
/// A currently playing instance of a sample.
|
||||
pub struct Voice {
|
||||
pub sample: Arc<Sample>,
|
||||
pub after: usize,
|
||||
|
|
@ -203,48 +211,3 @@ impl Iterator for Voice {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
//fn render_table (
|
||||
//self: &mut Sampler,
|
||||
//stdout: &mut Stdout,
|
||||
//offset: (u16, u16),
|
||||
//) -> Result<(), Box<dyn Error>> {
|
||||
//let move_to = |col, row| crossterm::cursor::MoveTo(offset.0 + col, offset.1 + row);
|
||||
//stdout.queue(move_to(0, 3))?.queue(
|
||||
//Print(" Name Rate Trigger Route")
|
||||
//)?;
|
||||
//for (i, sample) in self.samples.lock().unwrap().iter().enumerate() {
|
||||
//let row = 4 + i as u16;
|
||||
//for (j, (column, field)) in [
|
||||
//(0, format!(" {:7} ", sample.name)),
|
||||
//(9, format!(" {:.1}Hz ", sample.rate)),
|
||||
//(18, format!(" MIDI C{} {} ", sample.trigger.0, sample.trigger.1)),
|
||||
//(33, format!(" {:.1}dB -> Output ", sample.gain)),
|
||||
//(50, format!(" {} ", sample.playing.unwrap_or(0))),
|
||||
//].into_iter().enumerate() {
|
||||
//stdout.queue(move_to(column, row))?;
|
||||
//if self.selected_sample == i && self.selected_column == j {
|
||||
//stdout.queue(PrintStyledContent(field.to_string().bold().reverse()))?;
|
||||
//} else {
|
||||
//stdout.queue(PrintStyledContent(field.to_string().bold()))?;
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//Ok(())
|
||||
//}
|
||||
|
||||
//fn render_meters (
|
||||
//self: &mut Sampler,
|
||||
//stdout: &mut Stdout,
|
||||
//offset: (u16, u16),
|
||||
//) -> Result<(), Box<dyn Error>> {
|
||||
//let move_to = |col, row| crossterm::cursor::MoveTo(offset.0 + col, offset.1 + row);
|
||||
//for (i, sample) in self.samples.lock().iter().enumerate() {
|
||||
//let row = 4 + i as u16;
|
||||
//stdout.queue(move_to(32, row))?.queue(
|
||||
//PrintStyledContent("▁".green())
|
||||
//)?;
|
||||
//}
|
||||
//Ok(())
|
||||
//}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue