mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
156 lines
5.7 KiB
Rust
156 lines
5.7 KiB
Rust
use crate::*;
|
|
mod model_track; pub use self::model_track::*;
|
|
mod model_scene; pub use self::model_scene::*;
|
|
mod model_select; pub use self::model_select::*;
|
|
#[derive(Default, Debug)] pub struct Tek {
|
|
/// Must not be dropped for the duration of the process
|
|
pub jack: Jack,
|
|
/// Source of time
|
|
pub clock: Clock,
|
|
/// Theme
|
|
pub color: ItemPalette,
|
|
/// Contains all clips in the project
|
|
pub pool: Option<MidiPool>,
|
|
/// Contains the currently edited MIDI clip
|
|
pub editor: Option<MidiEditor>,
|
|
/// Contains a render of the project arrangement, redrawn on update.
|
|
pub arranger: Arc<RwLock<Buffer>>,
|
|
pub midi_ins: Vec<JackMidiIn>,
|
|
pub midi_outs: Vec<JackMidiOut>,
|
|
pub audio_ins: Vec<JackAudioIn>,
|
|
pub audio_outs: Vec<JackAudioOut>,
|
|
pub note_buf: Vec<u8>,
|
|
pub midi_buf: Vec<Vec<Vec<u8>>>,
|
|
|
|
pub tracks: Vec<Track>,
|
|
pub track_scroll: usize,
|
|
|
|
pub scenes: Vec<Scene>,
|
|
pub scene_scroll: usize,
|
|
|
|
pub selected: Selection,
|
|
pub size: Measure<TuiOut>,
|
|
pub perf: PerfModel,
|
|
pub editing: AtomicBool,
|
|
pub history: Vec<TekCommand>,
|
|
pub ports: std::collections::BTreeMap<u32, Port<Unowned>>,
|
|
|
|
/// View definition
|
|
pub view: SourceIter<'static>,
|
|
// Input definitions
|
|
pub keys: SourceIter<'static>,
|
|
pub keys_clip: SourceIter<'static>,
|
|
pub keys_track: SourceIter<'static>,
|
|
pub keys_scene: SourceIter<'static>,
|
|
pub keys_mix: SourceIter<'static>,
|
|
|
|
pub(crate) fmtd: Arc<RwLock<ViewCache>>,
|
|
}
|
|
has_size!(<TuiOut>|self: Tek|&self.size);
|
|
has_clock!(|self: Tek|self.clock);
|
|
has_clips!(|self: Tek|self.pool.as_ref().expect("no clip pool").clips);
|
|
//has_sampler!(|self: Tek|{
|
|
//sampler = self.sampler;
|
|
//index = self.editor.as_ref().map(|e|e.note_pos()).unwrap_or(0); });
|
|
has_editor!(|self: Tek|{
|
|
editor = self.editor;
|
|
editor_w = {
|
|
let size = self.size.w();
|
|
let editor = self.editor.as_ref().expect("missing editor");
|
|
let time_len = editor.time_len().get();
|
|
let time_zoom = editor.time_zoom().get().max(1);
|
|
(5 + (time_len / time_zoom)).min(size.saturating_sub(20)).max(16)
|
|
};
|
|
editor_h = 15;
|
|
is_editing = self.editing.load(Relaxed); });
|
|
provide!(Color: |self: Tek| {});
|
|
provide!(Arc<RwLock<MidiClip>>: |self: Tek| {});
|
|
provide!(Option<Arc<RwLock<MidiClip>>>: |self: Tek| {
|
|
":clip" => match self.selected {
|
|
Selection::Clip(t, s) => self.scenes[s].clips[t].clone(),
|
|
_ => None
|
|
}
|
|
});
|
|
provide_bool!(bool: |self: Tek| {});
|
|
provide_num!(isize: |self: Tek| {});
|
|
provide_num!(usize: |self: Tek| {
|
|
":scene-last" => self.scenes.len(),
|
|
":track-last" => self.tracks.len() });
|
|
provide!(Option<usize>: |self: Tek| {
|
|
":scene" => self.selected.scene(),
|
|
":track" => self.selected.track() });
|
|
provide!(Selection: |self: Tek| {
|
|
":scene-next" => match self.selected {
|
|
Selection::Mix => Selection::Scene(0),
|
|
Selection::Track(t) => Selection::Clip(t, 0),
|
|
Selection::Scene(s) if s + 1 < self.scenes.len() => Selection::Scene(s + 1),
|
|
Selection::Scene(s) => Selection::Mix,
|
|
Selection::Clip(t, s) if s + 1 < self.scenes.len() => Selection::Clip(t, s + 1),
|
|
Selection::Clip(t, s) => Selection::Track(t),
|
|
},
|
|
":scene-prev" => match self.selected {
|
|
Selection::Mix => Selection::Mix,
|
|
Selection::Track(t) => Selection::Track(t),
|
|
Selection::Scene(0) => Selection::Mix,
|
|
Selection::Scene(s) => Selection::Scene(s - 1),
|
|
Selection::Clip(t, 0) => Selection::Track(t),
|
|
Selection::Clip(t, s) => Selection::Clip(t, s - 1),
|
|
},
|
|
":track-next" => match self.selected {
|
|
Selection::Mix => Selection::Track(0),
|
|
Selection::Track(t) if t + 1 < self.tracks.len() => Selection::Track(t + 1),
|
|
Selection::Track(t) => Selection::Mix,
|
|
Selection::Scene(s) => Selection::Clip(0, s),
|
|
Selection::Clip(t, s) if t + 1 < self.tracks.len() => Selection::Clip(t + 1, s),
|
|
Selection::Clip(t, s) => Selection::Scene(s),
|
|
},
|
|
":track-prev" => match self.selected {
|
|
Selection::Mix => Selection::Mix,
|
|
Selection::Scene(s) => Selection::Scene(s),
|
|
Selection::Track(0) => Selection::Mix,
|
|
Selection::Track(t) => Selection::Track(t - 1),
|
|
Selection::Clip(0, s) => Selection::Scene(s),
|
|
Selection::Clip(t, s) => Selection::Clip(t - 1, s),
|
|
},
|
|
});
|
|
impl Tek {
|
|
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
|
self.scene()?.clips.get(self.selected().track()?)?.clone()
|
|
}
|
|
fn toggle_loop (&mut self) {
|
|
if let Some(clip) = self.clip() {
|
|
clip.write().unwrap().toggle_loop()
|
|
}
|
|
}
|
|
fn activate (&mut self) -> Usually<()> {
|
|
let selected = self.selected().clone();
|
|
match selected {
|
|
Selection::Scene(s) => {
|
|
let mut clips = vec![];
|
|
for (t, _) in self.tracks().iter().enumerate() {
|
|
clips.push(self.scenes()[s].clips[t].clone());
|
|
}
|
|
for (t, track) in self.tracks_mut().iter_mut().enumerate() {
|
|
if track.player.play_clip.is_some() || clips[t].is_some() {
|
|
track.player.enqueue_next(clips[t].as_ref());
|
|
}
|
|
}
|
|
if self.clock().is_stopped() {
|
|
self.clock().play_from(Some(0))?;
|
|
}
|
|
},
|
|
Selection::Clip(t, s) => {
|
|
let clip = self.scenes()[s].clips[t].clone();
|
|
self.tracks_mut()[t].player.enqueue_next(clip.as_ref());
|
|
},
|
|
_ => {}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
#[cfg(test)] #[test] fn test_model () {
|
|
let mut tek = Tek::default();
|
|
let _ = tek.clip();
|
|
let _ = tek.toggle_loop();
|
|
let _ = tek.activate();
|
|
}
|