mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: refactor pt.21: 48 errors
This commit is contained in:
parent
2188bccd63
commit
b8708d6b2d
15 changed files with 313 additions and 355 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Arrangement {
|
||||
pub struct ArrangerModel {
|
||||
/// JACK client handle (needs to not be dropped for standalone mode to work).
|
||||
pub jack: Arc<RwLock<JackClient>>,
|
||||
/// Global timebase
|
||||
|
|
@ -9,15 +9,15 @@ pub struct Arrangement {
|
|||
/// Name of arranger
|
||||
pub name: Arc<RwLock<String>>,
|
||||
/// Collection of phrases.
|
||||
pub phrases: Arc<RwLock<Vec<Phrase>>>,
|
||||
pub phrases: Arc<RwLock<PhrasePool>>,
|
||||
/// Collection of tracks.
|
||||
pub tracks: Vec<ArrangementTrack>,
|
||||
pub tracks: Vec<ArrangerTrack>,
|
||||
/// Collection of scenes.
|
||||
pub scenes: Vec<ArrangementScene>,
|
||||
pub scenes: Vec<ArrangerScene>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ArrangementTrack {
|
||||
pub struct ArrangerTrack {
|
||||
/// Name of track
|
||||
pub name: Arc<RwLock<String>>,
|
||||
/// Preferred width of track column
|
||||
|
|
@ -29,7 +29,7 @@ pub struct ArrangementTrack {
|
|||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ArrangementScene {
|
||||
pub struct ArrangerScene {
|
||||
/// Name of scene
|
||||
pub name: Arc<RwLock<String>>,
|
||||
/// Clips in scene, one per track
|
||||
|
|
@ -38,7 +38,7 @@ pub struct ArrangementScene {
|
|||
pub color: ItemColor,
|
||||
}
|
||||
|
||||
impl Arrangement {
|
||||
impl ArrangerModel {
|
||||
pub fn is_stopped (&self) -> bool {
|
||||
*self.clock.playing.read().unwrap() == Some(TransportState::Stopped)
|
||||
}
|
||||
|
|
@ -50,9 +50,9 @@ impl Arrangement {
|
|||
}
|
||||
pub fn track_add (
|
||||
&mut self, name: Option<&str>, color: Option<ItemColor>
|
||||
) -> Usually<&mut ArrangementTrack> {
|
||||
) -> Usually<&mut ArrangerTrack> {
|
||||
let name = name.map_or_else(||self.track_default_name(), |x|x.to_string());
|
||||
self.tracks.push(ArrangementTrack {
|
||||
self.tracks.push(ArrangerTrack {
|
||||
width: name.len() + 2,
|
||||
color: color.unwrap_or_else(||ItemColor::random()),
|
||||
player: MIDIPlayer::new(&self.jack, &self.clock, name.as_str())?,
|
||||
|
|
@ -63,9 +63,9 @@ impl Arrangement {
|
|||
}
|
||||
pub fn scene_add (
|
||||
&mut self, name: Option<&str>, color: Option<ItemColor>
|
||||
) -> Usually<&mut ArrangementScene> {
|
||||
) -> Usually<&mut ArrangerScene> {
|
||||
let name = name.map_or_else(||self.scene_default_name(), |x|x.to_string());
|
||||
self.scenes.push(ArrangementScene {
|
||||
self.scenes.push(ArrangerScene {
|
||||
name: Arc::new(name.into()),
|
||||
clips: vec![None;self.tracks.len()],
|
||||
color: color.unwrap_or_else(||ItemColor::random()),
|
||||
|
|
@ -84,7 +84,7 @@ impl Arrangement {
|
|||
}
|
||||
}
|
||||
|
||||
impl ArrangementScene {
|
||||
impl ArrangerScene {
|
||||
pub fn ppqs (scenes: &[Self], factor: usize) -> Vec<(usize, usize)> {
|
||||
let mut total = 0;
|
||||
if factor == 0 {
|
||||
|
|
@ -113,7 +113,7 @@ impl ArrangementScene {
|
|||
|
||||
/// Returns true if all phrases in the scene are
|
||||
/// currently playing on the given collection of tracks.
|
||||
pub fn is_playing (&self, tracks: &[ArrangementTrack]) -> bool {
|
||||
pub fn is_playing (&self, tracks: &[ArrangerTrack]) -> bool {
|
||||
self.clips.iter().any(|clip|clip.is_some()) && self.clips.iter().enumerate()
|
||||
.all(|(track_index, clip)|match clip {
|
||||
Some(clip) => tracks
|
||||
|
|
@ -153,7 +153,7 @@ impl ArrangementScene {
|
|||
//},
|
||||
//_ => panic!("unexpected in scene '{name:?}': {edn:?}")
|
||||
//});
|
||||
//Ok(ArrangementScene {
|
||||
//Ok(ArrangerScene {
|
||||
//name: Arc::new(name.unwrap_or("").to_string().into()),
|
||||
//color: ItemColor::random(),
|
||||
//clips,
|
||||
|
|
@ -161,7 +161,7 @@ impl ArrangementScene {
|
|||
//}
|
||||
}
|
||||
|
||||
impl ArrangementTrack {
|
||||
impl ArrangerTrack {
|
||||
pub fn longest_name (tracks: &[Self]) -> usize {
|
||||
tracks.iter().map(|s|s.name.read().unwrap().len()).fold(0, usize::max)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementCommand {
|
||||
pub enum ArrangerCommand {
|
||||
Clear,
|
||||
Export,
|
||||
Import,
|
||||
StopAll,
|
||||
Scene(ArrangementSceneCommand),
|
||||
Track(ArrangementTrackCommand),
|
||||
Clip(ArrangementClipCommand),
|
||||
Scene(ArrangerSceneCommand),
|
||||
Track(ArrangerTrackCommand),
|
||||
Clip(ArrangerClipCommand),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementSceneCommand {
|
||||
pub enum ArrangerSceneCommand {
|
||||
Add,
|
||||
Delete(usize),
|
||||
RandomColor,
|
||||
|
|
@ -23,7 +23,7 @@ pub enum ArrangementSceneCommand {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementTrackCommand {
|
||||
pub enum ArrangerTrackCommand {
|
||||
Add,
|
||||
Delete(usize),
|
||||
RandomColor,
|
||||
|
|
@ -34,7 +34,7 @@ pub enum ArrangementTrackCommand {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ArrangementClipCommand {
|
||||
pub enum ArrangerClipCommand {
|
||||
Play,
|
||||
Get(usize, usize),
|
||||
Set(usize, usize, Option<Arc<RwLock<Phrase>>>),
|
||||
|
|
@ -43,8 +43,8 @@ pub enum ArrangementClipCommand {
|
|||
RandomColor,
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
impl Command<ArrangerModel> for ArrangerCommand {
|
||||
fn execute (self, state: &mut ArrangerModel) -> Perhaps<Self> {
|
||||
match self {
|
||||
Self::Scene(command) => { return Ok(command.execute(state)?.map(Self::Scene)) },
|
||||
Self::Track(command) => { return Ok(command.execute(state)?.map(Self::Track)) },
|
||||
|
|
@ -55,8 +55,8 @@ impl Command<Arrangement> for ArrangementCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementSceneCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
impl Command<ArrangerModel> for ArrangerSceneCommand {
|
||||
fn execute (self, state: &mut ArrangerModel) -> Perhaps<Self> {
|
||||
match self {
|
||||
Self::Delete(index) => { state.scene_del(index); },
|
||||
_ => todo!()
|
||||
|
|
@ -65,8 +65,8 @@ impl Command<Arrangement> for ArrangementSceneCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementTrackCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
impl Command<ArrangerModel> for ArrangerTrackCommand {
|
||||
fn execute (self, state: &mut ArrangerModel) -> Perhaps<Self> {
|
||||
match self {
|
||||
Self::Delete(index) => { state.track_del(index); },
|
||||
_ => todo!()
|
||||
|
|
@ -75,8 +75,8 @@ impl Command<Arrangement> for ArrangementTrackCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl Command<Arrangement> for ArrangementClipCommand {
|
||||
fn execute (self, state: &mut Arrangement) -> Perhaps<Self> {
|
||||
impl Command<ArrangerModel> for ArrangerClipCommand {
|
||||
fn execute (self, state: &mut ArrangerModel) -> Perhaps<Self> {
|
||||
match self {
|
||||
_ => todo!()
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ impl Command<Arrangement> for ArrangementClipCommand {
|
|||
}
|
||||
}
|
||||
|
||||
//impl Command<Arrangement> for ArrangementSceneCommand {
|
||||
//impl Command<ArrangerModel> for ArrangerSceneCommand {
|
||||
//}
|
||||
//Edit(phrase) => { state.state.phrase = phrase.clone() },
|
||||
//ToggleViewMode => { state.state.mode.to_next(); },
|
||||
|
|
@ -101,27 +101,27 @@ impl Command<Arrangement> for ArrangementClipCommand {
|
|||
//AddTrack => { state.state.track_add(None, None)?; },
|
||||
//ToggleLoop => { state.state.toggle_loop() },
|
||||
//pub fn zoom_in (&mut self) {
|
||||
//if let ArrangementEditorMode::Vertical(factor) = self.mode {
|
||||
//self.mode = ArrangementEditorMode::Vertical(factor + 1)
|
||||
//if let ArrangerEditorMode::Vertical(factor) = self.mode {
|
||||
//self.mode = ArrangerEditorMode::Vertical(factor + 1)
|
||||
//}
|
||||
//}
|
||||
//pub fn zoom_out (&mut self) {
|
||||
//if let ArrangementEditorMode::Vertical(factor) = self.mode {
|
||||
//self.mode = ArrangementEditorMode::Vertical(factor.saturating_sub(1))
|
||||
//if let ArrangerEditorMode::Vertical(factor) = self.mode {
|
||||
//self.mode = ArrangerEditorMode::Vertical(factor.saturating_sub(1))
|
||||
//}
|
||||
//}
|
||||
//pub fn move_back (&mut self) {
|
||||
//match self.selected {
|
||||
//ArrangementEditorFocus::Scene(s) => {
|
||||
//ArrangerEditorFocus::Scene(s) => {
|
||||
//if s > 0 {
|
||||
//self.scenes.swap(s, s - 1);
|
||||
//self.selected = ArrangementEditorFocus::Scene(s - 1);
|
||||
//self.selected = ArrangerEditorFocus::Scene(s - 1);
|
||||
//}
|
||||
//},
|
||||
//ArrangementEditorFocus::Track(t) => {
|
||||
//ArrangerEditorFocus::Track(t) => {
|
||||
//if t > 0 {
|
||||
//self.tracks.swap(t, t - 1);
|
||||
//self.selected = ArrangementEditorFocus::Track(t - 1);
|
||||
//self.selected = ArrangerEditorFocus::Track(t - 1);
|
||||
//// FIXME: also swap clip order in scenes
|
||||
//}
|
||||
//},
|
||||
|
|
@ -130,16 +130,16 @@ impl Command<Arrangement> for ArrangementClipCommand {
|
|||
//}
|
||||
//pub fn move_forward (&mut self) {
|
||||
//match self.selected {
|
||||
//ArrangementEditorFocus::Scene(s) => {
|
||||
//ArrangerEditorFocus::Scene(s) => {
|
||||
//if s < self.scenes.len().saturating_sub(1) {
|
||||
//self.scenes.swap(s, s + 1);
|
||||
//self.selected = ArrangementEditorFocus::Scene(s + 1);
|
||||
//self.selected = ArrangerEditorFocus::Scene(s + 1);
|
||||
//}
|
||||
//},
|
||||
//ArrangementEditorFocus::Track(t) => {
|
||||
//ArrangerEditorFocus::Track(t) => {
|
||||
//if t < self.tracks.len().saturating_sub(1) {
|
||||
//self.tracks.swap(t, t + 1);
|
||||
//self.selected = ArrangementEditorFocus::Track(t + 1);
|
||||
//self.selected = ArrangerEditorFocus::Track(t + 1);
|
||||
//// FIXME: also swap clip order in scenes
|
||||
//}
|
||||
//},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::*;
|
||||
|
||||
/// Contains all phrases in a project
|
||||
#[derive(Debug)]
|
||||
pub struct PhrasePool {
|
||||
/// Phrases in the pool
|
||||
pub phrases: Vec<Arc<RwLock<Phrase>>>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue