mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: refactor pt.9, 403 errors
This commit is contained in:
parent
a784f7a6f2
commit
8aa1ba8d0f
29 changed files with 1008 additions and 902 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Arrangement {
|
||||
/// JACK client handle (needs to not be dropped for standalone mode to work).
|
||||
pub jack: Arc<RwLock<JackClient>>,
|
||||
|
|
@ -12,9 +13,10 @@ pub struct Arrangement {
|
|||
/// Collection of tracks.
|
||||
pub tracks: Vec<ArrangementTrack>,
|
||||
/// Collection of scenes.
|
||||
pub scenes: Vec<Scene>,
|
||||
pub scenes: Vec<ArrangementScene>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ArrangementTrack {
|
||||
/// Name of track
|
||||
pub name: Arc<RwLock<String>>,
|
||||
|
|
@ -26,57 +28,93 @@ pub struct ArrangementTrack {
|
|||
pub player: MIDIPlayer
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ArrangementScene {
|
||||
/// Name of scene
|
||||
pub name: Arc<RwLock<String>>,
|
||||
/// Clips in scene, one per track
|
||||
pub clips: Vec<Option<Arc<RwLock<Phrase>>>>,
|
||||
/// Identifying color of scene
|
||||
pub color: ItemColor,
|
||||
}
|
||||
|
||||
impl Audio for Arrangement {
|
||||
fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
|
||||
#[inline] fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
|
||||
for track in self.tracks.iter_mut() {
|
||||
track.player.process(client, scope);
|
||||
if track.process(client, scope) == Control::Quit {
|
||||
return Control::Quit
|
||||
}
|
||||
}
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
||||
impl Audio for ArrangementTrack {
|
||||
#[inline] fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
|
||||
self.player.process(client, scope)
|
||||
}
|
||||
}
|
||||
|
||||
impl Arrangement {
|
||||
fn is_stopped (&self) -> bool {
|
||||
pub fn is_stopped (&self) -> bool {
|
||||
*self.clock.playing.read().unwrap() == Some(TransportState::Stopped)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementCommand {
|
||||
New,
|
||||
Load,
|
||||
Save,
|
||||
ToggleViewMode,
|
||||
Delete,
|
||||
Activate,
|
||||
Increment,
|
||||
Decrement,
|
||||
ZoomIn,
|
||||
ZoomOut,
|
||||
Go(Direction),
|
||||
Edit(Option<Arc<RwLock<Phrase>>>),
|
||||
Scene(SceneCommand),
|
||||
Track(ArrangementTrackCommand),
|
||||
Clip(ArrangementClipCommand),
|
||||
}
|
||||
impl ArrangementScene {
|
||||
/// Returns the pulse length of the longest phrase in the scene
|
||||
pub fn pulses (&self) -> usize {
|
||||
self.clips.iter().fold(0, |a, p|{
|
||||
a.max(p.as_ref().map(|q|q.read().unwrap().length).unwrap_or(0))
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementTrackCommand {
|
||||
Next,
|
||||
Prev,
|
||||
Add,
|
||||
Delete,
|
||||
MoveForward,
|
||||
MoveBack,
|
||||
RandomColor,
|
||||
SetSize(usize),
|
||||
SetZoom(usize),
|
||||
}
|
||||
/// Returns true if all phrases in the scene are
|
||||
/// currently playing on the given collection of tracks.
|
||||
pub fn is_playing (&self, tracks: &[MIDIPlayer]) -> bool {
|
||||
self.clips.iter().any(|clip|clip.is_some()) && self.clips.iter().enumerate()
|
||||
.all(|(track_index, clip)|match clip {
|
||||
Some(clip) => tracks
|
||||
.get(track_index)
|
||||
.map(|track|if let Some((_, Some(phrase))) = &track.phrase {
|
||||
*phrase.read().unwrap() == *clip.read().unwrap()
|
||||
} else {
|
||||
false
|
||||
})
|
||||
.unwrap_or(false),
|
||||
None => true
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementClipCommand {
|
||||
Get(usize, usize),
|
||||
Put(usize, usize, Option<Arc<RwLock<Phrase>>>),
|
||||
Edit(Option<Arc<RwLock<Phrase>>>),
|
||||
SetLoop(bool),
|
||||
pub fn clip (&self, index: usize) -> Option<&Arc<RwLock<Phrase>>> {
|
||||
match self.clips.get(index) { Some(Some(clip)) => Some(clip), _ => None }
|
||||
}
|
||||
|
||||
//TODO
|
||||
//pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Self> {
|
||||
//let mut name = None;
|
||||
//let mut clips = vec![];
|
||||
//edn!(edn in args {
|
||||
//Edn::Map(map) => {
|
||||
//let key = map.get(&Edn::Key(":name"));
|
||||
//if let Some(Edn::Str(n)) = key {
|
||||
//name = Some(*n);
|
||||
//} else {
|
||||
//panic!("unexpected key in scene '{name:?}': {key:?}")
|
||||
//}
|
||||
//},
|
||||
//Edn::Symbol("_") => {
|
||||
//clips.push(None);
|
||||
//},
|
||||
//Edn::Int(i) => {
|
||||
//clips.push(Some(*i as usize));
|
||||
//},
|
||||
//_ => panic!("unexpected in scene '{name:?}': {edn:?}")
|
||||
//});
|
||||
//Ok(ArrangementScene {
|
||||
//name: Arc::new(name.unwrap_or("").to_string().into()),
|
||||
//color: ItemColor::random(),
|
||||
//clips,
|
||||
//})
|
||||
//}
|
||||
}
|
||||
|
|
|
|||
94
crates/tek_api/src/arrange_cmd.rs
Normal file
94
crates/tek_api/src/arrange_cmd.rs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementCommand {
|
||||
Clear,
|
||||
Export,
|
||||
Import,
|
||||
StopAll,
|
||||
Scene(ArrangementSceneCommand),
|
||||
Track(ArrangementTrackCommand),
|
||||
Clip(ArrangementClipCommand),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementSceneCommand {
|
||||
Add,
|
||||
Delete,
|
||||
RandomColor,
|
||||
Play,
|
||||
Swap(usize),
|
||||
SetSize(usize),
|
||||
SetZoom(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementTrackCommand {
|
||||
Add,
|
||||
Delete,
|
||||
RandomColor,
|
||||
Stop,
|
||||
Swap(usize),
|
||||
SetSize(usize),
|
||||
SetZoom(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementClipCommand {
|
||||
Play,
|
||||
Get(usize, usize),
|
||||
Set(usize, usize, Option<Arc<RwLock<Phrase>>>),
|
||||
Edit(Option<Arc<RwLock<Phrase>>>),
|
||||
SetLoop(bool),
|
||||
RandomColor,
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
match self {
|
||||
Self::Clear => todo!(),
|
||||
Self::Export => todo!(),
|
||||
Self::Import => todo!(),
|
||||
Self::StopAll => todo!(),
|
||||
Self::Scene(command) => { return Ok(command.execute(state)?.map(Self::Scene)) },
|
||||
Self::Track(command) => { return Ok(command.execute(state)?.map(Self::Track)) },
|
||||
Self::Clip(command) => { return Ok(command.execute(state)?.map(Self::Clip)) },
|
||||
}
|
||||
return Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementSceneCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementTrackCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementClipCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
//impl Command<Arrangement> for ArrangementSceneCommand {
|
||||
//}
|
||||
//Edit(phrase) => { state.state.phrase = phrase.clone() },
|
||||
//ToggleViewMode => { state.state.mode.to_next(); },
|
||||
//Delete => { state.state.delete(); },
|
||||
//Activate => { state.state.activate(); },
|
||||
//ZoomIn => { state.state.zoom_in(); },
|
||||
//ZoomOut => { state.state.zoom_out(); },
|
||||
//MoveBack => { state.state.move_back(); },
|
||||
//MoveForward => { state.state.move_forward(); },
|
||||
//RandomColor => { state.state.randomize_color(); },
|
||||
//Put => { state.state.phrase_put(); },
|
||||
//Get => { state.state.phrase_get(); },
|
||||
//AddScene => { state.state.scene_add(None, None)?; },
|
||||
//AddTrack => { state.state.track_add(None, None)?; },
|
||||
//ToggleLoop => { state.state.toggle_loop() },
|
||||
|
|
@ -10,21 +10,31 @@ pub(crate) use tek_core::jack::{
|
|||
|
||||
submod! {
|
||||
api_jack
|
||||
|
||||
arrange
|
||||
arrange_cmd
|
||||
|
||||
clock
|
||||
|
||||
mixer
|
||||
mixer_track
|
||||
|
||||
phrase
|
||||
|
||||
plugin
|
||||
plugin_kind
|
||||
plugin_lv2
|
||||
|
||||
pool
|
||||
sample
|
||||
|
||||
sampler
|
||||
scene
|
||||
scene_cmd
|
||||
sampler_sample
|
||||
sampler_voice
|
||||
|
||||
sequencer
|
||||
track
|
||||
|
||||
status
|
||||
|
||||
transport
|
||||
transport_cmd
|
||||
voice
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,16 +14,6 @@ pub struct MixerTrack {
|
|||
pub devices: Vec<Box<dyn MixerTrackDevice>>,
|
||||
}
|
||||
|
||||
pub trait MixerTrackDevice: Audio + Debug {
|
||||
fn boxed (self) -> Box<dyn MixerTrackDevice> where Self: Sized + 'static {
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl MixerTrackDevice for Sampler {}
|
||||
|
||||
impl MixerTrackDevice for Plugin {}
|
||||
|
||||
//impl MixerTrackDevice for LV2Plugin {}
|
||||
|
||||
impl MixerTrack {
|
||||
|
|
@ -81,3 +71,13 @@ impl MixerTrack {
|
|||
Ok(track)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MixerTrackDevice: Audio + Debug {
|
||||
fn boxed (self) -> Box<dyn MixerTrackDevice> where Self: Sized + 'static {
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl MixerTrackDevice for Sampler {}
|
||||
|
||||
impl MixerTrackDevice for Plugin {}
|
||||
|
|
@ -4,46 +4,18 @@ use crate::*;
|
|||
pub struct PhrasePool {
|
||||
/// Phrases in the pool
|
||||
pub phrases: Vec<Arc<RwLock<Phrase>>>,
|
||||
/// Highlighted phrase
|
||||
pub phrase: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum PhrasePoolCommand {
|
||||
Prev,
|
||||
Next,
|
||||
MoveUp,
|
||||
MoveDown,
|
||||
Delete,
|
||||
Append,
|
||||
Insert,
|
||||
Duplicate,
|
||||
RandomColor,
|
||||
Edit,
|
||||
Import,
|
||||
Export,
|
||||
Rename(PhraseRenameCommand),
|
||||
Length(PhraseLengthCommand),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum PhraseRenameCommand {
|
||||
Begin,
|
||||
Backspace,
|
||||
Append(char),
|
||||
Set(String),
|
||||
Confirm,
|
||||
Cancel,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum PhraseLengthCommand {
|
||||
Begin,
|
||||
Next,
|
||||
Prev,
|
||||
Inc,
|
||||
Dec,
|
||||
Set(usize),
|
||||
Confirm,
|
||||
Cancel,
|
||||
Select(usize),
|
||||
Add(usize),
|
||||
Delete(usize),
|
||||
Duplicate(usize),
|
||||
Swap(usize),
|
||||
RandomColor(usize),
|
||||
Import(String),
|
||||
Export(String),
|
||||
SetName(String),
|
||||
SetLength(String),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,70 +0,0 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Scene {
|
||||
/// Name of scene
|
||||
pub name: Arc<RwLock<String>>,
|
||||
/// Clips in scene, one per track
|
||||
pub clips: Vec<Option<Arc<RwLock<Phrase>>>>,
|
||||
/// Identifying color of scene
|
||||
pub color: ItemColor,
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
//TODO
|
||||
//pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Self> {
|
||||
//let mut name = None;
|
||||
//let mut clips = vec![];
|
||||
//edn!(edn in args {
|
||||
//Edn::Map(map) => {
|
||||
//let key = map.get(&Edn::Key(":name"));
|
||||
//if let Some(Edn::Str(n)) = key {
|
||||
//name = Some(*n);
|
||||
//} else {
|
||||
//panic!("unexpected key in scene '{name:?}': {key:?}")
|
||||
//}
|
||||
//},
|
||||
//Edn::Symbol("_") => {
|
||||
//clips.push(None);
|
||||
//},
|
||||
//Edn::Int(i) => {
|
||||
//clips.push(Some(*i as usize));
|
||||
//},
|
||||
//_ => panic!("unexpected in scene '{name:?}': {edn:?}")
|
||||
//});
|
||||
//Ok(Scene {
|
||||
//name: Arc::new(name.unwrap_or("").to_string().into()),
|
||||
//color: ItemColor::random(),
|
||||
//clips,
|
||||
//})
|
||||
//}
|
||||
|
||||
/// Returns the pulse length of the longest phrase in the scene
|
||||
pub fn pulses (&self) -> usize {
|
||||
self.clips.iter().fold(0, |a, p|{
|
||||
a.max(p.as_ref().map(|q|q.read().unwrap().length).unwrap_or(0))
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns true if all phrases in the scene are
|
||||
/// currently playing on the given collection of tracks.
|
||||
pub fn is_playing (&self, tracks: &[MIDIPlayer]) -> bool {
|
||||
self.clips.iter().any(|clip|clip.is_some()) && self.clips.iter().enumerate()
|
||||
.all(|(track_index, clip)|match clip {
|
||||
Some(clip) => tracks
|
||||
.get(track_index)
|
||||
.map(|track|if let Some((_, Some(phrase))) = &track.phrase {
|
||||
*phrase.read().unwrap() == *clip.read().unwrap()
|
||||
} else {
|
||||
false
|
||||
})
|
||||
.unwrap_or(false),
|
||||
None => true
|
||||
})
|
||||
}
|
||||
|
||||
pub fn clip (&self, index: usize) -> Option<&Arc<RwLock<Phrase>>> {
|
||||
match self.clips.get(index) { Some(Some(clip)) => Some(clip), _ => None }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum SceneCommand {
|
||||
Next,
|
||||
Prev,
|
||||
Add,
|
||||
Delete,
|
||||
MoveForward,
|
||||
MoveBack,
|
||||
RandomColor,
|
||||
SetSize(usize),
|
||||
SetZoom(usize),
|
||||
}
|
||||
19
crates/tek_api/src/status.rs
Normal file
19
crates/tek_api/src/status.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use crate::*;
|
||||
|
||||
pub trait StatusBar<E: Engine>: Widget<Engine = E> {
|
||||
fn hotkey_fg () -> Color;
|
||||
|
||||
fn command (commands: &[[impl Widget<Engine = Tui>;3]]) -> impl Widget<Engine = Tui> + '_ {
|
||||
let hotkey_fg = Self::hotkey_fg();
|
||||
Stack::right(move |add|{
|
||||
Ok(for [a, b, c] in commands.iter() {
|
||||
add(&row!(
|
||||
" ",
|
||||
widget(a),
|
||||
widget(b).bold(true).fg(hotkey_fg),
|
||||
widget(c),
|
||||
))?;
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue