mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
placebo
This commit is contained in:
parent
3ae2467acc
commit
94c1f83ef2
13 changed files with 277 additions and 124 deletions
|
|
@ -46,10 +46,6 @@ impl<T: PortList + Send + Sync + 'static> PortList for DynamicDevice<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DynamicAsyncClient = AsyncClient<DynamicNotifications, DynamicProcessHandler>;
|
|
||||||
type DynamicNotifications = Notifications<Box<dyn Fn(AppEvent) + Send + Sync>>;
|
|
||||||
type DynamicProcessHandler = ClosureProcessHandler<BoxedProcessHandler>;
|
|
||||||
|
|
||||||
impl<T: Send + Sync + 'static> DynamicDevice<T> {
|
impl<T: Send + Sync + 'static> DynamicDevice<T> {
|
||||||
pub fn new <'a, R, H, P> (render: R, handle: H, process: P, state: T) -> Self where
|
pub fn new <'a, R, H, P> (render: R, handle: H, process: P, state: T) -> Self where
|
||||||
R: FnMut(&T, &mut Buffer, Rect) -> Usually<Rect> + Send + 'static,
|
R: FnMut(&T, &mut Buffer, Rect) -> Usually<Rect> + Send + 'static,
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,37 @@
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
|
|
||||||
pub type BoxedNotificationHandler =
|
pub trait Process {
|
||||||
Box<dyn Fn(AppEvent) + Send>;
|
fn process (&mut self, c: &Client, s: &ProcessScope) -> Control;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type DynamicAsyncClient =
|
||||||
|
AsyncClient<DynamicNotifications, DynamicProcessHandler>;
|
||||||
|
|
||||||
|
pub type DynamicNotifications =
|
||||||
|
Notifications<Box<dyn Fn(AppEvent) + Send + Sync>>;
|
||||||
|
|
||||||
|
pub type DynamicProcessHandler =
|
||||||
|
ClosureProcessHandler<BoxedProcessHandler>;
|
||||||
|
|
||||||
pub type BoxedProcessHandler =
|
pub type BoxedProcessHandler =
|
||||||
Box<dyn FnMut(&Client, &ProcessScope)-> Control + Send>;
|
Box<dyn FnMut(&Client, &ProcessScope)-> Control + Send>;
|
||||||
|
|
||||||
pub type Jack<N> =
|
pub fn jack_run <T> (name: &str, app: &Arc<Mutex<T>>) -> Usually<DynamicAsyncClient>
|
||||||
AsyncClient<N, ClosureProcessHandler<BoxedProcessHandler>>;
|
where T: Handle + Process + Send + 'static
|
||||||
|
{
|
||||||
|
let options = ClientOptions::NO_START_SERVER;
|
||||||
|
let (client, _status) = Client::new(name, options)?;
|
||||||
|
Ok(client.activate_async(
|
||||||
|
Notifications(Box::new({
|
||||||
|
let app = app.clone();
|
||||||
|
move|event|{app.lock().unwrap().handle(&event).unwrap();}
|
||||||
|
}) as Box<dyn Fn(AppEvent) + Send + Sync>),
|
||||||
|
ClosureProcessHandler::new(Box::new({
|
||||||
|
let app = app.clone();
|
||||||
|
move|c: &Client, s: &ProcessScope|{app.lock().unwrap().process(c, s)}
|
||||||
|
}) as BoxedProcessHandler)
|
||||||
|
)?)
|
||||||
|
}
|
||||||
|
|
||||||
pub use ::jack::{
|
pub use ::jack::{
|
||||||
AsyncClient,
|
AsyncClient,
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,20 @@
|
||||||
pub type Usually<T> = Result<T, Box<dyn Error>>;
|
|
||||||
|
|
||||||
macro_rules! submod {
|
|
||||||
($($name:ident)*) => { $(mod $name; pub use self::$name::*;)* };
|
|
||||||
}
|
|
||||||
|
|
||||||
submod!( device handle jack keymap port render run time );
|
|
||||||
|
|
||||||
pub use std::error::Error;
|
pub use std::error::Error;
|
||||||
pub use std::io::{stdout, Stdout, Write};
|
pub use std::io::{stdout, Stdout, Write};
|
||||||
pub use std::thread::{spawn, JoinHandle};
|
pub use std::thread::{spawn, JoinHandle};
|
||||||
pub use std::time::Duration;
|
pub use std::time::Duration;
|
||||||
pub use std::collections::BTreeMap;
|
pub use std::collections::BTreeMap;
|
||||||
pub use std::sync::{
|
pub use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
Arc, Mutex, MutexGuard,
|
pub use std::sync::atomic::{Ordering, AtomicBool, AtomicUsize};
|
||||||
atomic::{Ordering, AtomicBool, AtomicUsize},
|
pub use std::sync::mpsc::{channel, Sender, Receiver};
|
||||||
mpsc::{self, channel, Sender, Receiver}
|
pub use ratatui::prelude::*;
|
||||||
};
|
pub use midly::{MidiMessage, live::LiveEvent, num::u7};
|
||||||
|
pub use crossterm::{ExecutableCommand, QueueableCommand};
|
||||||
|
pub use crossterm::event::{Event, KeyEvent, KeyCode, KeyModifiers};
|
||||||
|
|
||||||
pub use ::crossterm::{
|
macro_rules! submod { ($($name:ident)*) => { $(mod $name; pub use self::$name::*;)* }; }
|
||||||
ExecutableCommand, QueueableCommand,
|
|
||||||
event::{Event, KeyEvent, KeyCode, KeyModifiers},
|
submod!( device handle jack keymap port render run time );
|
||||||
terminal::{
|
|
||||||
self,
|
pub type Usually<T> = Result<T, Box<dyn Error>>;
|
||||||
Clear, ClearType,
|
|
||||||
EnterAlternateScreen, LeaveAlternateScreen,
|
|
||||||
enable_raw_mode, disable_raw_mode
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub use ::ratatui::prelude::*;
|
|
||||||
pub use ::midly::{MidiMessage, live::LiveEvent, num::u7};
|
|
||||||
pub use crate::{key, keymap};
|
pub use crate::{key, keymap};
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,16 @@ pub trait Render {
|
||||||
fn max_height (&self) -> u16 {
|
fn max_height (&self) -> u16 {
|
||||||
u16::MAX
|
u16::MAX
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fn boxed (self) -> Box<dyn Render> where Self: Sized + 'static {
|
||||||
|
//Box::new(self)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Fn(&mut Buffer, Rect) -> Usually<Rect>> Render for T {
|
||||||
|
fn render (&self, b: &mut Buffer, a: Rect) -> Usually<Rect> {
|
||||||
|
(*self).render(b, a)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for Box<dyn Device> {
|
impl Render for Box<dyn Device> {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,21 @@
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
|
use crossterm::terminal::{
|
||||||
|
EnterAlternateScreen, LeaveAlternateScreen,
|
||||||
|
enable_raw_mode, disable_raw_mode
|
||||||
|
};
|
||||||
|
|
||||||
pub trait Run: Render + Handle + Send + Sized + 'static {
|
pub trait Run: Render + Handle + Send + Sized + 'static {
|
||||||
fn run (self) -> Usually<()> {
|
fn run (self, callback: Option<impl FnOnce(Arc<Mutex<Self>>)->Usually<()>>) -> Usually<()> {
|
||||||
let device = Arc::new(Mutex::new(self));
|
let device = Arc::new(Mutex::new(self));
|
||||||
let exited = Arc::new(AtomicBool::new(false));
|
let exited = Arc::new(AtomicBool::new(false));
|
||||||
let _input_thread = input_thread(&exited, &device);
|
let _input_thread = input_thread(&exited, &device);
|
||||||
terminal_setup()?;
|
terminal_setup()?;
|
||||||
panic_hook_setup();
|
panic_hook_setup();
|
||||||
main_thread(&exited, &device)?;
|
let main_thread = main_thread(&exited, &device)?;
|
||||||
|
if let Some(callback) = callback {
|
||||||
|
callback(device);
|
||||||
|
}
|
||||||
|
main_thread.join();
|
||||||
terminal_teardown()?;
|
terminal_teardown()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -67,12 +75,13 @@ pub fn panic_hook_setup () {
|
||||||
/// Main thread render loop
|
/// Main thread render loop
|
||||||
pub fn main_thread (
|
pub fn main_thread (
|
||||||
exited: &Arc<AtomicBool>,
|
exited: &Arc<AtomicBool>,
|
||||||
device: &Arc<Mutex<impl Render>>
|
device: &Arc<Mutex<impl Render + Send + 'static>>
|
||||||
) -> Usually<()> {
|
) -> Usually<JoinHandle<()>> {
|
||||||
let exited = exited.clone();
|
let exited = exited.clone();
|
||||||
|
let device = device.clone();
|
||||||
let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout()))?;
|
let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout()))?;
|
||||||
let sleep = std::time::Duration::from_millis(16);
|
let sleep = std::time::Duration::from_millis(16);
|
||||||
loop {
|
Ok(spawn(move || loop {
|
||||||
|
|
||||||
terminal.draw(|frame|{
|
terminal.draw(|frame|{
|
||||||
let area = frame.size();
|
let area = frame.size();
|
||||||
|
|
@ -86,8 +95,7 @@ pub fn main_thread (
|
||||||
|
|
||||||
std::thread::sleep(sleep);
|
std::thread::sleep(sleep);
|
||||||
|
|
||||||
}
|
}))
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
/// Cleanup
|
/// Cleanup
|
||||||
pub fn terminal_teardown () -> Usually<()> {
|
pub fn terminal_teardown () -> Usually<()> {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Timebase {
|
pub struct Timebase {
|
||||||
/// Frames per second
|
/// Frames per second
|
||||||
pub rate: ::atomic_float::AtomicF64,
|
pub rate: ::atomic_float::AtomicF64,
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,36 @@
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
pub struct LauncherGrid<'a> {
|
pub struct SceneGrid<'a> {
|
||||||
state: &'a Launcher,
|
pub buf: &'a mut Buffer,
|
||||||
|
pub area: Rect,
|
||||||
|
pub name: &'a str,
|
||||||
|
pub focused: bool,
|
||||||
|
pub scenes: &'a[Scene],
|
||||||
|
pub tracks: &'a[Track],
|
||||||
|
pub cursor: &'a(usize, usize),
|
||||||
|
}
|
||||||
|
impl<'a> SceneGrid<'a> {
|
||||||
|
pub fn new (
|
||||||
buf: &'a mut Buffer,
|
buf: &'a mut Buffer,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
|
name: &'a str,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
|
scenes: &'a[Scene],
|
||||||
|
tracks: &'a[Track],
|
||||||
|
cursor: &'a(usize, usize),
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
buf,
|
||||||
|
area,
|
||||||
|
name,
|
||||||
|
focused,
|
||||||
|
scenes,
|
||||||
|
tracks,
|
||||||
|
cursor,
|
||||||
}
|
}
|
||||||
impl<'a> LauncherGrid<'a> {
|
|
||||||
pub fn new (state: &'a Launcher, buf: &'a mut Buffer, area: Rect, focused: bool) -> Self {
|
|
||||||
Self { state, buf, area, focused }
|
|
||||||
}
|
}
|
||||||
pub fn draw (&mut self) -> Usually<Rect> {
|
pub fn draw (&mut self) -> Usually<Rect> {
|
||||||
self.area.height = self.state.scenes.len() as u16 + 2;
|
self.area.height = self.scenes.len() as u16 + 2;
|
||||||
let style = Some(Style::default().green().dim());
|
let style = Some(Style::default().green().dim());
|
||||||
if self.focused {
|
if self.focused {
|
||||||
let Rect { x, y, width, height } = self.area;
|
let Rect { x, y, width, height } = self.area;
|
||||||
|
|
@ -24,9 +43,9 @@ impl<'a> LauncherGrid<'a> {
|
||||||
if x >= self.area.x + self.area.width {
|
if x >= self.area.x + self.area.width {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
self.separator_v(x, i == self.state.cursor.0);
|
self.separator_v(x, i == self.cursor.0);
|
||||||
x = x + w;
|
x = x + w;
|
||||||
self.separator_v(x, i == self.state.cursor.0);
|
self.separator_v(x, i == self.cursor.0);
|
||||||
}
|
}
|
||||||
let (mut x, y) = (self.area.x, self.area.y);
|
let (mut x, y) = (self.area.x, self.area.y);
|
||||||
for (i, title) in columns.iter().enumerate() {
|
for (i, title) in columns.iter().enumerate() {
|
||||||
|
|
@ -34,7 +53,7 @@ impl<'a> LauncherGrid<'a> {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
title.blit(
|
title.blit(
|
||||||
self.buf, x+1, y, Some(self.highlight(i == self.state.cursor.0).bold())
|
self.buf, x+1, y, Some(self.highlight(i == self.cursor.0).bold())
|
||||||
);
|
);
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
self.scenes(x+1, y + 1);
|
self.scenes(x+1, y + 1);
|
||||||
|
|
@ -49,8 +68,8 @@ impl<'a> LauncherGrid<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_names (&self) -> Vec<&'a str> {
|
fn column_names (&self) -> Vec<&'a str> {
|
||||||
let mut column_names = vec![self.state.name.as_str()];
|
let mut column_names = vec![self.name];
|
||||||
for track in self.state.tracks.iter() {
|
for track in self.tracks.iter() {
|
||||||
column_names.push(track.name.as_str());
|
column_names.push(track.name.as_str());
|
||||||
}
|
}
|
||||||
column_names
|
column_names
|
||||||
|
|
@ -63,23 +82,23 @@ impl<'a> LauncherGrid<'a> {
|
||||||
fn scenes (&mut self, x: u16, y: u16) -> u16 {
|
fn scenes (&mut self, x: u16, y: u16) -> u16 {
|
||||||
let mut index = 0usize;
|
let mut index = 0usize;
|
||||||
loop {
|
loop {
|
||||||
if index >= self.state.scenes.len() {
|
if index >= self.scenes.len() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if y + index as u16 >= self.area.height {
|
if y + index as u16 >= self.area.height {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if let Some(scene) = self.state.scenes.get(index) {
|
if let Some(scene) = self.scenes.get(index) {
|
||||||
let style = Some(self.highlight(
|
let style = Some(self.highlight(
|
||||||
(0 == self.state.cursor.0) && (index + 1 == self.state.cursor.1)
|
(0 == self.cursor.0) && (index + 1 == self.cursor.1)
|
||||||
).bold());
|
).bold());
|
||||||
"⯈".blit(self.buf, x, y + index as u16, style);
|
"⯈".blit(self.buf, x, y + index as u16, style);
|
||||||
scene.name.blit(self.buf, x+1, y + index as u16, style);
|
scene.name.blit(self.buf, x+1, y + index as u16, style);
|
||||||
}
|
}
|
||||||
index = index + 1;
|
index = index + 1;
|
||||||
}
|
}
|
||||||
let hi = (0 == self.state.cursor.0) &&
|
let hi = (0 == self.cursor.0) &&
|
||||||
(self.state.scenes.len() + 1 == self.state.cursor.1);
|
(self.scenes.len() + 1 == self.cursor.1);
|
||||||
"+Add scene…".blit(self.buf, x, y + index as u16, Some(if hi {
|
"+Add scene…".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||||
self.highlight(true)
|
self.highlight(true)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -91,20 +110,20 @@ impl<'a> LauncherGrid<'a> {
|
||||||
fn clips (&mut self, x: u16, y: u16, track: usize) -> u16 {
|
fn clips (&mut self, x: u16, y: u16, track: usize) -> u16 {
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
loop {
|
loop {
|
||||||
if index >= self.state.scenes.len() {
|
if index >= self.scenes.len() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if y + index as u16 >= self.area.height {
|
if y + index as u16 >= self.area.height {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if let Some(scene) = self.state.scenes.get(index) {
|
if let Some(scene) = self.scenes.get(index) {
|
||||||
let hi = (track + 1 == self.state.cursor.0) &&
|
let hi = (track + 1 == self.cursor.0) &&
|
||||||
(index + 1 == self.state.cursor.1);
|
(index + 1 == self.cursor.1);
|
||||||
let style = Some(self.highlight(hi));
|
let style = Some(self.highlight(hi));
|
||||||
let clip = scene.clips.get(track);
|
let clip = scene.clips.get(track);
|
||||||
let index = index as u16;
|
let index = index as u16;
|
||||||
let label = if let Some(Some(clip)) = clip {
|
let label = if let Some(Some(clip)) = clip {
|
||||||
let track = self.state.tracks[track].sequencer.state();
|
let track = self.tracks[track].sequencer.state();
|
||||||
let phrase = track.phrases.get(*clip);
|
let phrase = track.phrases.get(*clip);
|
||||||
if let Some(phrase) = phrase {
|
if let Some(phrase) = phrase {
|
||||||
format!("⯈{}", phrase.name)
|
format!("⯈{}", phrase.name)
|
||||||
|
|
@ -118,8 +137,8 @@ impl<'a> LauncherGrid<'a> {
|
||||||
}
|
}
|
||||||
index = index + 1;
|
index = index + 1;
|
||||||
}
|
}
|
||||||
let hi = (track + 1 == self.state.cursor.0) &&
|
let hi = (track + 1 == self.cursor.0) &&
|
||||||
(self.state.scenes.len() + 1 == self.state.cursor.1);
|
(self.scenes.len() + 1 == self.cursor.1);
|
||||||
" + Add clip".blit(self.buf, x, y + index as u16, Some(if hi {
|
" + Add clip".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||||
self.highlight(true)
|
self.highlight(true)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
use crate::layout::*;
|
use crate::layout::*;
|
||||||
use crate::device::*;
|
use crate::device::*;
|
||||||
mod grid;
|
mod grid; pub use self::grid::*;
|
||||||
pub use self::grid::*; mod handle;
|
mod handle; pub use self::handle::*;
|
||||||
pub use self::handle::*;
|
mod scene; pub use self::scene::*;
|
||||||
pub struct Launcher {
|
pub struct Launcher {
|
||||||
name: String,
|
name: String,
|
||||||
timebase: Arc<Timebase>,
|
timebase: Arc<Timebase>,
|
||||||
|
|
@ -20,28 +20,6 @@ pub struct Launcher {
|
||||||
view: LauncherView,
|
view: LauncherView,
|
||||||
modal: Option<Box<dyn Modal<Self>>>,
|
modal: Option<Box<dyn Modal<Self>>>,
|
||||||
}
|
}
|
||||||
pub enum LauncherView {
|
|
||||||
Tracks,
|
|
||||||
Sequencer,
|
|
||||||
Chains
|
|
||||||
}
|
|
||||||
impl LauncherView {
|
|
||||||
fn is_tracks (&self) -> bool {
|
|
||||||
match self { Self::Tracks => true, _ => false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub struct Scene {
|
|
||||||
name: String,
|
|
||||||
clips: Vec<Option<usize>>,
|
|
||||||
}
|
|
||||||
impl Scene {
|
|
||||||
pub fn new (name: impl AsRef<str>, clips: impl AsRef<[Option<usize>]>) -> Self {
|
|
||||||
Self {
|
|
||||||
name: name.as_ref().into(),
|
|
||||||
clips: clips.as_ref().iter().map(|x|x.clone()).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Launcher {
|
impl Launcher {
|
||||||
pub fn new (
|
pub fn new (
|
||||||
name: &str,
|
name: &str,
|
||||||
|
|
@ -144,7 +122,7 @@ impl Launcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl DynamicDevice<Launcher> {
|
impl DynamicDevice<Launcher> {
|
||||||
pub fn connect (self, midi_in: &str, audio_outs: &[&str]) -> Usually<Self> {
|
pub fn connect (&self, midi_in: &str, audio_outs: &[&str]) -> Usually<&Self> {
|
||||||
{
|
{
|
||||||
let state = &self.state();
|
let state = &self.state();
|
||||||
let (client, _status) = Client::new(
|
let (client, _status) = Client::new(
|
||||||
|
|
@ -197,16 +175,26 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
|
||||||
frame: state.current_frame
|
frame: state.current_frame
|
||||||
}.render(buf, area)?.height;
|
}.render(buf, area)?.height;
|
||||||
|
|
||||||
y = y + LauncherGrid::new(
|
y = y + crate::device::launcher::SceneGrid {
|
||||||
state, buf, Rect { x, y, width, height: height/3 }, state.view.is_tracks()
|
buf,
|
||||||
).draw()?.height;
|
area: Rect { x, y, width, height },
|
||||||
|
name: &state.name,
|
||||||
|
focused: state.view.is_tracks(),
|
||||||
|
scenes: &state.scenes,
|
||||||
|
tracks: &state.tracks,
|
||||||
|
cursor: &state.cursor
|
||||||
|
}.draw()?.height;
|
||||||
|
|
||||||
y = y + draw_section_chains(
|
y = y + draw_section_chains(
|
||||||
state, buf, Rect { x, y, width, height: height/3 }
|
state,
|
||||||
|
buf,
|
||||||
|
Rect { x, y, width, height: height/3 }
|
||||||
)?.height;
|
)?.height;
|
||||||
|
|
||||||
y = y + draw_section_sequencer(
|
y = y + draw_section_sequencer(
|
||||||
state, buf, Rect { x, y, width, height: height - y }
|
state,
|
||||||
|
buf,
|
||||||
|
Rect { x, y, width, height: height - y }
|
||||||
)?.height;
|
)?.height;
|
||||||
|
|
||||||
area.height = y;
|
area.height = y;
|
||||||
|
|
@ -262,14 +250,11 @@ fn draw_section_sequencer (state: &Launcher, buf: &mut Buffer, area: Rect) -> Us
|
||||||
}
|
}
|
||||||
fn draw_section_chains (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
fn draw_section_chains (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||||
let style = Some(Style::default().green().dim());
|
let style = Some(Style::default().green().dim());
|
||||||
match state.view {
|
if state.view.is_chains() {
|
||||||
LauncherView::Chains => {
|
|
||||||
let Rect { x, y, width, height} = area;
|
let Rect { x, y, width, height} = area;
|
||||||
lozenge_left(buf, x, y, height, style);
|
lozenge_left(buf, x, y, height, style);
|
||||||
lozenge_right(buf, x + width - 1, y, height, style);
|
lozenge_right(buf, x + width - 1, y, height, style);
|
||||||
},
|
}
|
||||||
_ => {},
|
|
||||||
};
|
|
||||||
let chain = state.chain();
|
let chain = state.chain();
|
||||||
let _ = if let Some(chain) = &chain {
|
let _ = if let Some(chain) = &chain {
|
||||||
let (_, plugins) = crate::device::chain::draw_as_row(
|
let (_, plugins) = crate::device::chain::draw_as_row(
|
||||||
|
|
@ -281,3 +266,16 @@ fn draw_section_chains (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usual
|
||||||
};
|
};
|
||||||
Ok(area)
|
Ok(area)
|
||||||
}
|
}
|
||||||
|
pub enum LauncherView {
|
||||||
|
Tracks,
|
||||||
|
Sequencer,
|
||||||
|
Chains
|
||||||
|
}
|
||||||
|
impl LauncherView {
|
||||||
|
fn is_chains (&self) -> bool {
|
||||||
|
match self { Self::Chains => true, _ => false }
|
||||||
|
}
|
||||||
|
fn is_tracks (&self) -> bool {
|
||||||
|
match self { Self::Tracks => true, _ => false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
13
src/device/launcher/scene.rs
Normal file
13
src/device/launcher/scene.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
pub struct Scene {
|
||||||
|
pub name: String,
|
||||||
|
pub clips: Vec<Option<usize>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Scene {
|
||||||
|
pub fn new (name: impl AsRef<str>, clips: impl AsRef<[Option<usize>]>) -> Self {
|
||||||
|
Self {
|
||||||
|
name: name.as_ref().into(),
|
||||||
|
clips: clips.as_ref().iter().map(|x|x.clone()).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -127,8 +127,8 @@ pub fn lanes (
|
||||||
phrase.contains_note_on(u7::from_int_lossy(note_b as u8), a, b),
|
phrase.contains_note_on(u7::from_int_lossy(note_b as u8), a, b),
|
||||||
) {
|
) {
|
||||||
(true, true) => ("█", wh),
|
(true, true) => ("█", wh),
|
||||||
(false, true) => ("▄", wh),
|
(false, true) => ("▀", wh),
|
||||||
(true, false) => ("▀", wh),
|
(true, false) => ("▄", wh),
|
||||||
(false, false) => ("·", bw),
|
(false, false) => ("·", bw),
|
||||||
};
|
};
|
||||||
let y = y + height.saturating_sub(index+2) as u16;
|
let y = y + height.saturating_sub(index+2) as u16;
|
||||||
|
|
|
||||||
42
src/layout/collect.rs
Normal file
42
src/layout/collect.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
pub enum Collected<'a> {
|
||||||
|
Box(Box<dyn Render + 'a>),
|
||||||
|
Ref(&'a (dyn Render + 'a)),
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Render for Collected<'a> {
|
||||||
|
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||||
|
match self {
|
||||||
|
Self::Box(item) => (*item).render(buf, area),
|
||||||
|
Self::Ref(item) => (*item).render(buf, area),
|
||||||
|
Self::None => Ok(area),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Collector<'a>(pub Vec<Collected<'a>>);
|
||||||
|
|
||||||
|
impl<'a, R: Render + 'a> FnOnce<(R)> for Collector<'a> {
|
||||||
|
type Output = ();
|
||||||
|
extern "rust-call" fn call_once (self, (device, ): (R,)) -> Self::Output {
|
||||||
|
self.add(widget.into_collected());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Collector<'a> {
|
||||||
|
pub fn collect (collect: impl Fn(&mut Collector<'a>)) -> Self {
|
||||||
|
let mut items = Self(vec![]);
|
||||||
|
collect(&mut items);
|
||||||
|
items
|
||||||
|
}
|
||||||
|
fn add (mut self, widget: Collected<'a>) -> Self {
|
||||||
|
self.0.push(widget);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Collection<'a, T, U> {
|
||||||
|
fn add (self, widget: impl Render + 'a) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,5 +1,17 @@
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
|
|
||||||
|
pub struct Stack<'a>(pub &'a[Box<dyn Render>]);
|
||||||
|
|
||||||
|
impl<'a> Render for Stack<'a> {
|
||||||
|
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||||
|
let mut area2 = area.clone();
|
||||||
|
for layer in self.0.iter() {
|
||||||
|
area2 = layer.render(buf, area2)?;
|
||||||
|
}
|
||||||
|
Ok(area)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Column(pub Vec<Box<dyn Device>>);
|
pub struct Column(pub Vec<Box<dyn Device>>);
|
||||||
|
|
||||||
pub struct Row(pub Vec<Box<dyn Device>>);
|
pub struct Row(pub Vec<Box<dyn Device>>);
|
||||||
|
|
|
||||||
73
src/main.rs
73
src/main.rs
|
|
@ -1,3 +1,5 @@
|
||||||
|
//#![feature(fn_traits)]
|
||||||
|
//#![feature(unboxed_closures)]
|
||||||
#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]
|
#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]
|
||||||
|
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
|
@ -18,22 +20,58 @@ use crate::device::*;
|
||||||
|
|
||||||
mod new {
|
mod new {
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
type Phrase = (String, usize, BTreeMap<usize, Vec<Vec<u8>>>);
|
use crate::layout::Stack;
|
||||||
type Scene = (String, Option<usize>, Vec<Option<AtomicUsize>>);
|
type Phrase = (String, usize, BTreeMap<usize, Vec<MidiMessage>>);
|
||||||
|
type Scene = (String, Option<usize>, Vec<Option<usize>>);
|
||||||
type Track = (String, usize);
|
type Track = (String, usize);
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct App {
|
pub struct App {
|
||||||
phrases: BTreeMap<usize, Arc<Mutex<Phrase>>>,
|
client: Option<DynamicAsyncClient>,
|
||||||
scenes: BTreeMap<usize, Arc<Mutex<Scene>>>,
|
phrases: BTreeMap<usize, Phrase>,
|
||||||
tracks: BTreeMap<usize, Arc<Mutex<Track>>>,
|
scenes: BTreeMap<usize, Scene>,
|
||||||
|
tracks: BTreeMap<usize, Track>,
|
||||||
|
frame: usize,
|
||||||
|
scene: Vec<usize>,
|
||||||
|
timebase: Arc<Timebase>,
|
||||||
}
|
}
|
||||||
fn main () {
|
struct SceneGrid {}
|
||||||
App::default().run()
|
impl Render for SceneGrid {}
|
||||||
|
struct Chains {}
|
||||||
|
impl Render for Chains {}
|
||||||
|
struct Sequencer {}
|
||||||
|
impl Render for Sequencer {}
|
||||||
|
impl Render for App {
|
||||||
|
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||||
|
crate::device::Transport {
|
||||||
|
timebase: &self.timebase,
|
||||||
|
playing: TransportState::Stopped,
|
||||||
|
record: false,
|
||||||
|
overdub: false,
|
||||||
|
monitor: false,
|
||||||
|
frame: 0,
|
||||||
|
}.render(buf, area)?;
|
||||||
|
SceneGrid {
|
||||||
|
}.render(buf, area)?;
|
||||||
|
Chains {}.render(buf, area)?;
|
||||||
|
Sequencer {}.render(buf, area)?;
|
||||||
|
Ok(area)
|
||||||
}
|
}
|
||||||
impl App {
|
|
||||||
fn run (self) {
|
|
||||||
panic_hook_setup();
|
|
||||||
}
|
}
|
||||||
|
impl Handle for App {
|
||||||
|
fn handle (&mut self, _e: &AppEvent) -> Usually<bool> {
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Process for App {
|
||||||
|
fn process (&mut self, _c: &Client, _s: &ProcessScope) -> Control {
|
||||||
|
Control::Continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn main () -> Usually<()> {
|
||||||
|
App::default().run(Some(|app: Arc<Mutex<App>>|{
|
||||||
|
app.lock().unwrap().client = Some(jack_run("tek", &app)?);
|
||||||
|
Ok(())
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,8 +99,6 @@ fn main () -> Usually<()> {
|
||||||
let xdg = microxdg::XdgApp::new("tek")?;
|
let xdg = microxdg::XdgApp::new("tek")?;
|
||||||
crate::config::create_dirs(&xdg)?;
|
crate::config::create_dirs(&xdg)?;
|
||||||
//run(Sampler::new("Sampler#000")?)
|
//run(Sampler::new("Sampler#000")?)
|
||||||
let input = ".*nanoKEY.*";
|
|
||||||
let output = ["Komplete.*:playback_FL", "Komplete.*:playback_FR"];
|
|
||||||
let (client, _) = Client::new("init", ClientOptions::NO_START_SERVER)?;
|
let (client, _) = Client::new("init", ClientOptions::NO_START_SERVER)?;
|
||||||
let timebase = Arc::new(Timebase::new(client.sample_rate() as f64, 125.0, 96.0));
|
let timebase = Arc::new(Timebase::new(client.sample_rate() as f64, 125.0, 96.0));
|
||||||
let ppq = timebase.ppq() as usize;
|
let ppq = timebase.ppq() as usize;
|
||||||
|
|
@ -213,6 +249,13 @@ fn main () -> Usually<()> {
|
||||||
])
|
])
|
||||||
|
|
||||||
)?
|
)?
|
||||||
.connect(input, &output)?
|
.run(Some(init))
|
||||||
.run()
|
}
|
||||||
|
|
||||||
|
fn init (state: Arc<Mutex<DynamicDevice<Launcher>>>) -> Usually<()> {
|
||||||
|
let input = ".*nanoKEY.*";
|
||||||
|
let output = ["Komplete.*:playback_FL", "Komplete.*:playback_FR"];
|
||||||
|
let state = state.lock().unwrap();
|
||||||
|
state.connect(input, &output)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue