mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-08-07 22:17:07 +02:00
restruct: 45e
This commit is contained in:
parent
b3e9cde8a1
commit
027f69cd50
9 changed files with 264 additions and 270 deletions
|
|
@ -27,7 +27,7 @@ pub trait ClipsView: TracksView + ScenesView {
|
|||
/// Draw clips per scene
|
||||
fn view_scenes_clips <'a> (&'a self) -> impl Draw<Tui> + 'a {
|
||||
crate::view::view_scenes_clips(
|
||||
self.scenes_with_sizes(),
|
||||
||self.scenes_with_sizes(),
|
||||
self.tracks_with_sizes(),
|
||||
self.selection(),
|
||||
self.editor(),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
use crate::*;
|
||||
|
||||
/// Default scene height.
|
||||
pub const H_SCENE: usize = 2;
|
||||
|
||||
/// Default editor height.
|
||||
pub const H_EDITOR: usize = 15;
|
||||
|
||||
/// A scene consists of a set of clips to play together.
|
||||
///
|
||||
/// ```
|
||||
|
|
@ -51,10 +57,6 @@ impl Scene {
|
|||
}
|
||||
|
||||
pub trait ScenesView: HasEditor + HasSelection + HasSceneScroll + HasClipsSize + Send + Sync {
|
||||
/// Default scene height.
|
||||
const H_SCENE: usize = 2;
|
||||
/// Default editor height.
|
||||
const H_EDITOR: usize = 15;
|
||||
fn h_scenes (&self) -> u16;
|
||||
fn w_side (&self) -> u16;
|
||||
fn w_mid (&self) -> u16;
|
||||
|
|
@ -70,7 +72,7 @@ pub trait ScenesView: HasEditor + HasSelection + HasSceneScroll + HasClipsSize +
|
|||
let height = if self.selection().scene() == Some(s) && self.editor().is_some() {
|
||||
8
|
||||
} else {
|
||||
Self::H_SCENE
|
||||
H_SCENE
|
||||
};
|
||||
if y + height <= self.clips_size().h() as usize {
|
||||
let data = (s, scene, y, y + height);
|
||||
|
|
|
|||
|
|
@ -223,71 +223,66 @@ impl HasTrackScroll for Arrangement {
|
|||
|
||||
def_command!(TrackCommand: |track: Track| {
|
||||
Stop => { track.sequencer.enqueue_next(None); Ok(None) },
|
||||
SetMute { mute: Option<bool> } => todo!(),
|
||||
SetSolo { solo: Option<bool> } => todo!(),
|
||||
SetSize { size: usize } => todo!(),
|
||||
SetZoom { zoom: usize } => todo!(),
|
||||
SetName { name: Arc<str> } =>
|
||||
swap_value(&mut track.name, name, |name|Self::SetName { name }),
|
||||
SetColor { color: ItemTheme } =>
|
||||
swap_value(&mut track.color, color, |color|Self::SetColor { color }),
|
||||
SetRec { rec: Option<bool> } =>
|
||||
toggle_bool(&mut track.sequencer.recording, rec, |rec|Self::SetRec { rec }),
|
||||
SetMon { mon: Option<bool> } =>
|
||||
toggle_bool(&mut track.sequencer.monitoring, mon, |mon|Self::SetMon { mon }),
|
||||
SetRec { rec: Option<bool> } => toggle_bool(&mut track.sequencer.recording, rec, |rec|Self::SetRec { rec }),
|
||||
SetMon { mon: Option<bool> } => toggle_bool(&mut track.sequencer.monitoring, mon, |mon|Self::SetMon { mon }),
|
||||
SetMute { mute: Option<bool> } => todo!(),
|
||||
SetSolo { solo: Option<bool> } => todo!(),
|
||||
SetSize { size: usize } => todo!(),
|
||||
SetZoom { zoom: usize } => todo!(),
|
||||
SetName { name: Arc<str> } => swap_value(&mut track.name, name, |name|Self::SetName { name }),
|
||||
SetColor { color: ItemTheme } => swap_value(&mut track.color, color, |color|Self::SetColor { color }),
|
||||
});
|
||||
|
||||
impl<T: AsRef<Vec<Track>>+AsMut<Vec<Track>>> HasTracks for T {}
|
||||
impl<T: AsRefOpt<Track>+AsMutOpt<Track>+Send+Sync> HasTrack for T {}
|
||||
impl<T: ScenesView+HasMidiIns+HasMidiOuts+HasTrackScroll> TracksView for T {}
|
||||
impl<T: AsRef<Vec<Track>>+AsMut<Vec<Track>>> HasTracks for T {}
|
||||
impl<T: AsRefOpt<Track>+AsMutOpt<Track>+Send+Sync> HasTrack for T {}
|
||||
impl<T: ScenesView+HasMidiIns+HasMidiOuts+HasTrackScroll> TracksView for T {}
|
||||
impl_has!(Vec<Track>: |self: Arrangement| self.tracks);
|
||||
impl_as_ref_opt!(Track: |self: Arrangement| self.selected_track());
|
||||
impl_as_mut_opt!(Track: |self: Arrangement| self.selected_track_mut());
|
||||
impl_as_ref!(Vec<Track>: |self: App| self.project.as_ref());
|
||||
impl_as_mut!(Vec<Track>: |self: App| self.project.as_mut());
|
||||
#[cfg(feature = "select")] impl_as_ref_opt!(Track: |self: App| self.project.as_ref_opt());
|
||||
#[cfg(feature = "select")] impl_as_mut_opt!(Track: |self: App| self.project.as_mut_opt());
|
||||
impl_has!(Vec<Track>: |self: Arrangement| self.tracks);
|
||||
impl_as_ref_opt!(Track: |self: Arrangement| self.selected_track());
|
||||
impl_as_mut_opt!(Track: |self: Arrangement| self.selected_track_mut());
|
||||
|
||||
impl Arrangement {
|
||||
#[cfg(feature = "track")]
|
||||
|
||||
pub fn view_inputs (&self, _theme: ItemTheme) -> impl Draw<Tui> + '_ {
|
||||
crate::view::view_inputs(self.tracks_with_sizes(), self.midi_ins().as_slice())
|
||||
crate::view::view_inputs(
|
||||
self.tracks_with_sizes(), self.midi_ins().as_slice()
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "track")]
|
||||
pub fn view_inputs_header (&self) -> impl Draw<Tui> + '_ {
|
||||
crate::view::view_inputs_header(self.tracks_with_sizes(), self.midi_ins().as_slice())
|
||||
}
|
||||
|
||||
#[cfg(feature = "track")]
|
||||
pub fn view_inputs_row (&self, port: &MidiInput) -> impl Draw<Tui> {
|
||||
crate::view::view_inputs_row(port)
|
||||
}
|
||||
|
||||
#[cfg(feature = "track")]
|
||||
pub fn view_outputs (&self, theme: ItemTheme) -> impl Draw<Tui> {
|
||||
crate::view::view_outputs(
|
||||
theme, self.tracks_with_sizes(), self.midi_outs(), self.outputs_height()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn view_track_devices (&self, theme: ItemTheme) -> impl Draw<Tui> {
|
||||
crate::view::view_track_devices(
|
||||
theme, self.tracks_with_sizes(), self.track(), self.devices_height()
|
||||
)
|
||||
}
|
||||
|
||||
fn devices_height (&self) -> u16 {
|
||||
let mut h = 2;
|
||||
for track in self.tracks().iter() {
|
||||
h = h.max(track.devices.len() * 2);
|
||||
}
|
||||
h as u16
|
||||
}
|
||||
|
||||
fn outputs_height (&self) -> u16 {
|
||||
let mut h = 1;
|
||||
for output in self.midi_outs().iter() {
|
||||
h += 1 + output.connections.len();
|
||||
}
|
||||
let h = h as u16;
|
||||
crate::view::view_outputs(self.tracks_with_sizes())
|
||||
}
|
||||
|
||||
#[cfg(feature = "track")]
|
||||
pub fn view_track_devices (&self, theme: ItemTheme) -> impl Draw<Tui> {
|
||||
let mut h = 2u16;
|
||||
for track in self.tracks().iter() {
|
||||
h = h.max(track.devices.len() as u16 * 2);
|
||||
}
|
||||
crate::view::view_track_devices(||self.tracks_with_sizes(), self.track(), h)
|
||||
h as u16
|
||||
}
|
||||
|
||||
/// Add multiple tracks
|
||||
#[cfg(feature = "track")] pub fn tracks_add (
|
||||
&mut self,
|
||||
count: usize, width: Option<usize>,
|
||||
mins: &[Connect], mouts: &[Connect],
|
||||
pub fn tracks_add (
|
||||
&mut self, count: usize, width: Option<usize>, mins: &[Connect], mouts: &[Connect],
|
||||
) -> Usually<()> {
|
||||
let track_color_1 = ItemColor::random();
|
||||
let track_color_2 = ItemColor::random();
|
||||
|
|
@ -302,10 +297,12 @@ impl Arrangement {
|
|||
}
|
||||
|
||||
/// Add a track
|
||||
#[cfg(feature = "track")] pub fn track_add (
|
||||
pub fn track_add (
|
||||
&mut self,
|
||||
name: Option<&str>, color: Option<ItemTheme>,
|
||||
mins: &[Connect], mouts: &[Connect],
|
||||
name: Option<&str>,
|
||||
color: Option<ItemTheme>,
|
||||
mins: &[Connect],
|
||||
mouts: &[Connect],
|
||||
) -> Usually<(usize, &mut Track)> {
|
||||
let name: Arc<str> = name.map_or_else(
|
||||
||format!("trk{:02}", self.track_last).into(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue