diff --git a/.scratch.rs b/.scratch.rs deleted file mode 100644 index e6eede87..00000000 --- a/.scratch.rs +++ /dev/null @@ -1,357 +0,0 @@ -/// Just a scratchpad - -/// From sequencer: - - //pub fn footer ( - //buf: &mut Buffer, - //area: Rect, - //note0: usize, - //note: usize, - //time0: usize, - //time: usize, - //time_z: usize, - //) { - //let Rect { mut x, y, width, height } = area; - //buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())), - //Style::default().dim()); - //buf.set_string(x, y + height + 2, format!("├{}┤", "-".repeat((width - 2).into())), - //Style::default().dim()); - //x = x + 2; - //{ - //for (_, [letter, title, value]) in [ - //["S", &format!("ync"), &format!("<4/4>")], - //["Q", &format!("uant"), &format!("<1/{}>", 4 * time_z)], - //["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")], - //["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")], - //].iter().enumerate() { - //buf.set_string(x, y + height + 1, letter, Style::default().bold().yellow().dim()); - //x = x + 1; - //buf.set_string(x, y + height + 1, &title, Style::default().bold().dim()); - //x = x + title.len() as u16 + 1; - //buf.set_string(x, y + height + 1, &value, Style::default().not_dim()); - //x = x + value.len() as u16; - //buf.set_string(x, y + height + 1, " ", Style::default().dim()); - //x = x + 2; - //} - //} - //} - -//mod vertical { - //use super::*; - - //pub fn draw ( - //s: &Sequencer, - //buf: &mut Buffer, - //mut area: Rect, - //) -> Usually { - //area.x = area.x + 13; - //keys(s, buf, area, 0); - //steps(s, buf, area, 0); - //playhead(s, buf, area.x, area.y); - //Ok(area) - //} - - //pub fn steps (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) { - //if s.sequence.is_none() { - //return - //} - //let ppq = s.timebase.ppq() as usize; - //let bg = Style::default(); - //let bw = bg.dim(); - //let wh = bg.white(); - //let Rect { x, y, .. } = area; - //for step in s.time_start..s.time_start+area.height as usize { - //let y = y - (s.time_start + step / 2) as u16; - //let step = step as usize; - ////buf.set_string(x + 5, y, &" ".repeat(32.max(note1-s.note_start)as usize), bg); - //if step % s.time_zoom == 0 { - //buf.set_string(x + 2, y, &format!("{:2} ", step + 1), Style::default()); - //} - //for k in s.note_start..s.note_start+area.width as usize { - //let key = ::midly::num::u7::from_int_lossy(k as u8); - //if step % 2 == 0 { - //let (a, b, c) = ( - //(step + 0) as usize * ppq / s.time_zoom as usize, - //(step + 1) as usize * ppq / s.time_zoom as usize, - //(step + 2) as usize * ppq / s.time_zoom as usize, - //); - //let phrase = &s.phrases[s.sequence.unwrap()]; - //let (character, style) = match ( - //phrase.contains_note_on(key, a, b), - //phrase.contains_note_on(key, b, c), - //) { - //(true, true) => ("█", wh), - //(true, false) => ("▀", wh), - //(false, true) => ("▄", wh), - //(false, false) => ("·", bw), - //}; - //character.blit(buf, x + (5 + k - s.note_start) as u16, y, Some(style)); - //} - //} - //if beat == step as usize { - //buf.set_string(x + 4, y, if beat % 2 == 0 { "▀" } else { "▄" }, Style::default().yellow()); - //for key in s.note_start..s.note_start+area.width as usize { - //let _color = if s.notes_on[key as usize] { - //Style::default().red() - //} else { - //KEY_STYLE[key as usize % 12] - //}; - //} - //} - //} - //} - - //pub fn playhead (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16) { - //let x = x + 5 + s.note_cursor as u16; - //let y = y + s.time_cursor as u16 / 2; - //let c = if s.time_cursor % 2 == 0 { "▀" } else { "▄" }; - //buf.set_string(x, y, c, Style::default()); - //} - -//pub const KEY_WHITE: Style = Style { - //fg: Some(Color::Gray), - //bg: None, - //underline_color: None, - //add_modifier: ::ratatui::style::Modifier::empty(), - //sub_modifier: ::ratatui::style::Modifier::empty(), -//}; - -//pub const KEY_BLACK: Style = Style { - //fg: Some(Color::Black), - //bg: None, - //underline_color: None, - //add_modifier: ::ratatui::style::Modifier::empty(), - //sub_modifier: ::ratatui::style::Modifier::empty(), -//}; - -//pub const KEY_STYLE: [Style;12] = [ - //KEY_WHITE, KEY_BLACK, KEY_WHITE, KEY_BLACK, KEY_WHITE, - //KEY_WHITE, KEY_BLACK, KEY_WHITE, KEY_BLACK, KEY_WHITE, KEY_BLACK, KEY_WHITE, -//]; - - //pub fn keys (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) { - //let ppq = s.timebase.ppq() as usize; - //let Rect { x, y, .. } = area; - //for key in s.note_start..s.note_start+area.width as usize { - //let x = x + (5 + key - s.note_start) as u16; - //if key % 12 == 0 { - //let octave = format!("C{}", (key / 12) as i8 - 4); - //buf.set_string(x, y, &octave, Style::default()); - //} - //let mut color = KEY_STYLE[key as usize % 12]; - //let mut is_on = s.notes_on[key as usize]; - //let step = beat; - //let (a, b, c) = ( - //(step + 0) as usize * ppq / s.time_zoom as usize, - //(step + 1) as usize * ppq / s.time_zoom as usize, - //(step + 2) as usize * ppq / s.time_zoom as usize, - //); - //let key = ::midly::num::u7::from(key as u8); - //let phrase = &s.phrases[s.sequence.unwrap()]; - //is_on = is_on || phrase.contains_note_on(key, a, b); - //is_on = is_on || phrase.contains_note_on(key, b, c); - //if is_on { - //color = Style::default().red(); - //} - //buf.set_string(x, y - 1, &format!("▄"), color); - //} - //} - -////pub fn render (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually { - ////let Rect { x, y, width, height } = area; - ////let header = draw_header(s, buf, area)?; - ////let piano = match s.view { - ////SequencerMode::Tiny => Rect { x, y, width, height: 0 }, - ////SequencerMode::Compact => Rect { x, y, width, height: 0 }, - ////SequencerMode::Vertical => self::vertical::draw(s, buf, Rect { - ////x, y: y + header.height, width, height, - ////})?, - ////SequencerMode::Horizontal => self::horizontal::draw( - ////buf, - ////Rect { x, y: y + header.height, width, height, }, - ////s.phrase(), - ////s.timebase.ppq() as usize, - ////s.time_cursor, - ////s.time_start, - ////s.time_zoom, - ////s.note_cursor, - ////s.note_start, - ////None - ////)?, - ////}; - ////Ok(draw_box(buf, Rect { - ////x, y, - ////width: header.width.max(piano.width), - ////height: header.height + piano.height - ////})) -////} - -////pub fn draw_header (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually { - ////let Rect { x, y, width, .. } = area; - ////let style = Style::default().gray(); - ////crate::view::TransportView { - ////timebase: &s.timebase, - ////playing: s.playing, - ////record: s.recording, - ////overdub: s.overdub, - ////monitor: s.monitoring, - ////frame: 0 - ////}.render(buf, area)?; - ////let separator = format!("├{}┤", "-".repeat((width - 2).into())); - ////separator.blit(buf, x, y + 2, Some(style.dim())); - ////let _ = draw_clips(s, buf, area)?; - ////Ok(Rect { x, y, width, height: 3 }) -////} - -////pub fn draw_clips (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually { - ////let Rect { x, y, .. } = area; - ////let style = Style::default().gray(); - ////for (i, sequence) in s.phrases.iter().enumerate() { - ////let label = format!("▶ {}", &sequence.name); - ////label.blit(buf, x + 2, y + 3 + (i as u16)*2, Some(if Some(i) == s.sequence { - ////match s.playing { - ////TransportState::Rolling => style.white().bold(), - ////_ => style.not_dim().bold() - ////} - ////} else { - ////style.dim() - ////})); - ////} - ////Ok(Rect { x, y, width: 14, height: 14 }) -////} -//} - -/// From arranger: - -//use crate::core::*; -//use crate::view::*; -//use crate::model::*; - -//pub fn render (state: &Mixer, buf: &mut Buffer, mut area: Rect) - //-> Usually -//{ - //if area.height < 2 { - //return Ok(area) - //} - //area.x = area.width.saturating_sub(80) / 2; - //area.width = area.width.min(80); - //area.height = state.tracks.len() as u16 + 2; - //draw_box(buf, area); - //let x = area.x + 1; - //let y = area.y + 1; - //let _h = area.height - 2; - //for (i, track) in state.tracks.iter().enumerate() { - ////buf.set_string( - ////x, y + index as u16, - ////&track.name, Style::default().bold().not_dim() - ////); - //for (j, (column, field)) in [ - //(0, format!(" {:10} ", track.name)), - //(12, format!(" {:.1}dB ", track.gain)), - //(22, format!(" [ ] ")), - //(30, format!(" C ")), - //(35, format!(" {:.1}dB ", track.level)), - //(45, format!(" [ ] ")), - //(51, format!(" {:7} ", track.route)), - //].into_iter().enumerate() { - //buf.set_string( - //x + column as u16, - //y + i as u16, - //field, - //if state.selected_track == i && state.selected_column == j { - //Style::default().white().bold().not_dim() - //} else { - //Style::default().not_dim() - //} - //); - ////stdout.queue(move_to(column, row))?; - ////if state.selected_track == i && state.selected_column == j { - ////stdout.queue(PrintStyledContent(field.to_string().bold().reverse()))?; - ////} else { - ////stdout.queue(PrintStyledContent(field.to_string().bold()))?; - ////} - ////fn render_meters ( - ////state: &mut Mixer, - ////stdout: &mut Stdout, - ////offset: Rect - ////) -> Result<(), Box> { - ////let move_to = |col, row| crossterm::cursor::MoveTo(offset.0 + col, offset.1 + row); - ////for (i, track) in state.tracks.iter().enumerate() { - ////let row = (i + 1) as u16; - ////stdout - ////.queue(move_to(10, row))?.queue(PrintStyledContent("▁".green()))? - ////.queue(move_to(20, row))?.queue(PrintStyledContent("▁".green()))? - ////.queue(move_to(28, row))?.queue(PrintStyledContent("▁".green()))? - ////.queue(move_to(43, row))?.queue(PrintStyledContent("▁".green()))?; - ////} - ////Ok(()) - ////} - //} - //} - //Ok(area) -//} - - -/// From transport: - - // Record button/indicator - //&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{ - //"⏺ REC".blit(buf, x, y, Some(if self.record { red } else { dim })) - //}, - - //// Overdub button/indicator - //&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{ - //"⏺ DUB".blit(buf, x, y, Some(if self.overdub { yellow } else { dim })) - //}, - - //// Monitor button/indicator - //&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{ - //"⏺ MON".blit(buf, x, y, Some(if self.monitor { green } else { dim })) - //}, - // - -// From sampler: -//fn render_table ( - //self: &mut Sampler, - //stdout: &mut Stdout, - //offset: (u16, u16), -//) -> Result<(), Box> { - //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> { - //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(()) -//} -