mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
show sample during recording
This commit is contained in:
parent
f09a6072f8
commit
240c498a50
3 changed files with 17 additions and 20 deletions
|
|
@ -88,7 +88,13 @@ render!(<Tui>|self:GrooveboxTui|{
|
|||
}),
|
||||
lay!([
|
||||
Outer(Style::default().fg(TuiTheme::g(128))),
|
||||
Fill::w(Fixed::h(4, SampleViewer(None))),
|
||||
Fill::w(Fixed::h(4, if let Some((_, sample)) = &self.sampler.recording {
|
||||
SampleViewer(Some(sample.clone()))
|
||||
} else if let Some(sample) = &self.sampler.mapped[note_pt] {
|
||||
SampleViewer(Some(sample.clone()))
|
||||
} else {
|
||||
SampleViewer(None)
|
||||
})),
|
||||
]),
|
||||
]),
|
||||
Tui::split_w(false, pool_w,
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ pub struct Sampler {
|
|||
pub jack: Arc<RwLock<JackClient>>,
|
||||
pub name: String,
|
||||
pub mapped: [Option<Arc<RwLock<Sample>>>;128],
|
||||
pub recording: Option<(usize, Sample)>,
|
||||
pub recording: Option<(usize, Arc<RwLock<Sample>>)>,
|
||||
pub unmapped: Vec<Arc<RwLock<Sample>>>,
|
||||
pub voices: Arc<RwLock<Vec<Voice>>>,
|
||||
pub midi_in: Port<MidiIn>,
|
||||
|
|
@ -75,31 +75,21 @@ impl Sampler {
|
|||
self.recording = None;
|
||||
}
|
||||
pub fn begin_recording (&mut self, index: usize) {
|
||||
self.recording = Some(
|
||||
(index, Sample::new("(new)", 0, 0, vec![vec![];self.audio_ins.len()]))
|
||||
);
|
||||
self.recording = Some((
|
||||
index,
|
||||
Arc::new(RwLock::new(Sample::new("(new)", 0, 0, vec![vec![];self.audio_ins.len()])))
|
||||
));
|
||||
}
|
||||
pub fn finish_recording (&mut self) -> Option<Arc<RwLock<Sample>>> {
|
||||
let recording = self.recording.take();
|
||||
if let Some((index, sample)) = recording {
|
||||
let old = self.mapped[index].clone();
|
||||
self.mapped[index] = Some(Arc::new(RwLock::new(sample)));
|
||||
self.mapped[index] = Some(sample);
|
||||
old
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
pub fn record_chunk (&mut self, chunks: &[&[f32]]) {
|
||||
if let Some((_, sample)) = &mut self.recording {
|
||||
if chunks.len() != sample.channels.len() {
|
||||
panic!()
|
||||
}
|
||||
for (chunk, channel) in chunks.iter().zip(sample.channels.iter_mut()) {
|
||||
channel.extend_from_slice(chunk)
|
||||
}
|
||||
sample.end += chunks[0].len();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum SamplerCommand {
|
||||
|
|
@ -157,6 +147,7 @@ impl Sampler {
|
|||
*input_meter = vec![0.0;audio_ins.len()];
|
||||
}
|
||||
if let Some((_, sample)) = recording {
|
||||
let mut sample = sample.write().unwrap();
|
||||
if sample.channels.len() != audio_ins.len() {
|
||||
panic!("channel count mismatch");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ use crate::*;
|
|||
use std::ops::Deref;
|
||||
use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Points}}};
|
||||
|
||||
pub struct SampleViewer<'a>(pub Option<&'a Arc<RwLock<Sample>>>);
|
||||
render!(<Tui>|self: SampleViewer<'a>|render(|to|{
|
||||
pub struct SampleViewer(pub Option<Arc<RwLock<Sample>>>);
|
||||
render!(<Tui>|self: SampleViewer|render(|to|{
|
||||
let [x, y, width, height] = to.area();
|
||||
let area = Rect { x, y, width, height };
|
||||
let (x_bounds, y_bounds, coords): ([f64;2], [f64;2], &[(f64,f64)]) =
|
||||
if let Some(sample) = self.0 {
|
||||
if let Some(sample) = &self.0 {
|
||||
let sample = sample.read().unwrap();
|
||||
(
|
||||
[sample.start as f64, sample.end as f64],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue