add Justfile and tweak things

This commit is contained in:
🪞👃🪞 2024-07-13 16:26:27 +03:00
parent a017d2ca51
commit f347ca838b
5 changed files with 95 additions and 86 deletions

6
Justfile Normal file
View file

@ -0,0 +1,6 @@
default:
just -l
status:
cargo c
cloc --by-file src/
git status

View file

@ -17,8 +17,8 @@ use crate::{core::*, model::*};
/// Application entrypoint.
pub fn main () -> Usually<()> {
run(App::from_edn(include_str!("../demos/project.edn"))?.activate(Some(|app: &Arc<RwLock<App>>| {
run(App::from_edn(include_str!("../demos/project.edn"))?
.activate(Some(|app: &Arc<RwLock<App>>|Ok({
let (midi_in, mut midi_outs) = {
let app = app.read().unwrap();
let jack = app.jack.as_ref().unwrap();
@ -28,12 +28,12 @@ pub fn main () -> Usually<()> {
.collect::<Vec<_>>();
(midi_in, midi_outs)
};
{
let mut app = app.write().unwrap();
let jack = app.jack.as_ref().unwrap();
for name in app.midi_ins.iter() {
for port in jack.client().ports(Some(name), None, PortFlags::empty()).iter() {
let ports = jack.client().ports(Some(name), None, PortFlags::empty());
for port in ports.iter() {
if let Some(port) = jack.client().port_by_name(port) {
jack.client().connect_ports(&port, &midi_in)?;
}
@ -47,10 +47,7 @@ pub fn main () -> Usually<()> {
track.connect_first_device()?;
track.connect_last_device(&app)?;
}
}
Ok(())
}))?)?;
};
})))?)?;
Ok(())
}

View file

@ -6,6 +6,16 @@ use crate::{core::*, view::*};
/// Root of application state.
pub struct App {
/// Optional modal dialog
pub modal: Option<Box<dyn Exit>>,
/// Whether the currently focused section has input priority
pub entered: bool,
/// Currently focused section
pub section: AppFocus,
/// Transport model and view.
pub transport: TransportToolbar,
/// Arraneger model and view.
pub arranger: Arranger,
/// Main JACK client.
pub jack: Option<JackClient>,
/// Map of external MIDI outs in the jack graph
@ -15,32 +25,23 @@ pub struct App {
pub midi_ins: Vec<String>,
/// Display mode of chain section
pub chain_mode: bool,
/// Display mode of sequencer seciton
pub seq_mode: bool,
/// Display buffer for sequencer
pub seq_buf: BufferedSequencerView,
/// Optional modal dialog
pub modal: Option<Box<dyn Exit>>,
/// Display position of cursor within note range
pub note_cursor: usize,
/// Range of notes to display
pub note_start: usize,
/// Display position of cursor within time range
pub time_cursor: usize,
/// Paths to user directories
xdg: Option<Arc<XdgApp>>,
/// Main audio outputs.
pub audio_outs: Vec<Arc<Port<Unowned>>>,
/// Number of frames requested by process callback
chunk_size: usize,
/// Transport model and view.
pub transport: TransportToolbar,
/// Arraneger model and view.
pub arranger: Arranger,
/// Currently focused section
pub section: AppFocus,
/// Whether the current focus section has input priority
pub entered: bool,
/// Display mode of sequencer seciton
pub seq_mode: bool,
/// Display buffer for sequencer
pub seq_buf: BufferedSequencerView,
/// Display position of cursor within note range
pub note_cursor: usize,
/// Range of notes to display
pub note_start: usize,
/// Display position of cursor within time range
pub time_cursor: usize,
}
impl App {
@ -49,25 +50,27 @@ impl App {
let first_run = crate::config::AppPaths::new(&xdg)?.should_create();
let jack = JackClient::Inactive(Client::new("tek", ClientOptions::NO_START_SERVER)?.0);
Ok(Self {
modal: first_run.then(||{
Exit::boxed(crate::config::SetupModal(Some(xdg.clone()), false))
}),
entered: true,
section: AppFocus::default(),
transport: TransportToolbar::new(Some(jack.transport())),
arranger: Arranger::new(),
jack: Some(jack),
audio_outs: vec![],
chain_mode: false,
chunk_size: 0,
entered: true,
jack: Some(jack),
midi_in: None,
midi_ins: vec![],
note_cursor: 0,
note_start: 2,
section: AppFocus::default(),
xdg: Some(xdg),
seq_mode: false,
seq_buf: BufferedSequencerView::new(96, 16384),
note_cursor: 0,
note_start: 2,
time_cursor: 0,
modal: first_run.then(
||Exit::boxed(crate::config::SetupModal(Some(xdg.clone()), false))
),
xdg: Some(xdg),
})
}
}
@ -133,9 +136,13 @@ impl App {
/// Different sections of the UI that may be focused.
#[derive(PartialEq, Clone, Copy)]
pub enum AppFocus {
/// The transport is selected.
Transport,
/// The arranger is selected.
Arranger,
/// The sequencer is selected.
Sequencer,
/// The device chain is selected.
Chain,
}

View file

@ -22,8 +22,7 @@ pub struct Track {
/// Device selector
pub device: usize,
/// Send all notes off
/// FIXME: Some(nframes)?
pub reset: bool,
pub reset: bool, // TODO?: after Some(nframes)
/// Highlight keys on piano roll.
pub notes_in: [bool;128],
/// Highlight keys on piano roll.

View file

@ -1,12 +1,12 @@
use crate::{core::*,view::*,model::*};
render!(TransportToolbar |self, buf, area| {
let mut area = area;
area.height = 2;
let gray = Style::default().gray();
let not_dim = Style::default().not_dim();
let not_dim_bold = not_dim.bold();
let mut area = area;
area.height = 2;
let corners = Corners(Style::default().green().not_dim());
let ppq = self.ppq();
let bpm = self.bpm();
let pulse = self.pulse();
@ -40,7 +40,7 @@ render!(TransportToolbar |self, buf, area| {
let width = format!("{}.{:03}", bpm, bpm % 1).blit(buf, x, y + 1, Some(not_dim_bold))?.width;
let area = Rect { x, y, width: (width + 2).max(10), height: 2 };
if self.focused && self.entered && self.selected == TransportFocus::BPM {
Corners(Style::default().green().not_dim()).draw(buf, Rect { x: area.x - 1, ..area })?;
corners.draw(buf, Rect { x: area.x - 1, ..area })?;
}
Ok(area)
},
@ -51,7 +51,7 @@ render!(TransportToolbar |self, buf, area| {
let width = ppq_to_name(*quant).blit(buf, x, y + 1, Some(not_dim_bold))?.width;
let area = Rect { x, y, width: (width + 2).max(10), height: 2 };
if self.focused && self.entered && self.selected == TransportFocus::Quant {
Corners(Style::default().green().not_dim()).draw(buf, Rect { x: area.x - 1, ..area })?;
corners.draw(buf, Rect { x: area.x - 1, ..area })?;
}
Ok(area)
},
@ -62,7 +62,7 @@ render!(TransportToolbar |self, buf, area| {
let width = ppq_to_name(*sync).blit(buf, x, y + 1, Some(not_dim_bold))?.width;
let area = Rect { x, y, width: (width + 2).max(10), height: 2 };
if self.focused && self.entered && self.selected == TransportFocus::Sync {
Corners(Style::default().green().not_dim()).draw(buf, Rect { x: area.x - 1, ..area })?;
corners.draw(buf, Rect { x: area.x - 1, ..area })?;
}
Ok(area)
},