mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
extract transport
This commit is contained in:
parent
449615eea8
commit
5a9ec0a63d
12 changed files with 178 additions and 182 deletions
|
|
@ -72,7 +72,7 @@ const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
||||||
}],
|
}],
|
||||||
|
|
||||||
[Char(' '), NONE, "play_toggle", "play or pause", |app: &mut App| {
|
[Char(' '), NONE, "play_toggle", "play or pause", |app: &mut App| {
|
||||||
app.toggle_play()?;
|
app.transport.toggle_play()?;
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}],
|
}],
|
||||||
[Char('r'), NONE, "record_toggle", "toggle recording", |app: &mut App| {
|
[Char('r'), NONE, "record_toggle", "toggle recording", |app: &mut App| {
|
||||||
|
|
@ -89,11 +89,11 @@ const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
||||||
}],
|
}],
|
||||||
|
|
||||||
[Char('+'), NONE, "quant_inc", "Quantize coarser", |app: &mut App| {
|
[Char('+'), NONE, "quant_inc", "Quantize coarser", |app: &mut App| {
|
||||||
app.quant = next_note_length(app.quant);
|
app.transport.quant = next_note_length(app.transport.quant);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}],
|
}],
|
||||||
[Char('_'), NONE, "quant_dec", "Quantize finer", |app: &mut App| {
|
[Char('_'), NONE, "quant_dec", "Quantize finer", |app: &mut App| {
|
||||||
app.quant = prev_note_length(app.quant);
|
app.transport.quant = prev_note_length(app.transport.quant);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
use crate::{core::*, model::*};
|
use crate::{core::*, model::*};
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// - Meters: propagate clipping:
|
||||||
|
// - If one stage clips, all stages after it are marked red
|
||||||
|
// - If one track clips, all tracks that feed from it are marked red?
|
||||||
|
|
||||||
|
//pub const ACTIONS: [(&'static str, &'static str);2] = [
|
||||||
|
//("+/-", "Adjust"),
|
||||||
|
//("Ins/Del", "Add/remove track"),
|
||||||
|
//];
|
||||||
|
|
||||||
pub fn handle (state: &mut Mixer, event: &AppEvent) -> Usually<bool> {
|
pub fn handle (state: &mut Mixer, event: &AppEvent) -> Usually<bool> {
|
||||||
if let AppEvent::Input(crossterm::event::Event::Key(event)) = event {
|
if let AppEvent::Input(crossterm::event::Event::Key(event)) = event {
|
||||||
|
|
||||||
|
|
@ -47,13 +57,3 @@ pub fn handle (state: &mut Mixer, event: &AppEvent) -> Usually<bool> {
|
||||||
}
|
}
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// - Meters: propagate clipping:
|
|
||||||
// - If one stage clips, all stages after it are marked red
|
|
||||||
// - If one track clips, all tracks that feed from it are marked red?
|
|
||||||
|
|
||||||
pub const ACTIONS: [(&'static str, &'static str);2] = [
|
|
||||||
("+/-", "Adjust"),
|
|
||||||
("Ins/Del", "Add/remove track"),
|
|
||||||
];
|
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,6 @@ pub fn run <T> (state: Arc<RwLock<T>>) -> Usually<Arc<RwLock<T>>>
|
||||||
terminal_teardown()?;
|
terminal_teardown()?;
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
pub trait Run: Render + Handle + Send + Sync + Sized + 'static {
|
|
||||||
fn run (self) -> Usually<Arc<RwLock<Self>>> { run(Arc::new(RwLock::new(self))) }
|
|
||||||
}
|
|
||||||
impl<T: Render + Handle + Send + Sync + Sized + 'static> Run for T {}
|
|
||||||
|
|
||||||
/// Set up panic hook
|
/// Set up panic hook
|
||||||
pub fn panic_hook_setup () {
|
pub fn panic_hook_setup () {
|
||||||
|
|
|
||||||
10
src/edn.rs
10
src/edn.rs
|
|
@ -21,7 +21,7 @@ impl App {
|
||||||
}
|
}
|
||||||
pub fn load_edn (&mut self, mut src: &str) -> Usually<&mut Self> {
|
pub fn load_edn (&mut self, mut src: &str) -> Usually<&mut Self> {
|
||||||
loop {
|
loop {
|
||||||
match clojure_reader::edn::read(src) {
|
match read(src) {
|
||||||
Ok((edn, rest)) => {
|
Ok((edn, rest)) => {
|
||||||
self.load_edn_one(edn)?;
|
self.load_edn_one(edn)?;
|
||||||
if rest.len() > 0 {
|
if rest.len() > 0 {
|
||||||
|
|
@ -46,8 +46,10 @@ impl App {
|
||||||
match items.get(0) {
|
match items.get(0) {
|
||||||
Some(Edn::Symbol("bpm")) => {
|
Some(Edn::Symbol("bpm")) => {
|
||||||
match items.get(1) {
|
match items.get(1) {
|
||||||
Some(Edn::Int(b)) => self.timebase.set_bpm(*b as f64),
|
Some(Edn::Int(b)) =>
|
||||||
Some(Edn::Double(b)) => self.timebase.set_bpm(f64::from(*b)),
|
self.transport.timebase.set_bpm(*b as f64),
|
||||||
|
Some(Edn::Double(b)) =>
|
||||||
|
self.transport.timebase.set_bpm(f64::from(*b)),
|
||||||
_ => panic!("unspecified bpm")
|
_ => panic!("unspecified bpm")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -99,7 +101,7 @@ impl Scene {
|
||||||
|
|
||||||
impl Track {
|
impl Track {
|
||||||
fn load_edn <'a, 'e> (app: &'a mut App, args: &[Edn<'e>]) -> Usually<&'a mut Self> {
|
fn load_edn <'a, 'e> (app: &'a mut App, args: &[Edn<'e>]) -> Usually<&'a mut Self> {
|
||||||
let ppq = app.timebase.ppq() as usize;
|
let ppq = app.transport.ppq();
|
||||||
let mut name = app.new_track_name();
|
let mut name = app.new_track_name();
|
||||||
let mut _gain = 0.0f64;
|
let mut _gain = 0.0f64;
|
||||||
let mut devices: Vec<JackDevice> = vec![];
|
let mut devices: Vec<JackDevice> = vec![];
|
||||||
|
|
|
||||||
101
src/model.rs
101
src/model.rs
|
|
@ -5,6 +5,7 @@ pub mod plugin;
|
||||||
pub mod sampler;
|
pub mod sampler;
|
||||||
pub mod scene;
|
pub mod scene;
|
||||||
pub mod track;
|
pub mod track;
|
||||||
|
pub mod transport;
|
||||||
|
|
||||||
pub use self::phrase::{Phrase, PhraseData};
|
pub use self::phrase::{Phrase, PhraseData};
|
||||||
pub use self::scene::Scene;
|
pub use self::scene::Scene;
|
||||||
|
|
@ -12,12 +13,11 @@ pub use self::track::Track;
|
||||||
pub use self::sampler::{Sampler, Sample, read_sample_data};
|
pub use self::sampler::{Sampler, Sample, read_sample_data};
|
||||||
pub use self::mixer::Mixer;
|
pub use self::mixer::Mixer;
|
||||||
pub use self::plugin::{Plugin, PluginKind, lv2::LV2Plugin};
|
pub use self::plugin::{Plugin, PluginKind, lv2::LV2Plugin};
|
||||||
|
pub use self::transport::TransportToolbar;
|
||||||
|
|
||||||
use crate::{core::*, view::*};
|
use crate::{core::*, view::*};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
/// Paths to user directories
|
|
||||||
pub xdg: Option<Arc<XdgApp>>,
|
|
||||||
/// Main JACK client.
|
/// Main JACK client.
|
||||||
pub jack: Option<JackClient>,
|
pub jack: Option<JackClient>,
|
||||||
/// Map of external MIDI outs in the jack graph
|
/// Map of external MIDI outs in the jack graph
|
||||||
|
|
@ -25,18 +25,6 @@ pub struct App {
|
||||||
pub midi_in: Option<Arc<Port<MidiIn>>>,
|
pub midi_in: Option<Arc<Port<MidiIn>>>,
|
||||||
/// Names of ports to connect to main MIDI IN.
|
/// Names of ports to connect to main MIDI IN.
|
||||||
pub midi_ins: Vec<String>,
|
pub midi_ins: Vec<String>,
|
||||||
/// Main audio outputs.
|
|
||||||
pub audio_outs: Vec<Arc<Port<Unowned>>>,
|
|
||||||
/// JACK transport handle.
|
|
||||||
pub transport: Option<Transport>,
|
|
||||||
/// Current transport state
|
|
||||||
pub playing: Option<TransportState>,
|
|
||||||
/// Current position according to transport
|
|
||||||
pub playhead: usize,
|
|
||||||
/// Position of T0 for this playback within global timeline
|
|
||||||
pub play_started: Option<(usize, usize)>,
|
|
||||||
/// Current sample rate and tempo.
|
|
||||||
pub timebase: Arc<Timebase>,
|
|
||||||
/// Display mode of arranger section
|
/// Display mode of arranger section
|
||||||
pub arranger_mode: bool,
|
pub arranger_mode: bool,
|
||||||
/// Display mode of chain section
|
/// Display mode of chain section
|
||||||
|
|
@ -49,10 +37,8 @@ pub struct App {
|
||||||
pub modal: Option<Box<dyn Component>>,
|
pub modal: Option<Box<dyn Component>>,
|
||||||
/// Currently focused section
|
/// Currently focused section
|
||||||
pub section: AppSection,
|
pub section: AppSection,
|
||||||
/// Whether the section is focused
|
/// Whether the current focus section has input priority
|
||||||
pub entered: bool,
|
pub entered: bool,
|
||||||
/// Current frame
|
|
||||||
pub metronome: bool,
|
|
||||||
/// Display position of cursor within note range
|
/// Display position of cursor within note range
|
||||||
pub note_cursor: usize,
|
pub note_cursor: usize,
|
||||||
/// Range of notes to display
|
/// Range of notes to display
|
||||||
|
|
@ -67,12 +53,16 @@ pub struct App {
|
||||||
pub track_cursor: usize,
|
pub track_cursor: usize,
|
||||||
/// Collection of tracks
|
/// Collection of tracks
|
||||||
pub tracks: Vec<Track>,
|
pub tracks: Vec<Track>,
|
||||||
|
/// Paths to user directories
|
||||||
|
xdg: Option<Arc<XdgApp>>,
|
||||||
|
/// Main audio outputs.
|
||||||
|
audio_outs: Vec<Arc<Port<Unowned>>>,
|
||||||
|
/// Tick enable?
|
||||||
|
metronome: bool,
|
||||||
/// Number of frames requested by process callback
|
/// Number of frames requested by process callback
|
||||||
pub chunk_size: usize,
|
chunk_size: usize,
|
||||||
/// Quantization factor
|
|
||||||
pub quant: usize,
|
pub transport: TransportToolbar,
|
||||||
/// Init callbacks called once after root JACK client has activated.
|
|
||||||
pub callbacks: Vec<Box<dyn (FnOnce(Arc<RwLock<Self>>)->Usually<()>) + Send + Sync>>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
|
@ -80,11 +70,10 @@ impl App {
|
||||||
let xdg = Arc::new(microxdg::XdgApp::new("tek")?);
|
let xdg = Arc::new(microxdg::XdgApp::new("tek")?);
|
||||||
let first_run = crate::config::AppPaths::new(&xdg)?.should_create();
|
let first_run = crate::config::AppPaths::new(&xdg)?.should_create();
|
||||||
let jack = JackClient::Inactive(Client::new("tek", ClientOptions::NO_START_SERVER)?.0);
|
let jack = JackClient::Inactive(Client::new("tek", ClientOptions::NO_START_SERVER)?.0);
|
||||||
let transport = jack.transport();
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
transport: TransportToolbar::new(Some(jack.transport())),
|
||||||
arranger_mode: false,
|
arranger_mode: false,
|
||||||
audio_outs: vec![],
|
audio_outs: vec![],
|
||||||
callbacks: vec![],
|
|
||||||
chain_mode: false,
|
chain_mode: false,
|
||||||
chunk_size: 0,
|
chunk_size: 0,
|
||||||
entered: true,
|
entered: true,
|
||||||
|
|
@ -95,35 +84,30 @@ impl App {
|
||||||
modal: first_run.then(||crate::config::SetupModal(Some(xdg.clone())).boxed()),
|
modal: first_run.then(||crate::config::SetupModal(Some(xdg.clone())).boxed()),
|
||||||
note_cursor: 0,
|
note_cursor: 0,
|
||||||
note_start: 2,
|
note_start: 2,
|
||||||
play_started: None,
|
|
||||||
playhead: 0,
|
|
||||||
playing: None,
|
|
||||||
quant: 24,
|
|
||||||
scene_cursor: 1,
|
scene_cursor: 1,
|
||||||
scenes: vec![],
|
scenes: vec![],
|
||||||
section: AppSection::default(),
|
section: AppSection::default(),
|
||||||
seq_mode: false,
|
seq_mode: false,
|
||||||
seq_buf: BufferedSequencerView::new(96, 16384),
|
seq_buf: BufferedSequencerView::new(96, 16384),
|
||||||
time_cursor: 0,
|
time_cursor: 0,
|
||||||
timebase: Arc::new(Timebase::default()),
|
|
||||||
track_cursor: 1,
|
track_cursor: 1,
|
||||||
tracks: vec![],
|
tracks: vec![],
|
||||||
transport: Some(transport),
|
|
||||||
xdg: Some(xdg),
|
xdg: Some(xdg),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
process!(App |self, _client, scope| {
|
process!(App |self, _client, scope| {
|
||||||
let (
|
let (
|
||||||
reset, current_frames, current_usecs, next_usecs, period_usecs
|
reset, current_frames, chunk_size, current_usecs, next_usecs, period_usecs
|
||||||
) = self.update_time(&scope);
|
) = self.transport.update(&scope);
|
||||||
|
self.chunk_size = chunk_size;
|
||||||
for track in self.tracks.iter_mut() {
|
for track in self.tracks.iter_mut() {
|
||||||
track.process(
|
track.process(
|
||||||
self.midi_in.as_ref().map(|p|p.iter(&scope)),
|
self.midi_in.as_ref().map(|p|p.iter(&scope)),
|
||||||
&self.timebase,
|
&self.transport.timebase,
|
||||||
self.playing,
|
self.transport.playing,
|
||||||
self.play_started,
|
self.transport.started,
|
||||||
self.quant,
|
self.transport.quant,
|
||||||
reset,
|
reset,
|
||||||
&scope,
|
&scope,
|
||||||
(current_frames as usize, self.chunk_size),
|
(current_frames as usize, self.chunk_size),
|
||||||
|
|
@ -169,51 +153,6 @@ impl App {
|
||||||
}
|
}
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
pub fn update_time (&mut self, scope: &ProcessScope) -> (bool, usize, usize, usize, f64) {
|
|
||||||
let CycleTimes {
|
|
||||||
current_frames,
|
|
||||||
current_usecs,
|
|
||||||
next_usecs,
|
|
||||||
period_usecs
|
|
||||||
} = scope.cycle_times().unwrap();
|
|
||||||
self.chunk_size = scope.n_frames() as usize;
|
|
||||||
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
|
||||||
self.playhead = transport.pos.frame() as usize;
|
|
||||||
let mut reset = false;
|
|
||||||
if self.playing != Some(transport.state) {
|
|
||||||
match transport.state {
|
|
||||||
TransportState::Rolling => {
|
|
||||||
self.play_started = Some((
|
|
||||||
current_frames as usize,
|
|
||||||
current_usecs as usize,
|
|
||||||
));
|
|
||||||
},
|
|
||||||
TransportState::Stopped => {
|
|
||||||
self.play_started = None;
|
|
||||||
reset = true;
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.playing = Some(transport.state);
|
|
||||||
(
|
|
||||||
reset, current_frames as usize, current_usecs as usize, next_usecs as usize, period_usecs as f64
|
|
||||||
)
|
|
||||||
}
|
|
||||||
pub fn toggle_play (&mut self) -> Usually<()> {
|
|
||||||
self.playing = match self.playing.expect("1st frame has not been processed yet") {
|
|
||||||
TransportState::Stopped => {
|
|
||||||
self.transport.as_ref().unwrap().start()?;
|
|
||||||
Some(TransportState::Starting)
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
self.transport.as_ref().unwrap().stop()?;
|
|
||||||
self.transport.as_ref().unwrap().locate(0)?;
|
|
||||||
Some(TransportState::Stopped)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Copy)]
|
#[derive(PartialEq, Clone, Copy)]
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,6 @@ impl App {
|
||||||
let clip = (*scene.clips.get(track_id)?)?;
|
let clip = (*scene.clips.get(track_id)?)?;
|
||||||
self.track_mut()?.1.phrases.get_mut(clip)
|
self.track_mut()?.1.phrases.get_mut(clip)
|
||||||
}
|
}
|
||||||
fn phrase_id (&self) -> Option<usize> {
|
|
||||||
let (track_id, _) = self.track()?;
|
|
||||||
let (_, scene) = self.scene()?;
|
|
||||||
*scene.clips.get(track_id)?
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define a MIDI phrase.
|
/// Define a MIDI phrase.
|
||||||
|
|
|
||||||
97
src/model/transport.rs
Normal file
97
src/model/transport.rs
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
use crate::{core::*,view::*,model::{App, AppSection}};
|
||||||
|
|
||||||
|
pub struct TransportToolbar {
|
||||||
|
mode: bool,
|
||||||
|
pub focused: bool,
|
||||||
|
pub entered: bool,
|
||||||
|
/// Current sample rate, tempo, and PPQ.
|
||||||
|
pub timebase: Arc<Timebase>,
|
||||||
|
/// JACK transport handle.
|
||||||
|
transport: Option<Transport>,
|
||||||
|
/// Quantization factor
|
||||||
|
pub quant: usize,
|
||||||
|
/// Current transport state
|
||||||
|
pub playing: Option<TransportState>,
|
||||||
|
/// Current position according to transport
|
||||||
|
playhead: usize,
|
||||||
|
/// Global frame and usec at which playback started
|
||||||
|
pub started: Option<(usize, usize)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TransportToolbar {
|
||||||
|
pub fn new (transport: Option<Transport>) -> Self {
|
||||||
|
Self {
|
||||||
|
transport,
|
||||||
|
mode: false,
|
||||||
|
focused: false,
|
||||||
|
entered: false,
|
||||||
|
timebase: Arc::new(Timebase::default()),
|
||||||
|
playhead: 0,
|
||||||
|
playing: Some(TransportState::Stopped),
|
||||||
|
started: None,
|
||||||
|
quant: 24,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn toggle_play (&mut self) -> Usually<()> {
|
||||||
|
self.playing = match self.playing.expect("1st frame has not been processed yet") {
|
||||||
|
TransportState::Stopped => {
|
||||||
|
self.transport.as_ref().unwrap().start()?;
|
||||||
|
Some(TransportState::Starting)
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
self.transport.as_ref().unwrap().stop()?;
|
||||||
|
self.transport.as_ref().unwrap().locate(0)?;
|
||||||
|
Some(TransportState::Stopped)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
pub fn update (&mut self, scope: &ProcessScope) -> (bool, usize, usize, usize, usize, f64) {
|
||||||
|
let CycleTimes {
|
||||||
|
current_frames,
|
||||||
|
current_usecs,
|
||||||
|
next_usecs,
|
||||||
|
period_usecs
|
||||||
|
} = scope.cycle_times().unwrap();
|
||||||
|
let chunk_size = scope.n_frames() as usize;
|
||||||
|
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
||||||
|
self.playhead = transport.pos.frame() as usize;
|
||||||
|
let mut reset = false;
|
||||||
|
if self.playing != Some(transport.state) {
|
||||||
|
match transport.state {
|
||||||
|
TransportState::Rolling => {
|
||||||
|
self.started = Some((
|
||||||
|
current_frames as usize,
|
||||||
|
current_usecs as usize,
|
||||||
|
));
|
||||||
|
},
|
||||||
|
TransportState::Stopped => {
|
||||||
|
self.started = None;
|
||||||
|
reset = true;
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.playing = Some(transport.state);
|
||||||
|
(
|
||||||
|
reset,
|
||||||
|
current_frames as usize,
|
||||||
|
chunk_size as usize,
|
||||||
|
current_usecs as usize,
|
||||||
|
next_usecs as usize,
|
||||||
|
period_usecs as f64
|
||||||
|
)
|
||||||
|
}
|
||||||
|
pub fn bpm (&self) -> usize {
|
||||||
|
self.timebase.bpm() as usize
|
||||||
|
}
|
||||||
|
pub fn ppq (&self) -> usize {
|
||||||
|
self.timebase.ppq() as usize
|
||||||
|
}
|
||||||
|
pub fn pulse (&self) -> usize {
|
||||||
|
self.timebase.frame_to_pulse(self.playhead as f64) as usize
|
||||||
|
}
|
||||||
|
pub fn usecs (&self) -> usize {
|
||||||
|
self.timebase.frame_to_usec(self.playhead as f64) as usize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,6 @@ pub mod theme;
|
||||||
|
|
||||||
pub use self::border::*;
|
pub use self::border::*;
|
||||||
pub use self::theme::*;
|
pub use self::theme::*;
|
||||||
pub use self::transport::TransportView;
|
|
||||||
pub use self::arranger::*;
|
pub use self::arranger::*;
|
||||||
pub use self::chain::ChainView;
|
pub use self::chain::ChainView;
|
||||||
pub use self::sequencer::{SequencerView, BufferedSequencerView};
|
pub use self::sequencer::{SequencerView, BufferedSequencerView};
|
||||||
|
|
@ -17,7 +16,7 @@ use crate::{render, App, core::*};
|
||||||
|
|
||||||
render!(App |self, buf, area| {
|
render!(App |self, buf, area| {
|
||||||
Split::down([
|
Split::down([
|
||||||
&TransportView::new(self),
|
&self.transport,
|
||||||
&ArrangerView::new(&self, !self.arranger_mode),
|
&ArrangerView::new(&self, !self.arranger_mode),
|
||||||
&If(self.track_cursor > 0, &Split::right([
|
&If(self.track_cursor > 0, &Split::right([
|
||||||
&ChainView::vertical(&self),
|
&ChainView::vertical(&self),
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ pub struct ArrangerView<'a> {
|
||||||
vertical: bool,
|
vertical: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const HELP: &'static str = "[C-t] Add track [C-a] Add scene [v] Show/hide track";
|
|
||||||
|
|
||||||
impl<'a> ArrangerView<'a> {
|
impl<'a> ArrangerView<'a> {
|
||||||
pub fn new (app: &'a App, vertical: bool) -> Self {
|
pub fn new (app: &'a App, vertical: bool) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -39,12 +37,9 @@ impl<'a> Render for ArrangerView<'a> {
|
||||||
} else {
|
} else {
|
||||||
self.draw_horizontal(buf, area)
|
self.draw_horizontal(buf, area)
|
||||||
}?;
|
}?;
|
||||||
if self.focused {
|
if self.focused && self.entered {
|
||||||
//HELP.blit(buf, area.x + 2, area.y + area.height - 1, Some(Style::default().dim()))?;
|
|
||||||
if self.entered {
|
|
||||||
Corners(Style::default().green().not_dim()).draw(buf, area)?;
|
Corners(Style::default().green().not_dim()).draw(buf, area)?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(area)
|
Ok(area)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +57,7 @@ impl<'a> ArrangerView<'a> {
|
||||||
if y + 2 * scene_index as u16 >= height {
|
if y + 2 * scene_index as u16 >= height {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
let style = Some(highlight(
|
let style = Some(Nord::style_hi(
|
||||||
self.focused,
|
self.focused,
|
||||||
(0 == self.cursor.0) && (scene_index + 1 == self.cursor.1)
|
(0 == self.cursor.0) && (scene_index + 1 == self.cursor.1)
|
||||||
).bold());
|
).bold());
|
||||||
|
|
@ -82,7 +77,7 @@ impl<'a> ArrangerView<'a> {
|
||||||
if x >= width {
|
if x >= width {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
let mut width = 16u16;
|
let width = 16u16;
|
||||||
track.name.blit(buf, x, y, Some(Style::default().bold()))?;
|
track.name.blit(buf, x, y, Some(Style::default().bold()))?;
|
||||||
for (scene_index, scene) in self.scenes.iter().enumerate() {
|
for (scene_index, scene) in self.scenes.iter().enumerate() {
|
||||||
if y + 2 * scene_index as u16 >= height {
|
if y + 2 * scene_index as u16 >= height {
|
||||||
|
|
@ -90,11 +85,8 @@ impl<'a> ArrangerView<'a> {
|
||||||
}
|
}
|
||||||
let label = if let Some(Some(clip)) = scene.clips.get(track_index) {
|
let label = if let Some(Some(clip)) = scene.clips.get(track_index) {
|
||||||
if let Some(phrase) = track.phrases.get(*clip) {
|
if let Some(phrase) = track.phrases.get(*clip) {
|
||||||
format!("{} {}", if track.sequence == Some(*clip) {
|
let icon = match track.sequence { Some(_) => "", None => "┊" };
|
||||||
""
|
format!("{icon} {}", phrase.name)
|
||||||
} else {
|
|
||||||
"┊"
|
|
||||||
}, phrase.name)
|
|
||||||
} else {
|
} else {
|
||||||
format!(" ??? ")
|
format!(" ??? ")
|
||||||
}
|
}
|
||||||
|
|
@ -102,12 +94,11 @@ impl<'a> ArrangerView<'a> {
|
||||||
format!("┊ ········")
|
format!("┊ ········")
|
||||||
};
|
};
|
||||||
let hi = (track_index + 1 == self.cursor.0) && (scene_index + 1 == self.cursor.1);
|
let hi = (track_index + 1 == self.cursor.0) && (scene_index + 1 == self.cursor.1);
|
||||||
let style = Some(highlight(self.focused, hi));
|
let style = Some(Nord::style_hi(self.focused, hi));
|
||||||
let y = 1 + y + 2 * scene_index as u16;
|
let y = 1 + y + 2 * scene_index as u16;
|
||||||
"┊".blit(buf, x, y, Some(Style::default().dim()))?;
|
"┊".blit(buf, x, y, Some(Style::default().dim()))?;
|
||||||
"┊".blit(buf, x, y + 1, Some(Style::default().dim()))?;
|
"┊".blit(buf, x, y + 1, Some(Style::default().dim()))?;
|
||||||
label.blit(buf, x, y, style)?;
|
label.blit(buf, x, y, style)?;
|
||||||
//width = width.max(2label.len() as u16 + 3);
|
|
||||||
}
|
}
|
||||||
if track_index + 1 == self.cursor.0 {
|
if track_index + 1 == self.cursor.0 {
|
||||||
let bg = Nord::bg_hi(self.focused, self.entered);
|
let bg = Nord::bg_hi(self.focused, self.entered);
|
||||||
|
|
@ -305,9 +296,7 @@ impl<'a> ArrangerView<'a> {
|
||||||
x3 = x3.max(label.len() as u16)
|
x3 = x3.max(label.len() as u16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x2 = x2 + x3;
|
x2 = x2 + x3 + 1;
|
||||||
|
|
||||||
x2 = x2 + 1;
|
|
||||||
}
|
}
|
||||||
Ok(Rect { x, y, height, width: x2 })
|
Ok(Rect { x, y, height, width: x2 })
|
||||||
},
|
},
|
||||||
|
|
@ -315,18 +304,6 @@ impl<'a> ArrangerView<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn highlight (focused: bool, highlight: bool) -> Style {
|
|
||||||
if highlight {
|
|
||||||
if focused {
|
|
||||||
Style::default().yellow().not_dim()
|
|
||||||
} else {
|
|
||||||
Style::default().yellow().dim()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Style::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//use crate::core::*;
|
//use crate::core::*;
|
||||||
//use crate::view::*;
|
//use crate::view::*;
|
||||||
//use crate::model::*;
|
//use crate::model::*;
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,8 @@ impl<'a> SequencerView<'a> {
|
||||||
phrase: app.phrase(),
|
phrase: app.phrase(),
|
||||||
focused: app.section == AppSection::Sequencer,
|
focused: app.section == AppSection::Sequencer,
|
||||||
entered: app.entered,
|
entered: app.entered,
|
||||||
ppq: app.timebase.ppq() as usize,
|
ppq: app.transport.ppq(),
|
||||||
now: app.timebase.frame_to_pulse(app.playhead as f64) as usize,
|
now: app.transport.pulse(),
|
||||||
time_cursor: app.time_cursor,
|
time_cursor: app.time_cursor,
|
||||||
time_start: app.seq_buf.time_start,
|
time_start: app.seq_buf.time_start,
|
||||||
time_zoom: app.seq_buf.time_zoom,
|
time_zoom: app.seq_buf.time_zoom,
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,16 @@ pub trait Theme {
|
||||||
Color::Reset
|
Color::Reset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn style_hi (focused: bool, highlight: bool) -> Style {
|
||||||
|
if highlight && focused {
|
||||||
|
Style::default().yellow().not_dim()
|
||||||
|
} else if highlight {
|
||||||
|
Style::default().yellow().dim()
|
||||||
|
} else {
|
||||||
|
Style::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Nord;
|
pub struct Nord;
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,33 @@
|
||||||
use crate::{core::*,view::*,model::{App, AppSection}};
|
use crate::{core::*,view::*,model::*};
|
||||||
pub struct TransportView {
|
|
||||||
focused: bool,
|
|
||||||
entered: bool,
|
|
||||||
playing: TransportState,
|
|
||||||
quant: usize,
|
|
||||||
ppq: usize,
|
|
||||||
bpm: usize,
|
|
||||||
pulse: usize,
|
|
||||||
usecs: usize,
|
|
||||||
}
|
|
||||||
impl TransportView {
|
|
||||||
pub fn new (app: &App) -> Self {
|
|
||||||
Self {
|
|
||||||
focused: app.section == AppSection::Transport,
|
|
||||||
entered: app.entered,
|
|
||||||
playing: *app.playing.as_ref().unwrap_or(&TransportState::Stopped),
|
|
||||||
quant: app.quant,
|
|
||||||
ppq: app.timebase.ppq() as usize,
|
|
||||||
bpm: app.timebase.bpm() as usize,
|
|
||||||
pulse: app.timebase.frame_to_pulse(app.playhead as f64) as usize,
|
|
||||||
usecs: app.timebase.frame_to_usec(app.playhead as f64) as usize,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
render!(TransportView |self, buf, area| {
|
|
||||||
let mut area = area;
|
|
||||||
area.height = 2;
|
|
||||||
let Self { ppq, bpm, quant, pulse, usecs, .. } = self;
|
|
||||||
|
|
||||||
fill_bg(buf, area, Nord::bg_lo(self.focused, self.entered));
|
|
||||||
|
|
||||||
|
render!(TransportToolbar |self, buf, area| {
|
||||||
let gray = Style::default().gray();
|
let gray = Style::default().gray();
|
||||||
let not_dim = Style::default().not_dim();
|
let not_dim = Style::default().not_dim();
|
||||||
let not_dim_bold = not_dim.bold();
|
let not_dim_bold = not_dim.bold();
|
||||||
|
|
||||||
|
let mut area = area;
|
||||||
|
area.height = 2;
|
||||||
|
let ppq = self.ppq();
|
||||||
|
let bpm = self.bpm();
|
||||||
|
let pulse = self.pulse();
|
||||||
|
let usecs = self.usecs();
|
||||||
|
let Self { quant, focused, entered, .. } = self;
|
||||||
|
fill_bg(buf, area, Nord::bg_lo(*focused, *entered));
|
||||||
let area = Split::right([
|
let area = Split::right([
|
||||||
|
|
||||||
// Play/Pause button
|
// Play/Pause button
|
||||||
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
|
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
|
||||||
let style = Some(match &self.playing {
|
let style = Some(match self.playing {
|
||||||
TransportState::Stopped => gray.dim().bold(),
|
Some(TransportState::Stopped) => gray.dim().bold(),
|
||||||
TransportState::Starting => gray.not_dim().bold(),
|
Some(TransportState::Starting) => gray.not_dim().bold(),
|
||||||
TransportState::Rolling => gray.not_dim().white().bold()
|
Some(TransportState::Rolling) => gray.not_dim().white().bold(),
|
||||||
|
_ => unreachable!(),
|
||||||
});
|
});
|
||||||
let label = match &self.playing {
|
let label = match self.playing {
|
||||||
TransportState::Rolling => "▶ PLAYING",
|
Some(TransportState::Rolling) => "▶ PLAYING",
|
||||||
TransportState::Starting => "READY ...",
|
Some(TransportState::Starting) => "READY ...",
|
||||||
TransportState::Stopped => "⏹ STOPPED",
|
Some(TransportState::Stopped) => "⏹ STOPPED",
|
||||||
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let mut result = label.blit(buf, x + 1, y, style)?;
|
let mut result = label.blit(buf, x + 1, y, style)?;
|
||||||
result.width = result.width + 1;
|
result.width = result.width + 1;
|
||||||
|
|
@ -86,7 +67,7 @@ render!(TransportView |self, buf, area| {
|
||||||
|
|
||||||
]).render(buf, area)?;
|
]).render(buf, area)?;
|
||||||
|
|
||||||
Ok(if self.focused && self.entered {
|
Ok(if *focused && *entered {
|
||||||
Corners(Style::default().green().not_dim()).draw(buf, area)?
|
Corners(Style::default().green().not_dim()).draw(buf, area)?
|
||||||
} else {
|
} else {
|
||||||
area
|
area
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue