mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
rename phrase -> clip mostly everywhere
This commit is contained in:
parent
709391ff0a
commit
08f7a62692
24 changed files with 426 additions and 423 deletions
|
|
@ -12,19 +12,19 @@ pub trait HasEditor {
|
|||
}
|
||||
}
|
||||
}
|
||||
/// Contains state for viewing and editing a phrase
|
||||
/// Contains state for viewing and editing a clip
|
||||
pub struct MidiEditor {
|
||||
pub mode: PianoHorizontal,
|
||||
pub size: Measure<TuiOut>
|
||||
}
|
||||
from!(|phrase: &Arc<RwLock<MidiClip>>|MidiEditor = {
|
||||
let model = Self::from(Some(phrase.clone()));
|
||||
from!(|clip: &Arc<RwLock<MidiClip>>|MidiEditor = {
|
||||
let model = Self::from(Some(clip.clone()));
|
||||
model.redraw();
|
||||
model
|
||||
});
|
||||
from!(|phrase: Option<Arc<RwLock<MidiClip>>>|MidiEditor = {
|
||||
from!(|clip: Option<Arc<RwLock<MidiClip>>>|MidiEditor = {
|
||||
let mut model = Self::default();
|
||||
*model.phrase_mut() = phrase;
|
||||
*model.clip_mut() = clip;
|
||||
model.redraw();
|
||||
model
|
||||
});
|
||||
|
|
@ -63,33 +63,33 @@ impl TimePoint for MidiEditor {
|
|||
fn set_time_point (&self, x: usize) { self.mode.set_time_point(x) }
|
||||
}
|
||||
impl MidiViewer for MidiEditor {
|
||||
fn buffer_size (&self, phrase: &MidiClip) -> (usize, usize) { self.mode.buffer_size(phrase) }
|
||||
fn buffer_size (&self, clip: &MidiClip) -> (usize, usize) { self.mode.buffer_size(clip) }
|
||||
fn redraw (&self) { self.mode.redraw() }
|
||||
fn phrase (&self) -> &Option<Arc<RwLock<MidiClip>>> { self.mode.phrase() }
|
||||
fn phrase_mut (&mut self) -> &mut Option<Arc<RwLock<MidiClip>>> { self.mode.phrase_mut() }
|
||||
fn set_phrase (&mut self, p: Option<&Arc<RwLock<MidiClip>>>) { self.mode.set_phrase(p) }
|
||||
fn clip (&self) -> &Option<Arc<RwLock<MidiClip>>> { self.mode.clip() }
|
||||
fn clip_mut (&mut self) -> &mut Option<Arc<RwLock<MidiClip>>> { self.mode.clip_mut() }
|
||||
fn set_clip (&mut self, p: Option<&Arc<RwLock<MidiClip>>>) { self.mode.set_clip(p) }
|
||||
}
|
||||
impl MidiEditor {
|
||||
/// Put note at current position
|
||||
pub fn put_note (&mut self, advance: bool) {
|
||||
let mut redraw = false;
|
||||
if let Some(phrase) = self.phrase() {
|
||||
let mut phrase = phrase.write().unwrap();
|
||||
if let Some(clip) = self.clip() {
|
||||
let mut clip = clip.write().unwrap();
|
||||
let note_start = self.time_point();
|
||||
let note_point = self.note_point();
|
||||
let note_len = self.note_len();
|
||||
let note_end = note_start + (note_len.saturating_sub(1));
|
||||
let key: u7 = u7::from(note_point as u8);
|
||||
let vel: u7 = 100.into();
|
||||
let length = phrase.length;
|
||||
let length = clip.length;
|
||||
let note_end = note_end % length;
|
||||
let note_on = MidiMessage::NoteOn { key, vel };
|
||||
if !phrase.notes[note_start].iter().any(|msg|*msg == note_on) {
|
||||
phrase.notes[note_start].push(note_on);
|
||||
if !clip.notes[note_start].iter().any(|msg|*msg == note_on) {
|
||||
clip.notes[note_start].push(note_on);
|
||||
}
|
||||
let note_off = MidiMessage::NoteOff { key, vel };
|
||||
if !phrase.notes[note_end].iter().any(|msg|*msg == note_off) {
|
||||
phrase.notes[note_end].push(note_off);
|
||||
if !clip.notes[note_end].iter().any(|msg|*msg == note_off) {
|
||||
clip.notes[note_end].push(note_off);
|
||||
}
|
||||
if advance {
|
||||
self.set_time_point(note_end);
|
||||
|
|
@ -102,8 +102,8 @@ impl MidiEditor {
|
|||
}
|
||||
|
||||
pub fn clip_status (&self) -> impl Content<TuiOut> + '_ {
|
||||
let (color, name, length, looped) = if let Some(phrase) = self.phrase().as_ref().map(|p|p.read().unwrap()) {
|
||||
(phrase.color, phrase.name.clone(), phrase.length, phrase.looped)
|
||||
let (color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
|
||||
(clip.color, clip.name.clone(), clip.length, clip.looped)
|
||||
} else {
|
||||
(ItemPalette::from(TuiTheme::g(64)), String::new().into(), 0, false)
|
||||
};
|
||||
|
|
@ -114,8 +114,8 @@ impl MidiEditor {
|
|||
}
|
||||
|
||||
pub fn edit_status (&self) -> impl Content<TuiOut> + '_ {
|
||||
let (color, length) = if let Some(phrase) = self.phrase().as_ref().map(|p|p.read().unwrap()) {
|
||||
(phrase.color, phrase.length)
|
||||
let (color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
|
||||
(clip.color, clip.length)
|
||||
} else {
|
||||
(ItemPalette::from(TuiTheme::g(64)), 0)
|
||||
};
|
||||
|
|
@ -140,7 +140,7 @@ impl std::fmt::Debug for MidiEditor {
|
|||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MidiEditCommand {
|
||||
// TODO: 1-9 seek markers that by default start every 8th of the phrase
|
||||
// TODO: 1-9 seek markers that by default start every 8th of the clip
|
||||
AppendNote,
|
||||
PutNote,
|
||||
SetNoteCursor(usize),
|
||||
|
|
@ -160,11 +160,11 @@ keymap!(KEYS_MIDI_EDITOR = |s: MidiEditor, _input: Event| MidiEditCommand {
|
|||
key(Char('s')) => SetNoteCursor(s.note_point().saturating_sub(1)),
|
||||
key(Left) => SetTimeCursor(s.time_point().saturating_sub(s.note_len())),
|
||||
key(Char('a')) => SetTimeCursor(s.time_point().saturating_sub(s.note_len())),
|
||||
key(Right) => SetTimeCursor((s.time_point() + s.note_len()) % s.phrase_length()),
|
||||
key(Right) => SetTimeCursor((s.time_point() + s.note_len()) % s.clip_length()),
|
||||
ctrl(alt(key(Up))) => SetNoteScroll(s.note_point() + 3),
|
||||
ctrl(alt(key(Down))) => SetNoteScroll(s.note_point().saturating_sub(3)),
|
||||
ctrl(alt(key(Left))) => SetTimeScroll(s.time_point().saturating_sub(s.time_zoom().get())),
|
||||
ctrl(alt(key(Right))) => SetTimeScroll((s.time_point() + s.time_zoom().get()) % s.phrase_length()),
|
||||
ctrl(alt(key(Right))) => SetTimeScroll((s.time_point() + s.time_zoom().get()) % s.clip_length()),
|
||||
ctrl(key(Up)) => SetNoteScroll(s.note_lo().get() + 1),
|
||||
ctrl(key(Down)) => SetNoteScroll(s.note_lo().get().saturating_sub(1)),
|
||||
ctrl(key(Left)) => SetTimeScroll(s.time_start().get().saturating_sub(s.note_len())),
|
||||
|
|
@ -172,8 +172,8 @@ keymap!(KEYS_MIDI_EDITOR = |s: MidiEditor, _input: Event| MidiEditCommand {
|
|||
alt(key(Up)) => SetNoteCursor(s.note_point() + 3),
|
||||
alt(key(Down)) => SetNoteCursor(s.note_point().saturating_sub(3)),
|
||||
alt(key(Left)) => SetTimeCursor(s.time_point().saturating_sub(s.time_zoom().get())),
|
||||
alt(key(Right)) => SetTimeCursor((s.time_point() + s.time_zoom().get()) % s.phrase_length()),
|
||||
key(Char('d')) => SetTimeCursor((s.time_point() + s.note_len()) % s.phrase_length()),
|
||||
alt(key(Right)) => SetTimeCursor((s.time_point() + s.time_zoom().get()) % s.clip_length()),
|
||||
key(Char('d')) => SetTimeCursor((s.time_point() + s.note_len()) % s.clip_length()),
|
||||
key(Char('z')) => SetTimeLock(!s.time_lock().get()),
|
||||
key(Char('-')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::next(s.time_zoom().get()) }),
|
||||
key(Char('_')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::next(s.time_zoom().get()) }),
|
||||
|
|
@ -189,15 +189,15 @@ keymap!(KEYS_MIDI_EDITOR = |s: MidiEditor, _input: Event| MidiEditCommand {
|
|||
//// TODO: kpat!(Char('?')) => // toggle dotted
|
||||
});
|
||||
impl MidiEditor {
|
||||
fn phrase_length (&self) -> usize {
|
||||
self.phrase().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1)
|
||||
fn clip_length (&self) -> usize {
|
||||
self.clip().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1)
|
||||
}
|
||||
}
|
||||
impl Command<MidiEditor> for MidiEditCommand {
|
||||
fn execute (self, state: &mut MidiEditor) -> Perhaps<Self> {
|
||||
use MidiEditCommand::*;
|
||||
match self {
|
||||
Show(phrase) => { state.set_phrase(phrase.as_ref()); },
|
||||
Show(clip) => { state.set_clip(clip.as_ref()); },
|
||||
PutNote => { state.put_note(false); },
|
||||
AppendNote => { state.put_note(true); },
|
||||
SetTimeZoom(x) => { state.time_zoom().set(x); state.redraw(); },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue