mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-02-01 08:36:42 +01:00
Compare commits
No commits in common. "0f16c89248bc2289760bd10b6e3b82528cbbdf3d" and "fa73821a0b6766b6f1b1810cb8f79205849f87a0" have entirely different histories.
0f16c89248
...
fa73821a0b
54 changed files with 2272 additions and 2491 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2315,7 +2315,6 @@ dependencies = [
|
||||||
"jack",
|
"jack",
|
||||||
"midly",
|
"midly",
|
||||||
"tengri",
|
"tengri",
|
||||||
"tengri_proc",
|
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@
|
||||||
(keys
|
(keys
|
||||||
(layer-if :focus-message "./keys_message.edn")
|
(layer-if :focus-message "./keys_message.edn")
|
||||||
(layer-if :focus-device-add "./keys_device_add.edn")
|
(layer-if :focus-device-add "./keys_device_add.edn")
|
||||||
(layer-if :focus-browser "./keys_browser.edn")
|
(layer-if :focus-browser "./keys_browser")
|
||||||
(layer-if :focus-pool-rename "./keys_rename.edn")
|
(layer-if :focus-pool-rename "./keys_rename.edn")
|
||||||
(layer-if :focus-pool-length "./keys_length.edn")
|
(layer-if :focus-pool-length "./keys_length.edn")
|
||||||
|
(layer "./keys_global.edn")
|
||||||
(layer-if :focus-editor "./keys_editor.edn")
|
(layer-if :focus-editor "./keys_editor.edn")
|
||||||
(layer-if :focus-clip "./keys_clip.edn")
|
(layer-if :focus-clip "./keys_clip.edn")
|
||||||
(layer-if :focus-track "./keys_track.edn")
|
(layer-if :focus-track "./keys_track.edn")
|
||||||
(layer-if :focus-scene "./keys_scene.edn")
|
(layer-if :focus-scene "./keys_scene.edn")
|
||||||
(layer-if :focus-mix "./keys_mix.edn")
|
(layer-if :focus-mix "./keys_mix.edn")
|
||||||
(layer "./keys_clock.edn")
|
(layer "./keys_clock.edn")
|
||||||
(layer "./keys_arranger.edn")
|
(layer "./keys_arranger.edn"))
|
||||||
(layer "./keys_global.edn"))
|
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,22 @@
|
||||||
(info "A sequencer with built-in sampler.")
|
(info "A sequencer with built-in sampler.")
|
||||||
|
|
||||||
(view
|
(view
|
||||||
(bsp/a :view-dialog
|
(bsp/a :view-dialog
|
||||||
(bsp/s (fixed/y 1 :view-transport)
|
(bsp/s (fixed/y 1 :view-transport)
|
||||||
(bsp/n (fixed/y 1 :view-status)
|
(bsp/n (fixed/y 1 :view-status)
|
||||||
(bsp/w :view-meters-output
|
(bsp/w :view-meters-output
|
||||||
(bsp/e :view-meters-input
|
(bsp/e :view-meters-input
|
||||||
(bsp/n :view-sample-info
|
(bsp/n :view-sample-info
|
||||||
(bsp/n (fixed/y 5 :view-sample-viewer)
|
(bsp/n (fixed/y 5 :view-sample-viewer)
|
||||||
(bsp/w :view-pool
|
(bsp/w (fixed/x :w-sidebar :view-pool)
|
||||||
(bsp/e :view-samples-keys
|
(bsp/e :view-samples-keys
|
||||||
(fill/y :view-editor)))))))))))
|
(fill/y :view-editor)))))))))))
|
||||||
|
|
||||||
(keys
|
(keys
|
||||||
(layer-if :focus-browser "./keys_browser.edn")
|
(layer-if :focus-browser "./keys_browser")
|
||||||
(layer-if :focus-pool-rename "./keys_rename.edn")
|
(layer-if :focus-pool-rename "./keys_rename.edn")
|
||||||
(layer-if :focus-pool-length "./keys_length.edn")
|
(layer-if :focus-pool-length "./keys_length.edn")
|
||||||
|
(layer "./keys_global.edn")
|
||||||
(layer "./keys_clock.edn")
|
(layer "./keys_clock.edn")
|
||||||
(layer "./keys_editor.edn")
|
(layer "./keys_editor.edn")
|
||||||
(layer "./keys_sampler.edn")
|
(layer "./keys_sampler.edn"))
|
||||||
(layer "./keys_global.edn"))
|
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,5 @@
|
||||||
(fill/xy :view-samples-grid)))))
|
(fill/xy :view-samples-grid)))))
|
||||||
|
|
||||||
(keys
|
(keys
|
||||||
(layer "./keys_sampler.edn")
|
(layer "./keys_global.edn")
|
||||||
(layer "./keys_global.edn"))
|
(layer "./keys_sampler.edn"))
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,10 @@
|
||||||
:view-editor)))))
|
:view-editor)))))
|
||||||
|
|
||||||
(keys
|
(keys
|
||||||
(layer-if :focus-browser "./keys_browser.edn")
|
(layer-if :focus-browser "./keys_browser")
|
||||||
(layer-if :mode-pool-rename "./keys_rename.edn")
|
(layer-if :mode-pool-rename "./keys_rename.edn")
|
||||||
(layer-if :mode-pool-length "./keys_length.edn")
|
(layer-if :mode-pool-length "./keys_length.edn")
|
||||||
|
(layer "./keys_global.edn")
|
||||||
(layer "./keys_editor.edn")
|
(layer "./keys_editor.edn")
|
||||||
(layer "./keys_clock.edn")
|
(layer "./keys_clock.edn")
|
||||||
(layer "./keys_global.edn"))
|
(layer "./keys_arranger.edn"))
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@
|
||||||
(view :view-transport)
|
(view :view-transport)
|
||||||
|
|
||||||
(keys
|
(keys
|
||||||
(layer "./keys_clock.edn")
|
(layer "./keys_global.edn")
|
||||||
(layer "./keys_global.edn"))
|
(layer "./keys_clock.edn"))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
(@shift-O output add)
|
(@shift-O output add)
|
||||||
(@shift-S scene add)
|
(@shift-S scene add)
|
||||||
(@shift-T track add)
|
(@shift-T track add)
|
||||||
(@shift-D toggle-dialog :dialog-device)
|
(@shift-D device picker)
|
||||||
|
|
||||||
(@up select :select-scene-prev)
|
(@up select :select-scene-prev)
|
||||||
(@down select :select-scene-next)
|
(@down select :select-scene-next)
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
(@up toggle-dialog :dialog-device-prev)
|
(@up device pick :device-kind-prev)
|
||||||
(@down toggle-dialog :dialog-device-next)
|
(@down device pick :device-kind-next)
|
||||||
|
(@enter device add :device-kind)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
(@esc dialog :dialog-none)
|
(@esc cancel-dialog)
|
||||||
(@f1 dialog :dialog-help)
|
(@f1 toggle-dialog :dialog-help)
|
||||||
(@f6 dialog :dialog-save)
|
(@f6 toggle-dialog :dialog-save)
|
||||||
(@f8 dialog :dialog-options)
|
(@f8 toggle-dialog :dialog-options)
|
||||||
(@f9 dialog :dialog-load)
|
(@f9 toggle-dialog :dialog-load)
|
||||||
(@f10 dialog :dialog-quit)
|
(@f10 toggle-dialog :dialog-quit)
|
||||||
|
|
||||||
(@u undo 1)
|
(@u undo 1)
|
||||||
(@r redo 1)
|
(@r redo 1)
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,176 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
|
||||||
None
|
None
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
#[tengri_proc::expose] impl App {
|
||||||
|
fn _todo_isize_stub (&self) -> isize {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn _todo_item_theme_stub (&self) -> ItemTheme {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn focus_editor (&self) -> bool {
|
||||||
|
self.is_editing()
|
||||||
|
}
|
||||||
|
fn focus_message (&self) -> bool {
|
||||||
|
matches!(self.dialog, Some(Dialog::Message(..)))
|
||||||
|
}
|
||||||
|
fn focus_device_add (&self) -> bool {
|
||||||
|
matches!(self.dialog, Some(Dialog::Device(..)))
|
||||||
|
}
|
||||||
|
fn focus_clip (&self) -> bool {
|
||||||
|
!self.is_editing() && self.selected.is_clip()
|
||||||
|
}
|
||||||
|
fn focus_track (&self) -> bool {
|
||||||
|
!self.is_editing() && self.selected.is_track()
|
||||||
|
}
|
||||||
|
fn focus_scene (&self) -> bool {
|
||||||
|
!self.is_editing() && self.selected.is_scene()
|
||||||
|
}
|
||||||
|
fn focus_mix (&self) -> bool {
|
||||||
|
!self.is_editing() && self.selected.is_mix()
|
||||||
|
}
|
||||||
|
fn focus_pool_import (&self) -> bool {
|
||||||
|
matches!(self.pool.as_ref().map(|p|p.mode.as_ref()).flatten(), Some(PoolMode::Import(..)))
|
||||||
|
}
|
||||||
|
fn focus_pool_export (&self) -> bool {
|
||||||
|
matches!(self.pool.as_ref().map(|p|p.mode.as_ref()).flatten(), Some(PoolMode::Export(..)))
|
||||||
|
}
|
||||||
|
fn focus_pool_rename (&self) -> bool {
|
||||||
|
matches!(self.pool.as_ref().map(|p|p.mode.as_ref()).flatten(), Some(PoolMode::Rename(..)))
|
||||||
|
}
|
||||||
|
fn focus_pool_length (&self) -> bool {
|
||||||
|
matches!(self.pool.as_ref().map(|p|p.mode.as_ref()).flatten(), Some(PoolMode::Length(..)))
|
||||||
|
}
|
||||||
|
fn dialog_help (&self) -> Dialog {
|
||||||
|
Dialog::Help
|
||||||
|
}
|
||||||
|
fn dialog_menu (&self) -> Dialog {
|
||||||
|
Dialog::Menu
|
||||||
|
}
|
||||||
|
fn dialog_save (&self) -> Dialog {
|
||||||
|
Dialog::Save
|
||||||
|
}
|
||||||
|
fn dialog_load (&self) -> Dialog {
|
||||||
|
Dialog::Load
|
||||||
|
}
|
||||||
|
fn dialog_options (&self) -> Dialog {
|
||||||
|
Dialog::Options
|
||||||
|
}
|
||||||
|
fn editor_pitch (&self) -> Option<u7> {
|
||||||
|
Some((self.editor().map(|e|e.get_note_pos()).unwrap() as u8).into())
|
||||||
|
}
|
||||||
|
/// Width of display
|
||||||
|
pub(crate) fn w (&self) -> u16 {
|
||||||
|
self.size.w() as u16
|
||||||
|
}
|
||||||
|
/// Width allocated for sidebar.
|
||||||
|
pub(crate) fn w_sidebar (&self) -> u16 {
|
||||||
|
self.w() / if self.is_editing() { 16 } else { 8 } as u16
|
||||||
|
}
|
||||||
|
/// Width taken by all tracks.
|
||||||
|
pub(crate) fn w_tracks (&self) -> u16 {
|
||||||
|
self.tracks_with_sizes().last().map(|(_, _, _, x)|x as u16).unwrap_or(0)
|
||||||
|
}
|
||||||
|
/// Width available to display tracks.
|
||||||
|
pub(crate) fn w_tracks_area (&self) -> u16 {
|
||||||
|
self.w().saturating_sub(2 * self.w_sidebar())
|
||||||
|
}
|
||||||
|
/// Height of display
|
||||||
|
pub(crate) fn h (&self) -> u16 {
|
||||||
|
self.size.h() as u16
|
||||||
|
}
|
||||||
|
/// Height available to display track headers.
|
||||||
|
pub(crate) fn h_tracks_area (&self) -> u16 {
|
||||||
|
5 // FIXME
|
||||||
|
//self.h().saturating_sub(self.h_inputs() + self.h_outputs())
|
||||||
|
}
|
||||||
|
/// Height available to display tracks.
|
||||||
|
pub(crate) fn h_scenes_area (&self) -> u16 {
|
||||||
|
//15
|
||||||
|
self.h().saturating_sub(
|
||||||
|
self.h_inputs() +
|
||||||
|
self.h_outputs() +
|
||||||
|
self.h_devices() +
|
||||||
|
13 // FIXME
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/// Height taken by all scenes.
|
||||||
|
pub(crate) fn h_scenes (&self) -> u16 {
|
||||||
|
self.scenes_with_sizes(self.is_editing(), Self::H_SCENE, Self::H_EDITOR).last()
|
||||||
|
.map(|(_, _, _, y)|y as u16).unwrap_or(0)
|
||||||
|
}
|
||||||
|
/// Height taken by all inputs.
|
||||||
|
pub(crate) fn h_inputs (&self) -> u16 {
|
||||||
|
self.inputs_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
||||||
|
}
|
||||||
|
/// Height taken by all outputs.
|
||||||
|
pub(crate) fn h_outputs (&self) -> u16 {
|
||||||
|
self.outputs_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
||||||
|
}
|
||||||
|
/// Height taken by visible device slots.
|
||||||
|
pub(crate) fn h_devices (&self) -> u16 {
|
||||||
|
2
|
||||||
|
//1 + self.devices_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
||||||
|
}
|
||||||
|
fn scene_count (&self) -> usize {
|
||||||
|
self.scenes.len()
|
||||||
|
}
|
||||||
|
fn scene_selected (&self) -> Option<usize> {
|
||||||
|
self.selected.scene()
|
||||||
|
}
|
||||||
|
fn track_count (&self) -> usize {
|
||||||
|
self.tracks.len()
|
||||||
|
}
|
||||||
|
fn track_selected (&self) -> Option<usize> {
|
||||||
|
self.selected.track()
|
||||||
|
}
|
||||||
|
fn select_scene_next (&self) -> Selection {
|
||||||
|
self.selected.scene_next(self.scenes.len())
|
||||||
|
}
|
||||||
|
fn select_scene_prev (&self) -> Selection {
|
||||||
|
self.selected.scene_prev()
|
||||||
|
}
|
||||||
|
fn select_track_header (&self) -> Selection {
|
||||||
|
self.selected.track_header(self.tracks.len())
|
||||||
|
}
|
||||||
|
fn select_track_next (&self) -> Selection {
|
||||||
|
self.selected.track_next(self.tracks.len())
|
||||||
|
}
|
||||||
|
fn select_track_prev (&self) -> Selection {
|
||||||
|
self.selected.track_prev()
|
||||||
|
}
|
||||||
|
fn clip_selected (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
||||||
|
match self.selected {
|
||||||
|
Selection::TrackClip { track, scene } => self.scenes[scene].clips[track].clone(),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn device_kind (&self) -> usize {
|
||||||
|
if let Some(Dialog::Device(index)) = self.dialog {
|
||||||
|
index
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn device_kind_prev (&self) -> usize {
|
||||||
|
if let Some(Dialog::Device(index)) = self.dialog {
|
||||||
|
index.overflowing_sub(1).0.min(self.device_kinds().len().saturating_sub(1))
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn device_kind_next (&self) -> usize {
|
||||||
|
if let Some(Dialog::Device(index)) = self.dialog {
|
||||||
|
(index + 1) % self.device_kinds().len()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tengri_proc::command(App)] impl AppCommand {
|
#[tengri_proc::command(App)] impl AppCommand {
|
||||||
fn dialog (app: &mut App, dialog: Option<Dialog>) -> Perhaps<Self> {
|
fn toggle_dialog (app: &mut App, dialog: Dialog) -> Perhaps<Self> {
|
||||||
app.toggle_dialog(dialog);
|
app.toggle_dialog(Some(dialog));
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
fn cancel_dialog (app: &mut App) -> Perhaps<Self> {
|
fn cancel_dialog (app: &mut App) -> Perhaps<Self> {
|
||||||
|
|
@ -30,9 +197,9 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
|
||||||
app.toggle_editor(Some(value));
|
app.toggle_editor(Some(value));
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
//fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
|
fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
|
||||||
//Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
|
Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
|
||||||
//}
|
}
|
||||||
fn enqueue (app: &mut App, clip: Option<Arc<RwLock<MidiClip>>>) -> Perhaps<Self> {
|
fn enqueue (app: &mut App, clip: Option<Arc<RwLock<MidiClip>>>) -> Perhaps<Self> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
@ -42,47 +209,49 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
|
||||||
fn zoom (app: &mut App, zoom: usize) -> Perhaps<Self> {
|
fn zoom (app: &mut App, zoom: usize) -> Perhaps<Self> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
//fn launch (app: &mut App) -> Perhaps<Self> {
|
fn launch (app: &mut App) -> Perhaps<Self> {
|
||||||
//app.project.launch();
|
app.launch();
|
||||||
//Ok(None)
|
Ok(None)
|
||||||
//}
|
}
|
||||||
fn select (app: &mut App, selection: Selection) -> Perhaps<Self> {
|
fn select (app: &mut App, selection: Selection) -> Perhaps<Self> {
|
||||||
*app.project.selection_mut() = selection;
|
app.select(selection);
|
||||||
if let Some(ref mut editor) = app.editor {
|
|
||||||
editor.set_clip(match app.project.selection() {
|
|
||||||
Selection::TrackClip { track, scene } if let Some(Some(Some(clip))) = app
|
|
||||||
.project
|
|
||||||
.scenes.get(*scene)
|
|
||||||
.map(|s|s.clips.get(*track))
|
|
||||||
=>
|
|
||||||
Some(clip),
|
|
||||||
_ =>
|
|
||||||
None
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
//("select" [t: usize, s: usize] Some(match (t.expect("no track"), s.expect("no scene")) {
|
//("select" [t: usize, s: usize] Some(match (t.expect("no track"), s.expect("no scene")) {
|
||||||
//(0, 0) => Self::Select(Selection::Mix),
|
//(0, 0) => Self::Select(Selection::Mix),
|
||||||
//(t, 0) => Self::Select(Selection::Track(t)),
|
//(t, 0) => Self::Select(Selection::Track(t)),
|
||||||
//(0, s) => Self::Select(Selection::Scene(s)),
|
//(0, s) => Self::Select(Selection::Scene(s)),
|
||||||
//(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
|
//(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
|
||||||
// autoedit: load focused clip in editor.
|
|
||||||
}
|
}
|
||||||
fn stop_all (app: &mut App) -> Perhaps<Self> {
|
fn stop_all (app: &mut App) -> Perhaps<Self> {
|
||||||
app.tracks_stop_all();
|
app.stop_all();
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
fn sampler (app: &mut App, command: SamplerCommand) -> Perhaps<Self> {
|
fn sampler (app: &mut App, command: SamplerCommand) -> Perhaps<Self> {
|
||||||
Ok(app.project.sampler_mut()
|
Ok(app.sampler_mut()
|
||||||
.map(|s|command.delegate(s, |command|Self::Sampler{command}))
|
.map(|s|command.delegate(s, |command|Self::Sampler{command}))
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.flatten())
|
.flatten())
|
||||||
}
|
}
|
||||||
fn project (app: &mut App, command: ArrangementCommand) -> Perhaps<Self> {
|
fn scene (app: &mut App, command: SceneCommand) -> Perhaps<Self> {
|
||||||
Ok(command.delegate(&mut app.project, |command|Self::Project{command})?)
|
Ok(command.delegate(app, |command|Self::Scene{command})?)
|
||||||
|
}
|
||||||
|
fn track (app: &mut App, command: TrackCommand) -> Perhaps<Self> {
|
||||||
|
Ok(command.delegate(app, |command|Self::Track{command})?)
|
||||||
|
}
|
||||||
|
fn input (app: &mut App, command: InputCommand) -> Perhaps<Self> {
|
||||||
|
Ok(command.delegate(app, |command|Self::Input{command})?)
|
||||||
|
}
|
||||||
|
fn output (app: &mut App, command: OutputCommand) -> Perhaps<Self> {
|
||||||
|
Ok(command.delegate(app, |command|Self::Output{command})?)
|
||||||
|
}
|
||||||
|
fn clip (app: &mut App, command: ClipCommand) -> Perhaps<Self> {
|
||||||
|
Ok(command.delegate(app, |command|Self::Clip{command})?)
|
||||||
}
|
}
|
||||||
fn clock (app: &mut App, command: ClockCommand) -> Perhaps<Self> {
|
fn clock (app: &mut App, command: ClockCommand) -> Perhaps<Self> {
|
||||||
Ok(command.execute(app.clock_mut())?.map(|command|Self::Clock{command}))
|
Ok(command.execute(&mut app.clock)?.map(|command|Self::Clock{command}))
|
||||||
|
}
|
||||||
|
fn device (app: &mut App, command: DeviceCommand) -> Perhaps<Self> {
|
||||||
|
Ok(command.delegate(app, |command|Self::Device{command})?)
|
||||||
}
|
}
|
||||||
fn message (app: &mut App, command: MessageCommand) -> Perhaps<Self> {
|
fn message (app: &mut App, command: MessageCommand) -> Perhaps<Self> {
|
||||||
Ok(command.delegate(app, |command|Self::Message{command})?)
|
Ok(command.delegate(app, |command|Self::Message{command})?)
|
||||||
|
|
@ -91,7 +260,7 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
|
||||||
Ok(if let Some(editor) = app.editor.as_mut() {
|
Ok(if let Some(editor) = app.editor.as_mut() {
|
||||||
let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?;
|
let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?;
|
||||||
// update linked sampler after editor action
|
// update linked sampler after editor action
|
||||||
app.project.sampler_mut().map(|sampler|match command {
|
app.sampler_mut().map(|sampler|match command {
|
||||||
// autoselect: automatically select sample in sampler
|
// autoselect: automatically select sample in sampler
|
||||||
MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
|
MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
@ -102,26 +271,27 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn pool (app: &mut App, command: PoolCommand) -> Perhaps<Self> {
|
fn pool (app: &mut App, command: PoolCommand) -> Perhaps<Self> {
|
||||||
let undo = command.clone().delegate(
|
Ok(if let Some(pool) = app.pool.as_mut() {
|
||||||
&mut app.project.pool,
|
let undo = command.clone().delegate(pool, |command|AppCommand::Pool{command})?;
|
||||||
|command|AppCommand::Pool{command}
|
// update linked editor after pool action
|
||||||
)?;
|
app.editor.as_mut().map(|editor|match command {
|
||||||
// update linked editor after pool action
|
// autoselect: automatically load selected clip in editor
|
||||||
app.editor.as_mut().map(|editor|match command {
|
PoolCommand::Select { .. } |
|
||||||
// autoselect: automatically load selected clip in editor
|
// autocolor: update color in all places simultaneously
|
||||||
PoolCommand::Select { .. } |
|
PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } =>
|
||||||
// autocolor: update color in all places simultaneously
|
editor.set_clip(pool.clip().as_ref()),
|
||||||
PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } =>
|
_ => {}
|
||||||
editor.set_clip(app.project.pool.clip().as_ref()),
|
});
|
||||||
_ => {}
|
undo
|
||||||
});
|
} else {
|
||||||
Ok(undo)
|
None
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'state> Context<'state, ClockCommand> for App {
|
impl<'state> Context<'state, ClockCommand> for App {
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<ClockCommand> {
|
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<ClockCommand> {
|
||||||
Context::get(&self.clock(), iter)
|
Context::get(&self.clock, iter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,25 +303,160 @@ impl<'state> Context<'state, MidiEditCommand> for App {
|
||||||
|
|
||||||
impl<'state> Context<'state, PoolCommand> for App {
|
impl<'state> Context<'state, PoolCommand> for App {
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<PoolCommand> {
|
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<PoolCommand> {
|
||||||
Context::get(&self.project.pool, iter)
|
self.pool().map(|p|Context::get(p, iter)).flatten()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'state> Context<'state, SamplerCommand> for App {
|
impl<'state> Context<'state, SamplerCommand> for App {
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<SamplerCommand> {
|
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<SamplerCommand> {
|
||||||
self.project.sampler().map(|p|Context::get(p, iter)).flatten()
|
self.sampler().map(|p|Context::get(p, iter)).flatten()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'state> Context<'state, ArrangementCommand> for App {
|
#[tengri_proc::command(App)] impl InputCommand {
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<ArrangementCommand> {
|
fn add (app: &mut App) -> Perhaps<Self> {
|
||||||
Context::get(&self.project, iter)
|
app.midi_in_add()?;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tengri_proc::command(App)] impl OutputCommand {
|
||||||
|
fn add (app: &mut App) -> Perhaps<Self> {
|
||||||
|
app.midi_out_add()?;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tengri_proc::command(App)] impl DeviceCommand {
|
||||||
|
fn cancel (app: &mut App) -> Perhaps<Self> {
|
||||||
|
app.dialog = None;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn picker (app: &mut App) -> Perhaps<Self> {
|
||||||
|
app.device_picker_show();
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn pick (app: &mut App, i: usize) -> Perhaps<Self> {
|
||||||
|
app.device_pick(i);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn add (app: &mut App, i: usize) -> Perhaps<Self> {
|
||||||
|
app.device_add(i);
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tengri_proc::command(App)] impl MessageCommand {
|
#[tengri_proc::command(App)] impl MessageCommand {
|
||||||
fn dismiss (app: &mut App) -> Perhaps<Self> {
|
fn dismiss (app: &mut App) -> Perhaps<Self> {
|
||||||
app.dialog = None;
|
app.message_dismiss();
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tengri_proc::command(App)] impl TrackCommand {
|
||||||
|
fn toggle_play (app: &mut App) -> Perhaps<Self> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn toggle_solo (app: &mut App) -> Perhaps<Self> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn toggle_rec (app: &mut App) -> Perhaps<Self> {
|
||||||
|
app.track_toggle_record();
|
||||||
|
Ok(Some(Self::ToggleRec))
|
||||||
|
}
|
||||||
|
fn toggle_mon (app: &mut App) -> Perhaps<Self> {
|
||||||
|
app.track_toggle_monitor();
|
||||||
|
Ok(Some(Self::ToggleMon))
|
||||||
|
}
|
||||||
|
fn set_size (app: &mut App, size: usize) -> Perhaps<Self> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn set_zoom (app: &mut App, zoom: usize) -> Perhaps<Self> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn swap (app: &mut App, index: usize, other: usize) -> Perhaps<Self> {
|
||||||
|
todo!();
|
||||||
|
Ok(Some(Self::Swap { index, other }))
|
||||||
|
}
|
||||||
|
fn del (app: &mut App, index: usize) -> Perhaps<Self> {
|
||||||
|
app.track_del(index);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn stop (app: &mut App, index: usize) -> Perhaps<Self> {
|
||||||
|
app.tracks[index].sequencer.enqueue_next(None);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn add (app: &mut App) -> Perhaps<Self> {
|
||||||
|
Ok(Some(Self::Del { index: app.track_add_focus()? }))
|
||||||
|
}
|
||||||
|
fn set_color (app: &mut App, index: usize, color: ItemTheme) -> Perhaps<Self> {
|
||||||
|
Ok(Some(Self::SetColor { index, color: app.track_set_color(index, color) }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tengri_proc::command(App)] impl SceneCommand {
|
||||||
|
fn add (app: &mut App) -> Perhaps<Self> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn del (app: &mut App, index: usize) -> Perhaps<Self> {
|
||||||
|
app.scene_del(index);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn enqueue (app: &mut App, index: usize) -> Perhaps<Self> {
|
||||||
|
app.scene_enqueue(index);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn set_color (app: &mut App, index: usize, color: ItemTheme) -> Perhaps<Self> {
|
||||||
|
Ok(Some(Self::SetColor { index, color: app.scene_set_color(index, color) }))
|
||||||
|
}
|
||||||
|
fn set_size (app: &mut App, index: usize, size: usize) -> Perhaps<Self> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn set_zoom (app: &mut App, index: usize, zoom: usize) -> Perhaps<Self> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn swap (app: &mut App, index: usize, other: usize) -> Perhaps<Self> {
|
||||||
|
todo!();
|
||||||
|
Ok(Some(Self::Swap { index, other }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tengri_proc::command(App)] impl ClipCommand {
|
||||||
|
fn get (app: &mut App, a: usize, b: usize) -> Perhaps<Self> {
|
||||||
|
//(Get [a: usize, b: usize] cmd_todo!("\n\rtodo: clip: get: {a} {b}"))
|
||||||
|
//("get" [a: usize, b: usize] Some(Self::Get(a.unwrap(), b.unwrap())))
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn edit (app: &mut App, a: usize, b: usize) -> Perhaps<Self> {
|
||||||
|
//(Edit [clip: MaybeClip] cmd_todo!("\n\rtodo: clip: edit: {clip:?}"))
|
||||||
|
//("edit" [a: MaybeClip] Some(Self::Edit(a.unwrap())))
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn set_loop (app: &mut App, a: usize, b: usize) -> Perhaps<Self> {
|
||||||
|
//(SetLoop [t: usize, s: usize, l: bool] cmd_todo!("\n\rtodo: {self:?}"))
|
||||||
|
//("loop" [a: usize, b: usize, c: bool] Some(Self::SetLoop(a.unwrap(), b.unwrap(), c.unwrap())))
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn put (app: &mut App, a: usize, b: usize) -> Perhaps<Self> {
|
||||||
|
//(Put [t: usize, s: usize, c: MaybeClip]
|
||||||
|
//Some(Self::Put(t, s, app.clip_put(t, s, c))))
|
||||||
|
//("put" [a: usize, b: usize, c: MaybeClip] Some(Self::Put(a.unwrap(), b.unwrap(), c.unwrap())))
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn del (app: &mut App, a: usize, b: usize) -> Perhaps<Self> {
|
||||||
|
//("delete" [a: usize, b: usize] Some(Self::Put(a.unwrap(), b.unwrap(), None))))
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn enqueue (app: &mut App, a: usize, b: usize) -> Perhaps<Self> {
|
||||||
|
//(Enqueue [t: usize, s: usize]
|
||||||
|
//cmd!(app.tracks[t].sequencer.enqueue_next(app.scenes[s].clips[t].as_ref())))
|
||||||
|
//("enqueue" [a: usize, b: usize] Some(Self::Enqueue(a.unwrap(), b.unwrap())))
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn set_color (app: &mut App, a: usize, b: usize) -> Perhaps<Self> {
|
||||||
|
//(SetColor [t: usize, s: usize, c: ItemTheme]
|
||||||
|
//app.clip_set_color(t, s, c).map(|o|Self::SetColor(t, s, o)))));
|
||||||
|
//("color" [a: usize, b: usize] Some(Self::SetColor(a.unwrap(), b.unwrap(), ItemTheme::random())))
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,32 +4,16 @@ audio!(
|
||||||
|self: App, client, scope|{
|
|self: App, client, scope|{
|
||||||
let t0 = self.perf.get_t0();
|
let t0 = self.perf.get_t0();
|
||||||
self.clock().update_from_scope(scope).unwrap();
|
self.clock().update_from_scope(scope).unwrap();
|
||||||
let midi_in = self.project.midi_input_collect(scope);
|
let midi_in = self.collect_midi_input(scope);
|
||||||
if let Some(editor) = &self.editor {
|
self.update_editor_cursor(&midi_in);
|
||||||
let mut pitch: Option<u7> = None;
|
let result = self.render_tracks(client, scope);
|
||||||
for port in midi_in.iter() {
|
|
||||||
for event in port.iter() {
|
|
||||||
if let (_, Ok(LiveEvent::Midi {message: MidiMessage::NoteOn {ref key, ..}, ..}))
|
|
||||||
= event
|
|
||||||
{
|
|
||||||
pitch = Some(key.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(pitch) = pitch {
|
|
||||||
editor.set_note_pos(pitch.as_int() as usize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let result = self.project.process_tracks(client, scope);
|
|
||||||
self.perf.update_from_jack_scope(t0, scope);
|
self.perf.update_from_jack_scope(t0, scope);
|
||||||
result
|
result
|
||||||
};
|
};
|
||||||
|self, event|{
|
|self, event|{
|
||||||
use JackEvent::*;
|
use JackEvent::*;
|
||||||
match event {
|
match event {
|
||||||
SampleRate(sr) => {
|
SampleRate(sr) => { self.clock.timebase.sr.set(sr as f64); },
|
||||||
self.clock().timebase.sr.set(sr as f64);
|
|
||||||
},
|
|
||||||
PortRegistration(id, true) => {
|
PortRegistration(id, true) => {
|
||||||
//let port = self.jack().port_by_id(id);
|
//let port = self.jack().port_by_id(id);
|
||||||
//println!("\rport add: {id} {port:?}");
|
//println!("\rport add: {id} {port:?}");
|
||||||
|
|
@ -49,3 +33,60 @@ audio!(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
type CollectedMidiInput<'a> = Vec<Vec<(u32, Result<LiveEvent<'a>, MidiError>)>>;
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
|
||||||
|
/// Collect MIDI input from app ports (TODO preallocate large buffers)
|
||||||
|
fn collect_midi_input <'a> (&'a self, scope: &'a ProcessScope) -> CollectedMidiInput<'a> {
|
||||||
|
self.midi_ins.iter()
|
||||||
|
.map(|port|port.port().iter(scope)
|
||||||
|
.map(|RawMidi { time, bytes }|(time, LiveEvent::parse(bytes)))
|
||||||
|
.collect::<Vec<_>>())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update cursor in MIDI editor
|
||||||
|
fn update_editor_cursor (&self, midi_in: &CollectedMidiInput) {
|
||||||
|
if let Some(editor) = &self.editor {
|
||||||
|
let mut pitch: Option<u7> = None;
|
||||||
|
for port in midi_in.iter() {
|
||||||
|
for event in port.iter() {
|
||||||
|
if let (_, Ok(LiveEvent::Midi {message: MidiMessage::NoteOn {ref key, ..}, ..}))
|
||||||
|
= event
|
||||||
|
{
|
||||||
|
pitch = Some(key.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(pitch) = pitch {
|
||||||
|
editor.set_note_pos(pitch.as_int() as usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run audio callbacks for every track and every device
|
||||||
|
fn render_tracks (&mut self, client: &Client, scope: &ProcessScope) -> Control {
|
||||||
|
for track in self.tracks.iter_mut() {
|
||||||
|
if Control::Quit == PlayerAudio(
|
||||||
|
track.sequencer_mut(), &mut self.note_buf, &mut self.midi_buf
|
||||||
|
).process(client, scope) {
|
||||||
|
return Control::Quit
|
||||||
|
}
|
||||||
|
for device in track.devices.iter_mut() {
|
||||||
|
if Control::Quit == DeviceAudio(device).process(client, scope) {
|
||||||
|
return Control::Quit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Control::Continue
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasJack for App {
|
||||||
|
fn jack (&self) -> &Jack {
|
||||||
|
&self.jack
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,12 @@
|
||||||
#![feature(type_changing_struct_update)]
|
#![feature(type_changing_struct_update)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(closure_lifetime_binder)]
|
#![feature(closure_lifetime_binder)]
|
||||||
|
/// Standard result type.
|
||||||
|
pub type Usually<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||||
|
/// Standard optional result type.
|
||||||
|
pub type Perhaps<T> = std::result::Result<Option<T>, Box<dyn std::error::Error>>;
|
||||||
pub use ::tek_engine:: *;
|
pub use ::tek_engine:: *;
|
||||||
pub use ::tek_device::{self, *};
|
pub use ::tek_device::{self, *};
|
||||||
pub use ::tengri::{Usually, Perhaps, Has};
|
|
||||||
pub use ::tengri::dsl::*;
|
pub use ::tengri::dsl::*;
|
||||||
pub use ::tengri::input::*;
|
pub use ::tengri::input::*;
|
||||||
pub use ::tengri::output::*;
|
pub use ::tengri::output::*;
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,451 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
mod dialog; pub use self::dialog::*;
|
||||||
|
mod pool; pub use self::pool::*;
|
||||||
|
mod selection; pub use self::selection::*;
|
||||||
|
mod track; pub use self::track::*;
|
||||||
|
mod scene; pub use self::scene::*;
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
/// Must not be dropped for the duration of the process
|
/// Must not be dropped for the duration of the process
|
||||||
pub jack: Jack,
|
pub jack: Jack,
|
||||||
/// Port handles
|
/// Source of time
|
||||||
pub ports: std::collections::BTreeMap<u32, Port<Unowned>>,
|
pub clock: Clock,
|
||||||
|
/// Theme
|
||||||
|
pub color: ItemTheme,
|
||||||
|
/// Contains all clips in the project
|
||||||
|
pub pool: Option<Pool>,
|
||||||
|
/// Contains the currently edited MIDI clip
|
||||||
|
pub editor: Option<MidiEditor>,
|
||||||
|
/// Contains a render of the project arrangement, redrawn on update.
|
||||||
|
pub arranger: Arc<RwLock<Buffer>>,
|
||||||
|
/// List of global midi inputs
|
||||||
|
pub midi_ins: Vec<JackMidiIn>,
|
||||||
|
/// List of global midi outputs
|
||||||
|
pub midi_outs: Vec<JackMidiOut>,
|
||||||
|
/// List of global audio inputs
|
||||||
|
pub audio_ins: Vec<JackAudioIn>,
|
||||||
|
/// List of global audio outputs
|
||||||
|
pub audio_outs: Vec<JackAudioOut>,
|
||||||
|
/// Buffer for writing a midi event
|
||||||
|
pub note_buf: Vec<u8>,
|
||||||
|
/// Buffer for writing a chunk of midi events
|
||||||
|
pub midi_buf: Vec<Vec<Vec<u8>>>,
|
||||||
|
/// Last track number (to avoid duplicate port names)
|
||||||
|
pub track_last: usize,
|
||||||
|
/// List of tracks
|
||||||
|
pub tracks: Vec<Track>,
|
||||||
|
/// Scroll offset of tracks
|
||||||
|
pub track_scroll: usize,
|
||||||
|
/// List of scenes
|
||||||
|
pub scenes: Vec<Scene>,
|
||||||
|
/// Scroll offset of scenes
|
||||||
|
pub scene_scroll: usize,
|
||||||
|
/// Selected UI element
|
||||||
|
pub selected: Selection,
|
||||||
/// Display size
|
/// Display size
|
||||||
pub size: Measure<TuiOut>,
|
pub size: Measure<TuiOut>,
|
||||||
/// Performance counter
|
/// Performance counter
|
||||||
pub perf: PerfModel,
|
pub perf: PerfModel,
|
||||||
|
/// Whether in edit mode
|
||||||
// View and input definition
|
pub editing: AtomicBool,
|
||||||
pub config: Configuration,
|
|
||||||
/// Contains the currently edited musical arrangement
|
|
||||||
pub project: Arrangement,
|
|
||||||
/// Undo history
|
/// Undo history
|
||||||
pub history: Vec<AppCommand>,
|
pub history: Vec<AppCommand>,
|
||||||
// Dialog overlay
|
/// Port handles
|
||||||
pub dialog: Option<Dialog>,
|
pub ports: std::collections::BTreeMap<u32, Port<Unowned>>,
|
||||||
/// Contains the currently edited MIDI clip
|
|
||||||
pub editor: Option<MidiEditor>,
|
|
||||||
|
|
||||||
// Cache of formatted strings
|
// Cache of formatted strings
|
||||||
pub view_cache: Arc<RwLock<ViewCache>>,
|
pub view_cache: Arc<RwLock<ViewCache>>,
|
||||||
/// Base color.
|
// Dialog overlay
|
||||||
pub color: ItemTheme,
|
pub dialog: Option<Dialog>,
|
||||||
|
// View and input definition
|
||||||
|
pub config: Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
has!(Jack: |self: App|self.jack);
|
impl App {
|
||||||
has!(Clock: |self: App|self.project.clock);
|
|
||||||
has!(Selection: |self: App|self.project.selection);
|
/// Add multiple tracks
|
||||||
has!(Vec<JackMidiIn>: |self: App|self.project.midi_ins);
|
pub fn tracks_add (
|
||||||
has!(Vec<JackMidiOut>: |self: App|self.project.midi_outs);
|
&mut self,
|
||||||
has!(Vec<Scene>: |self: App|self.project.scenes);
|
count: usize,
|
||||||
has!(Vec<Track>: |self: App|self.project.tracks);
|
width: Option<usize>,
|
||||||
has!(Measure<TuiOut>: |self: App|self.size);
|
mins: &[PortConnect],
|
||||||
|
mouts: &[PortConnect],
|
||||||
|
) -> Usually<()> {
|
||||||
|
let jack = self.jack().clone();
|
||||||
|
let track_color_1 = ItemColor::random();
|
||||||
|
let track_color_2 = ItemColor::random();
|
||||||
|
for i in 0..count {
|
||||||
|
let color = track_color_1.mix(track_color_2, i as f32 / count as f32).into();
|
||||||
|
let mut track = self.track_add(None, Some(color), mins, mouts)?.1;
|
||||||
|
if let Some(width) = width {
|
||||||
|
track.width = width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a track
|
||||||
|
pub fn track_add (
|
||||||
|
&mut self,
|
||||||
|
name: Option<&str>,
|
||||||
|
color: Option<ItemTheme>,
|
||||||
|
mins: &[PortConnect],
|
||||||
|
mouts: &[PortConnect],
|
||||||
|
) -> Usually<(usize, &mut Track)> {
|
||||||
|
self.track_last += 1;
|
||||||
|
let name: Arc<str> = name.map_or_else(
|
||||||
|
||format!("Track{:02}", self.track_last).into(),
|
||||||
|
|x|x.to_string().into()
|
||||||
|
);
|
||||||
|
let mut track = Track {
|
||||||
|
width: (name.len() + 2).max(12),
|
||||||
|
color: color.unwrap_or_else(ItemTheme::random),
|
||||||
|
sequencer: Sequencer::new(
|
||||||
|
&format!("{name}"),
|
||||||
|
self.jack(),
|
||||||
|
Some(self.clock()),
|
||||||
|
None,
|
||||||
|
mins,
|
||||||
|
mouts
|
||||||
|
)?,
|
||||||
|
name,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
self.tracks_mut().push(track);
|
||||||
|
let len = self.tracks().len();
|
||||||
|
let index = len - 1;
|
||||||
|
for scene in self.scenes_mut().iter_mut() {
|
||||||
|
while scene.clips.len() < len {
|
||||||
|
scene.clips.push(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok((index, &mut self.tracks_mut()[index]))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add and focus a track
|
||||||
|
pub(crate) fn track_add_focus (&mut self) -> Usually<usize> {
|
||||||
|
use Selection::*;
|
||||||
|
let index = self.track_add(None, None, &[], &[])?.0;
|
||||||
|
self.selected = match self.selected {
|
||||||
|
Track(_) => Track(index),
|
||||||
|
TrackClip { track, scene } => TrackClip { track: index, scene },
|
||||||
|
_ => self.selected
|
||||||
|
};
|
||||||
|
Ok(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete a track
|
||||||
|
pub fn track_del (&mut self, index: usize) -> Usually<()> {
|
||||||
|
let exists = self.tracks().get(index).is_some();
|
||||||
|
if exists {
|
||||||
|
let track = self.tracks_mut().remove(index);
|
||||||
|
let Track { sequencer: Sequencer { midi_ins, midi_outs, .. }, .. } = track;
|
||||||
|
for port in midi_ins.into_iter() {
|
||||||
|
port.close()?;
|
||||||
|
}
|
||||||
|
for port in midi_outs.into_iter() {
|
||||||
|
port.close()?;
|
||||||
|
}
|
||||||
|
for scene in self.scenes_mut().iter_mut() {
|
||||||
|
scene.clips.remove(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add multiple scenes
|
||||||
|
pub fn scenes_add (&mut self, n: usize) -> Usually<()> {
|
||||||
|
let scene_color_1 = ItemColor::random();
|
||||||
|
let scene_color_2 = ItemColor::random();
|
||||||
|
for i in 0..n {
|
||||||
|
let _ = self.scene_add(None, Some(
|
||||||
|
scene_color_1.mix(scene_color_2, i as f32 / n as f32).into()
|
||||||
|
))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a scene
|
||||||
|
pub fn scene_add (&mut self, name: Option<&str>, color: Option<ItemTheme>)
|
||||||
|
-> Usually<(usize, &mut Scene)>
|
||||||
|
{
|
||||||
|
let scene = Scene {
|
||||||
|
name: name.map_or_else(||self.scene_default_name(), |x|x.to_string().into()),
|
||||||
|
clips: vec![None;self.tracks().len()],
|
||||||
|
color: color.unwrap_or_else(ItemTheme::random),
|
||||||
|
};
|
||||||
|
self.scenes_mut().push(scene);
|
||||||
|
let index = self.scenes().len() - 1;
|
||||||
|
Ok((index, &mut self.scenes_mut()[index]))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add and focus an empty scene
|
||||||
|
pub fn scene_add_focus (&mut self) -> Usually<usize> {
|
||||||
|
use Selection::*;
|
||||||
|
let index = self.scene_add(None, None)?.0;
|
||||||
|
self.selected = match self.selected {
|
||||||
|
Scene(_) => Scene(index),
|
||||||
|
TrackClip { track, scene } => TrackClip { track, scene: index },
|
||||||
|
_ => self.selected
|
||||||
|
};
|
||||||
|
Ok(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enqueue clips from a scene across all tracks
|
||||||
|
pub fn scene_enqueue (&mut self, scene: usize) {
|
||||||
|
for track in 0..self.tracks.len() {
|
||||||
|
self.tracks[track].sequencer.enqueue_next(self.scenes[scene].clips[track].as_ref());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn toggle_editor (&mut self, value: Option<bool>) {
|
||||||
|
let editing = self.is_editing();
|
||||||
|
let value = value.unwrap_or_else(||!self.is_editing());
|
||||||
|
self.editing.store(value, Relaxed);
|
||||||
|
if value {
|
||||||
|
self.clip_auto_create();
|
||||||
|
} else {
|
||||||
|
self.clip_auto_remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new clip in pool when entering empty cell
|
||||||
|
pub fn clip_auto_create (&mut self) {
|
||||||
|
if let Some(ref pool) = self.pool
|
||||||
|
&& let Selection::TrackClip { track, scene } = self.selected
|
||||||
|
&& let Some(scene) = self.scenes.get_mut(scene)
|
||||||
|
&& let Some(slot) = scene.clips.get_mut(track)
|
||||||
|
&& slot.is_none()
|
||||||
|
{
|
||||||
|
let (index, mut clip) = pool.add_new_clip();
|
||||||
|
// autocolor: new clip colors from scene and track color
|
||||||
|
clip.write().unwrap().color = ItemColor::random_near(
|
||||||
|
self.tracks[track].color.base.mix(
|
||||||
|
scene.color.base,
|
||||||
|
0.5
|
||||||
|
),
|
||||||
|
0.2
|
||||||
|
).into();
|
||||||
|
if let Some(ref mut editor) = self.editor {
|
||||||
|
editor.set_clip(Some(&clip));
|
||||||
|
}
|
||||||
|
*slot = Some(clip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove clip from arrangement when exiting empty clip editor
|
||||||
|
pub fn clip_auto_remove (&mut self) {
|
||||||
|
if let Some(ref mut pool) = self.pool
|
||||||
|
&& let Selection::TrackClip { track, scene } = self.selected
|
||||||
|
&& let Some(scene) = self.scenes.get_mut(scene)
|
||||||
|
&& let Some(slot) = scene.clips.get_mut(track)
|
||||||
|
&& let Some(clip) = slot.as_mut()
|
||||||
|
{
|
||||||
|
let mut swapped = None;
|
||||||
|
if clip.read().unwrap().count_midi_messages() == 0 {
|
||||||
|
std::mem::swap(&mut swapped, slot);
|
||||||
|
}
|
||||||
|
if let Some(clip) = swapped {
|
||||||
|
pool.delete_clip(&clip.read().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Put a clip in a slot
|
||||||
|
pub(crate) fn clip_put (
|
||||||
|
&mut self, track: usize, scene: usize, clip: Option<Arc<RwLock<MidiClip>>>
|
||||||
|
) -> Option<Arc<RwLock<MidiClip>>> {
|
||||||
|
let old = self.scenes[scene].clips[track].clone();
|
||||||
|
self.scenes[scene].clips[track] = clip;
|
||||||
|
old
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change the color of a clip, returning the previous one
|
||||||
|
pub(crate) fn clip_set_color (
|
||||||
|
&self, track: usize, scene: usize, color: ItemTheme
|
||||||
|
) -> Option<ItemTheme> {
|
||||||
|
self.scenes[scene].clips[track].as_ref().map(|clip|{
|
||||||
|
let mut clip = clip.write().unwrap();
|
||||||
|
let old = clip.color.clone();
|
||||||
|
clip.color = color.clone();
|
||||||
|
panic!("{color:?} {old:?}");
|
||||||
|
old
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the clip pool, if present
|
||||||
|
pub(crate) fn pool (&self) -> Option<&Pool> {
|
||||||
|
self.pool.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the active clip
|
||||||
|
pub(crate) fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
||||||
|
self.scene()?.clips.get(self.selected().track()?)?.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the active editor
|
||||||
|
pub(crate) fn editor (&self) -> Option<&MidiEditor> {
|
||||||
|
self.editor.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Toggle looping for the active clip
|
||||||
|
pub(crate) fn toggle_loop (&mut self) {
|
||||||
|
if let Some(clip) = self.clip() {
|
||||||
|
clip.write().unwrap().toggle_loop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the selection
|
||||||
|
pub(crate) fn select (&mut self, s: Selection) {
|
||||||
|
self.selected = s;
|
||||||
|
// autoedit: load focused clip in editor.
|
||||||
|
if let Some(ref mut editor) = self.editor {
|
||||||
|
editor.set_clip(match self.selected {
|
||||||
|
Selection::TrackClip { track, scene }
|
||||||
|
if let Some(Some(Some(clip))) = self
|
||||||
|
.scenes.get(scene)
|
||||||
|
.map(|s|s.clips.get(track)) => Some(clip),
|
||||||
|
_ => None
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stop all playing clips
|
||||||
|
pub(crate) fn stop_all (&mut self) {
|
||||||
|
for track in 0..self.tracks.len() {
|
||||||
|
self.tracks[track].sequencer.enqueue_next(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch a clip or scene
|
||||||
|
pub(crate) fn launch (&mut self) {
|
||||||
|
use Selection::*;
|
||||||
|
match self.selected {
|
||||||
|
Track(t) => {
|
||||||
|
self.tracks[t].sequencer.enqueue_next(None)
|
||||||
|
},
|
||||||
|
TrackClip { track, scene } => {
|
||||||
|
self.tracks[track].sequencer.enqueue_next(self.scenes[scene].clips[track].as_ref())
|
||||||
|
},
|
||||||
|
Scene(s) => {
|
||||||
|
for t in 0..self.tracks.len() {
|
||||||
|
self.tracks[t].sequencer.enqueue_next(self.scenes[s].clips[t].as_ref())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the first sampler of the active track
|
||||||
|
pub fn sampler (&self) -> Option<&Sampler> {
|
||||||
|
self.track().map(|t|t.sampler(0)).flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the first sampler of the active track
|
||||||
|
pub fn sampler_mut (&mut self) -> Option<&mut Sampler> {
|
||||||
|
self.track_mut().map(|t|t.sampler_mut(0)).flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the color of the selected entity
|
||||||
|
pub fn set_color (&mut self, palette: Option<ItemTheme>) -> Option<ItemTheme> {
|
||||||
|
use Selection::*;
|
||||||
|
let palette = palette.unwrap_or_else(||ItemTheme::random());
|
||||||
|
Some(match self.selected {
|
||||||
|
Mix => {
|
||||||
|
let old = self.color;
|
||||||
|
self.color = palette;
|
||||||
|
old
|
||||||
|
},
|
||||||
|
Scene(s) => {
|
||||||
|
let old = self.scenes[s].color;
|
||||||
|
self.scenes[s].color = palette;
|
||||||
|
old
|
||||||
|
}
|
||||||
|
Track(t) => {
|
||||||
|
let old = self.tracks[t].color;
|
||||||
|
self.tracks[t].color = palette;
|
||||||
|
old
|
||||||
|
}
|
||||||
|
TrackClip { track, scene } => {
|
||||||
|
if let Some(ref clip) = self.scenes[scene].clips[track] {
|
||||||
|
let mut clip = clip.write().unwrap();
|
||||||
|
let old = clip.color;
|
||||||
|
clip.color = palette;
|
||||||
|
old
|
||||||
|
} else {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => todo!()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn midi_in_add (&mut self) -> Usually<()> {
|
||||||
|
self.midi_ins.push(JackMidiIn::new(&self.jack, &format!("M/{}", self.midi_ins.len()), &[])?);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn midi_out_add (&mut self) -> Usually<()> {
|
||||||
|
self.midi_outs.push(JackMidiOut::new(&self.jack, &format!("{}/M", self.midi_outs.len()), &[])?);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn device_kinds (&self) -> &'static [&'static str] {
|
||||||
|
&[
|
||||||
|
"Sampler",
|
||||||
|
"Plugin (LV2)",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn device_picker_show (&mut self) {
|
||||||
|
self.dialog = Some(Dialog::Device(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn device_pick (&mut self, index: usize) {
|
||||||
|
self.dialog = Some(Dialog::Device(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn device_add (&mut self, index: usize) -> Usually<()> {
|
||||||
|
match index {
|
||||||
|
0 => self.device_add_sampler(),
|
||||||
|
1 => self.device_add_lv2(),
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn device_add_sampler (&mut self) -> Usually<()> {
|
||||||
|
let name = self.jack.with_client(|c|c.name().to_string());
|
||||||
|
let midi = self.track().expect("no active track").sequencer.midi_outs[0].name();
|
||||||
|
let sampler = if let Ok(sampler) = Sampler::new(
|
||||||
|
&self.jack,
|
||||||
|
&format!("{}/Sampler", &self.track().expect("no active track").name),
|
||||||
|
&[PortConnect::exact(format!("{name}:{midi}"))],
|
||||||
|
&[&[], &[]],
|
||||||
|
&[&[], &[]]
|
||||||
|
) {
|
||||||
|
self.dialog = None;
|
||||||
|
Device::Sampler(sampler)
|
||||||
|
} else {
|
||||||
|
self.dialog = Some(Dialog::Message(Message::FailedToAddDevice));
|
||||||
|
return Err("failed to add device".into())
|
||||||
|
};
|
||||||
|
self.track_mut().expect("no active track").devices.push(sampler);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn device_add_lv2 (&mut self) -> Usually<()> {
|
||||||
|
todo!();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
has_size!(<TuiOut>|self: App|&self.size);
|
||||||
|
|
||||||
|
has_clock!(|self: App|self.clock);
|
||||||
|
|
||||||
|
has_clips!(|self: App|self.pool.as_ref().expect("no clip pool").clips);
|
||||||
|
|
||||||
has_clips!(|self: App|self.project.pool.clips);
|
|
||||||
has_editor!(|self: App|{
|
has_editor!(|self: App|{
|
||||||
editor = self.editor;
|
editor = self.editor;
|
||||||
editor_w = {
|
editor_w = {
|
||||||
|
|
@ -48,256 +456,5 @@ has_editor!(|self: App|{
|
||||||
(5 + (time_len / time_zoom)).min(size.saturating_sub(20)).max(16)
|
(5 + (time_len / time_zoom)).min(size.saturating_sub(20)).max(16)
|
||||||
};
|
};
|
||||||
editor_h = 15;
|
editor_h = 15;
|
||||||
is_editing = self.editor.is_some();
|
is_editing = self.editing.load(Relaxed);
|
||||||
});
|
});
|
||||||
|
|
||||||
impl App {
|
|
||||||
pub fn toggle_dialog (&mut self, mut dialog: Option<Dialog>) -> Option<Dialog> {
|
|
||||||
std::mem::swap(&mut self.dialog, &mut dialog);
|
|
||||||
dialog
|
|
||||||
}
|
|
||||||
pub fn toggle_editor (&mut self, value: Option<bool>) {
|
|
||||||
//FIXME: self.editing.store(value.unwrap_or_else(||!self.is_editing()), Relaxed);
|
|
||||||
let value = value.unwrap_or_else(||!self.editor.is_some());
|
|
||||||
if value {
|
|
||||||
self.clip_auto_create();
|
|
||||||
} else {
|
|
||||||
self.clip_auto_remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn browser (&self) -> Option<&Browser> {
|
|
||||||
self.dialog.as_ref().and_then(|dialog|match dialog {
|
|
||||||
Dialog::Save(b) | Dialog::Load(b) => Some(b),
|
|
||||||
_ => None
|
|
||||||
})
|
|
||||||
}
|
|
||||||
pub(crate) fn device_pick (&mut self, index: usize) {
|
|
||||||
self.dialog = Some(Dialog::Device(index));
|
|
||||||
}
|
|
||||||
pub(crate) fn device_kinds (&self) -> &'static [&'static str] {
|
|
||||||
&[
|
|
||||||
"Sampler",
|
|
||||||
"Plugin (LV2)",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
pub(crate) fn device_add (&mut self, index: usize) -> Usually<()> {
|
|
||||||
match index {
|
|
||||||
0 => self.device_add_sampler(),
|
|
||||||
1 => self.device_add_lv2(),
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn device_add_lv2 (&mut self) -> Usually<()> {
|
|
||||||
todo!();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn device_add_sampler (&mut self) -> Usually<()> {
|
|
||||||
let name = self.jack.with_client(|c|c.name().to_string());
|
|
||||||
let midi = self.project.track().expect("no active track").sequencer.midi_outs[0].name();
|
|
||||||
let track = self.track().expect("no active track");
|
|
||||||
let port = format!("{}/Sampler", &track.name);
|
|
||||||
let connect = PortConnect::exact(format!("{name}:{midi}"));
|
|
||||||
let sampler = if let Ok(sampler) = Sampler::new(
|
|
||||||
&self.jack, &port, &[connect], &[&[], &[]], &[&[], &[]]
|
|
||||||
) {
|
|
||||||
self.dialog = None;
|
|
||||||
Device::Sampler(sampler)
|
|
||||||
} else {
|
|
||||||
self.dialog = Some(Dialog::Message(Message::FailedToAddDevice));
|
|
||||||
return Err("failed to add device".into())
|
|
||||||
};
|
|
||||||
let track = self.track_mut().expect("no active track");
|
|
||||||
track.devices.push(sampler);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
// Create new clip in pool when entering empty cell
|
|
||||||
fn clip_auto_create (&mut self) -> Option<Arc<RwLock<MidiClip>>> {
|
|
||||||
if let Selection::TrackClip { track, scene } = *self.selection()
|
|
||||||
&& let Some(scene) = self.project.scenes.get_mut(scene)
|
|
||||||
&& let Some(slot) = scene.clips.get_mut(track)
|
|
||||||
&& slot.is_none()
|
|
||||||
&& let Some(track) = self.project.tracks.get_mut(track)
|
|
||||||
{
|
|
||||||
let (index, mut clip) = self.project.pool.add_new_clip();
|
|
||||||
// autocolor: new clip colors from scene and track color
|
|
||||||
let color = track.color.base.mix(scene.color.base, 0.5);
|
|
||||||
clip.write().unwrap().color = ItemColor::random_near(color, 0.2).into();
|
|
||||||
if let Some(ref mut editor) = self.editor {
|
|
||||||
editor.set_clip(Some(&clip));
|
|
||||||
}
|
|
||||||
*slot = Some(clip.clone());
|
|
||||||
Some(clip)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Remove clip from arrangement when exiting empty clip editor
|
|
||||||
fn clip_auto_remove (&mut self) {
|
|
||||||
if let Selection::TrackClip { track, scene } = *self.selection()
|
|
||||||
&& let Some(scene) = self.project.scenes.get_mut(scene)
|
|
||||||
&& let Some(slot) = scene.clips.get_mut(track)
|
|
||||||
&& let Some(clip) = slot.as_mut()
|
|
||||||
{
|
|
||||||
let mut swapped = None;
|
|
||||||
if clip.read().unwrap().count_midi_messages() == 0 {
|
|
||||||
std::mem::swap(&mut swapped, slot);
|
|
||||||
}
|
|
||||||
if let Some(clip) = swapped {
|
|
||||||
self.project.pool.delete_clip(&clip.read().unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Various possible dialog overlays
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub enum Dialog {
|
|
||||||
Help(usize),
|
|
||||||
Menu(usize),
|
|
||||||
Device(usize),
|
|
||||||
Message(Message),
|
|
||||||
Save(Browser),
|
|
||||||
Load(Browser),
|
|
||||||
Options,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Various possible messages
|
|
||||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
|
||||||
pub enum Message {
|
|
||||||
FailedToAddDevice,
|
|
||||||
}
|
|
||||||
|
|
||||||
content!(TuiOut: |self: Message| match self { Self::FailedToAddDevice => "Failed to add device." });
|
|
||||||
|
|
||||||
#[tengri_proc::expose]
|
|
||||||
impl App {
|
|
||||||
fn _todo_isize_stub (&self) -> isize {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn _todo_item_theme_stub (&self) -> ItemTheme {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn w_sidebar (&self) -> u16 {
|
|
||||||
self.project.w_sidebar(self.editor.is_some())
|
|
||||||
}
|
|
||||||
fn focus_editor (&self) -> bool {
|
|
||||||
self.is_editing()
|
|
||||||
}
|
|
||||||
fn focus_message (&self) -> bool {
|
|
||||||
matches!(self.dialog, Some(Dialog::Message(..)))
|
|
||||||
}
|
|
||||||
fn focus_device_add (&self) -> bool {
|
|
||||||
matches!(self.dialog, Some(Dialog::Device(..)))
|
|
||||||
}
|
|
||||||
fn focus_browser (&self) -> bool {
|
|
||||||
self.browser().is_some()
|
|
||||||
}
|
|
||||||
fn focus_clip (&self) -> bool {
|
|
||||||
!self.is_editing() && self.selection().is_clip()
|
|
||||||
}
|
|
||||||
fn focus_track (&self) -> bool {
|
|
||||||
!self.is_editing() && self.selection().is_track()
|
|
||||||
}
|
|
||||||
fn focus_scene (&self) -> bool {
|
|
||||||
!self.is_editing() && self.selection().is_scene()
|
|
||||||
}
|
|
||||||
fn focus_mix (&self) -> bool {
|
|
||||||
!self.is_editing() && self.selection().is_mix()
|
|
||||||
}
|
|
||||||
fn focus_pool_import (&self) -> bool {
|
|
||||||
matches!(self.project.pool.mode, Some(PoolMode::Import(..)))
|
|
||||||
}
|
|
||||||
fn focus_pool_export (&self) -> bool {
|
|
||||||
matches!(self.project.pool.mode, Some(PoolMode::Export(..)))
|
|
||||||
}
|
|
||||||
fn focus_pool_rename (&self) -> bool {
|
|
||||||
matches!(self.project.pool.mode, Some(PoolMode::Rename(..)))
|
|
||||||
}
|
|
||||||
fn focus_pool_length (&self) -> bool {
|
|
||||||
matches!(self.project.pool.mode, Some(PoolMode::Length(..)))
|
|
||||||
}
|
|
||||||
fn dialog_none (&self) -> Option<Dialog> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
fn dialog_device (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Device(0)) // TODO
|
|
||||||
}
|
|
||||||
fn dialog_device_prev (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Device(0)) // TODO
|
|
||||||
}
|
|
||||||
fn dialog_device_next (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Device(0)) // TODO
|
|
||||||
}
|
|
||||||
fn dialog_help (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Help(0))
|
|
||||||
}
|
|
||||||
fn dialog_menu (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Menu(0))
|
|
||||||
}
|
|
||||||
fn dialog_save (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Save(Default::default()))
|
|
||||||
}
|
|
||||||
fn dialog_load (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Load(Default::default()))
|
|
||||||
}
|
|
||||||
fn dialog_options (&self) -> Option<Dialog> {
|
|
||||||
Some(Dialog::Options)
|
|
||||||
}
|
|
||||||
fn editor_pitch (&self) -> Option<u7> {
|
|
||||||
Some((self.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into())
|
|
||||||
}
|
|
||||||
fn scene_count (&self) -> usize {
|
|
||||||
self.scenes().len()
|
|
||||||
}
|
|
||||||
fn scene_selection (&self) -> Option<usize> {
|
|
||||||
self.selection().scene()
|
|
||||||
}
|
|
||||||
fn track_count (&self) -> usize {
|
|
||||||
self.tracks().len()
|
|
||||||
}
|
|
||||||
fn track_selection (&self) -> Option<usize> {
|
|
||||||
self.selection().track()
|
|
||||||
}
|
|
||||||
fn select_scene_next (&self) -> Selection {
|
|
||||||
self.selection().scene_next(self.scenes().len())
|
|
||||||
}
|
|
||||||
fn select_scene_prev (&self) -> Selection {
|
|
||||||
self.selection().scene_prev()
|
|
||||||
}
|
|
||||||
fn select_track_header (&self) -> Selection {
|
|
||||||
self.selection().track_header(self.tracks().len())
|
|
||||||
}
|
|
||||||
fn select_track_next (&self) -> Selection {
|
|
||||||
self.selection().track_next(self.tracks().len())
|
|
||||||
}
|
|
||||||
fn select_track_prev (&self) -> Selection {
|
|
||||||
self.selection().track_prev()
|
|
||||||
}
|
|
||||||
fn clip_selection (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
|
||||||
match self.selection() {
|
|
||||||
Selection::TrackClip { track, scene } => self.scenes()[*scene].clips[*track].clone(),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn device_kind (&self) -> usize {
|
|
||||||
if let Some(Dialog::Device(index)) = self.dialog {
|
|
||||||
index
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn device_kind_prev (&self) -> usize {
|
|
||||||
if let Some(Dialog::Device(index)) = self.dialog {
|
|
||||||
index.overflowing_sub(1).0.min(self.device_kinds().len().saturating_sub(1))
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn device_kind_next (&self) -> usize {
|
|
||||||
if let Some(Dialog::Device(index)) = self.dialog {
|
|
||||||
(index + 1) % self.device_kinds().len()
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
36
crates/app/src/model/dialog.rs
Normal file
36
crates/app/src/model/dialog.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn toggle_dialog (&mut self, dialog: Option<Dialog>) {
|
||||||
|
self.dialog = if self.dialog == dialog {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
dialog
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn message_dismiss (&mut self) {
|
||||||
|
self.dialog = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Various possible dialog overlays
|
||||||
|
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||||
|
pub enum Dialog {
|
||||||
|
Help,
|
||||||
|
Menu,
|
||||||
|
Device(usize),
|
||||||
|
Message(Message),
|
||||||
|
Save,
|
||||||
|
Load,
|
||||||
|
Options,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Various possible messages
|
||||||
|
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||||
|
pub enum Message {
|
||||||
|
FailedToAddDevice,
|
||||||
|
}
|
||||||
|
|
||||||
|
content!(TuiOut: |self: Message| match self {
|
||||||
|
Self::FailedToAddDevice => "Failed to add device."
|
||||||
|
});
|
||||||
0
crates/app/src/model/pool.rs
Normal file
0
crates/app/src/model/pool.rs
Normal file
|
|
@ -1,56 +1,12 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
impl<'state> Context<'state, SceneCommand> for Arrangement {
|
#[derive(Debug, Default)] pub struct Scene {
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<SceneCommand> {
|
|
||||||
Context::get(&self, iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::expose]
|
|
||||||
impl Scene {
|
|
||||||
fn _todo_opt_bool_stub_ (&self) -> Option<bool> { todo!() }
|
|
||||||
fn _todo_usize_stub_ (&self) -> usize { todo!() }
|
|
||||||
fn _todo_arc_str_stub_ (&self) -> Arc<str> { todo!() }
|
|
||||||
fn _todo_item_theme_stub (&self) -> ItemTheme { todo!() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::command(Scene)]
|
|
||||||
impl SceneCommand {
|
|
||||||
fn set_name (scene: &mut Scene, mut name: Arc<str>) -> Perhaps<Self> {
|
|
||||||
std::mem::swap(&mut scene.name, &mut name);
|
|
||||||
Ok(Some(Self::SetName { name }))
|
|
||||||
}
|
|
||||||
fn set_color (scene: &mut Scene, mut color: ItemTheme) -> Perhaps<Self> {
|
|
||||||
std::mem::swap(&mut scene.color, &mut color);
|
|
||||||
Ok(Some(Self::SetColor { color }))
|
|
||||||
}
|
|
||||||
fn set_size (scene: &mut Scene, size: usize) -> Perhaps<Self> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn set_zoom (scene: &mut Scene, zoom: usize) -> Perhaps<Self> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Has<Option<Scene>> + Send + Sync> HasScene for T {}
|
|
||||||
|
|
||||||
pub trait HasScene: Has<Option<Scene>> + Send + Sync {
|
|
||||||
fn scene (&self) -> Option<&Scene> {
|
|
||||||
Has::<Option<Scene>>::get(self).as_ref()
|
|
||||||
}
|
|
||||||
fn scene_mut (&mut self) -> &mut Option<Scene> {
|
|
||||||
Has::<Option<Scene>>::get_mut(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct Scene {
|
|
||||||
/// Name of scene
|
/// Name of scene
|
||||||
pub name: Arc<str>,
|
pub name: Arc<str>,
|
||||||
/// Identifying color of scene
|
|
||||||
pub color: ItemTheme,
|
|
||||||
/// Clips in scene, one per track
|
/// Clips in scene, one per track
|
||||||
pub clips: Vec<Option<Arc<RwLock<MidiClip>>>>,
|
pub clips: Vec<Option<Arc<RwLock<MidiClip>>>>,
|
||||||
|
/// Identifying color of scene
|
||||||
|
pub color: ItemTheme,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scene {
|
impl Scene {
|
||||||
|
|
@ -82,3 +38,39 @@ impl Scene {
|
||||||
match self.clips.get(index) { Some(Some(clip)) => Some(clip), _ => None }
|
match self.clips.get(index) { Some(Some(clip)) => Some(clip), _ => None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait HasScenes: HasSelection + HasEditor + Send + Sync {
|
||||||
|
fn scenes (&self) -> &Vec<Scene>;
|
||||||
|
fn scenes_mut (&mut self) -> &mut Vec<Scene>;
|
||||||
|
fn scene_longest (&self) -> usize {
|
||||||
|
self.scenes().iter().map(|s|s.name.len()).fold(0, usize::max)
|
||||||
|
}
|
||||||
|
fn scene (&self) -> Option<&Scene> {
|
||||||
|
self.selected().scene()
|
||||||
|
.and_then(|s|self.scenes().get(s))
|
||||||
|
}
|
||||||
|
fn scene_mut (&mut self) -> Option<&mut Scene> {
|
||||||
|
self.selected().scene()
|
||||||
|
.and_then(|s|self.scenes_mut().get_mut(s))
|
||||||
|
}
|
||||||
|
fn scene_del (&mut self, index: usize) -> Option<Scene> {
|
||||||
|
self.selected().scene()
|
||||||
|
.and_then(|s|Some(self.scenes_mut().remove(index)))
|
||||||
|
}
|
||||||
|
/// Set the color of a scene, returning the previous one.
|
||||||
|
fn scene_set_color (&mut self, index: usize, color: ItemTheme) -> ItemTheme {
|
||||||
|
let scenes = self.scenes_mut();
|
||||||
|
let old = scenes[index].color;
|
||||||
|
scenes[index].color = color;
|
||||||
|
old
|
||||||
|
}
|
||||||
|
/// Generate the default name for a new scene
|
||||||
|
fn scene_default_name (&self) -> Arc<str> {
|
||||||
|
format!("Sc{:3>}", self.scenes().len() + 1).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasScenes for App {
|
||||||
|
fn scenes (&self) -> &Vec<Scene> { &self.scenes }
|
||||||
|
fn scenes_mut (&mut self) -> &mut Vec<Scene> { &mut self.scenes }
|
||||||
|
}
|
||||||
|
|
@ -1,24 +1,15 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
impl<T: Has<Selection>> HasSelection for T {}
|
pub trait HasSelection {
|
||||||
|
fn selected (&self) -> &Selection;
|
||||||
pub trait HasSelection: Has<Selection> {
|
fn selected_mut (&mut self) -> &mut Selection;
|
||||||
fn selection (&self) -> &Selection {
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
fn selection_mut (&mut self) -> &mut Selection {
|
|
||||||
self.get_mut()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the current user selection in the arranger
|
/// Represents the current user selection in the arranger
|
||||||
#[derive(PartialEq, Clone, Copy, Debug, Default)]
|
#[derive(PartialEq, Clone, Copy, Debug, Default)]
|
||||||
pub enum Selection {
|
pub enum Selection {
|
||||||
#[default]
|
|
||||||
/// Nothing is selected
|
|
||||||
Nothing,
|
|
||||||
/// The whole mix is selected
|
/// The whole mix is selected
|
||||||
Mix,
|
#[default] Mix,
|
||||||
/// A MIDI input is selected.
|
/// A MIDI input is selected.
|
||||||
Input(usize),
|
Input(usize),
|
||||||
/// A MIDI output is selected.
|
/// A MIDI output is selected.
|
||||||
|
|
@ -160,5 +151,7 @@ impl Selection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arrangement {
|
impl HasSelection for App {
|
||||||
|
fn selected (&self) -> &Selection { &self.selected }
|
||||||
|
fn selected_mut (&mut self) -> &mut Selection { &mut self.selected }
|
||||||
}
|
}
|
||||||
|
|
@ -1,59 +1,6 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
impl<'state> Context<'state, TrackCommand> for Arrangement {
|
#[derive(Debug, Default)] pub struct Track {
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<TrackCommand> {
|
|
||||||
Context::get(&self, iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::expose]
|
|
||||||
impl Track {
|
|
||||||
fn _todo_opt_bool_stub_ (&self) -> Option<bool> { todo!() }
|
|
||||||
fn _todo_usize_stub_ (&self) -> usize { todo!() }
|
|
||||||
fn _todo_arc_str_stub_ (&self) -> Arc<str> { todo!() }
|
|
||||||
fn _todo_item_theme_stub (&self) -> ItemTheme { todo!() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::command(Track)]
|
|
||||||
impl TrackCommand {
|
|
||||||
fn set_name (track: &mut Track, mut name: Arc<str>) -> Perhaps<Self> {
|
|
||||||
std::mem::swap(&mut name, &mut track.name);
|
|
||||||
Ok(Some(Self::SetName { name }))
|
|
||||||
}
|
|
||||||
fn set_color (track: &mut Track, mut color: ItemTheme) -> Perhaps<Self> {
|
|
||||||
std::mem::swap(&mut color, &mut track.color);
|
|
||||||
Ok(Some(Self::SetColor { color }))
|
|
||||||
}
|
|
||||||
fn set_mute (track: &mut Track, value: Option<bool>) -> Perhaps<Self> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn set_solo (track: &mut Track, value: Option<bool>) -> Perhaps<Self> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn set_rec (track: &mut Track, value: Option<bool>) -> Perhaps<Self> {
|
|
||||||
let current = track.sequencer.recording;
|
|
||||||
let value = value.unwrap_or(!current);
|
|
||||||
Ok((value != current).then_some(Self::SetRec { value: Some(current) }))
|
|
||||||
}
|
|
||||||
fn set_mon (track: &mut Track, value: Option<bool>) -> Perhaps<Self> {
|
|
||||||
let current = track.sequencer.monitoring;
|
|
||||||
let value = value.unwrap_or(!current);
|
|
||||||
Ok((value != current).then_some(Self::SetRec { value: Some(current) }))
|
|
||||||
}
|
|
||||||
fn set_size (track: &mut Track, size: usize) -> Perhaps<Self> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn set_zoom (track: &mut Track, zoom: usize) -> Perhaps<Self> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn stop (track: &mut Track) -> Perhaps<Self> {
|
|
||||||
track.sequencer.enqueue_next(None);
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct Track {
|
|
||||||
/// Name of track
|
/// Name of track
|
||||||
pub name: Arc<str>,
|
pub name: Arc<str>,
|
||||||
/// Identifying color of track
|
/// Identifying color of track
|
||||||
|
|
@ -66,8 +13,9 @@ pub struct Track {
|
||||||
pub devices: Vec<Device>,
|
pub devices: Vec<Device>,
|
||||||
}
|
}
|
||||||
|
|
||||||
has!(Clock: |self: Track|self.sequencer.clock);
|
has_clock!(|self: Track|self.sequencer.clock);
|
||||||
has!(Sequencer: |self: Track|self.sequencer);
|
|
||||||
|
has_sequencer!(|self: Track|self.sequencer);
|
||||||
|
|
||||||
impl Track {
|
impl Track {
|
||||||
/// Create a new track with only the default [Sequencer].
|
/// Create a new track with only the default [Sequencer].
|
||||||
|
|
@ -119,7 +67,6 @@ impl Track {
|
||||||
)?));
|
)?));
|
||||||
Ok(track)
|
Ok(track)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sampler")]
|
|
||||||
pub fn sampler (&self, mut nth: usize) -> Option<&Sampler> {
|
pub fn sampler (&self, mut nth: usize) -> Option<&Sampler> {
|
||||||
for device in self.devices.iter() {
|
for device in self.devices.iter() {
|
||||||
match device {
|
match device {
|
||||||
|
|
@ -133,7 +80,6 @@ impl Track {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sampler")]
|
|
||||||
pub fn sampler_mut (&mut self, mut nth: usize) -> Option<&mut Sampler> {
|
pub fn sampler_mut (&mut self, mut nth: usize) -> Option<&mut Sampler> {
|
||||||
for device in self.devices.iter_mut() {
|
for device in self.devices.iter_mut() {
|
||||||
match device {
|
match device {
|
||||||
|
|
@ -149,27 +95,67 @@ impl Track {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasTrack {
|
pub trait HasWidth {
|
||||||
fn track (&self) -> Option<&Track>;
|
const MIN_WIDTH: usize;
|
||||||
fn track_mut (&mut self) -> Option<&mut Track>;
|
/// Increment track width.
|
||||||
|
fn width_inc (&mut self);
|
||||||
|
/// Decrement track width, down to a hardcoded minimum of [Self::MIN_WIDTH].
|
||||||
|
fn width_dec (&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
//impl<T: Has<Option<Track>>> HasTrack for T {
|
impl HasWidth for Track {
|
||||||
//fn track (&self) -> Option<&Track> {
|
const MIN_WIDTH: usize = 9;
|
||||||
//self.get().as_ref()
|
fn width_inc (&mut self) {
|
||||||
//}
|
self.width += 1;
|
||||||
//fn track_mut (&mut self) -> Option<&mut Track> {
|
}
|
||||||
//self.get_mut().as_mut()
|
fn width_dec (&mut self) {
|
||||||
//}
|
if self.width > Track::MIN_WIDTH {
|
||||||
//}
|
self.width -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Has<Vec<Track>> + Has<Selection>> HasTrack for T {
|
pub trait HasTracks: HasSelection + HasClock + HasJack + HasEditor + Send + Sync {
|
||||||
|
fn midi_ins (&self) -> &Vec<JackMidiIn>;
|
||||||
|
fn midi_outs (&self) -> &Vec<JackMidiOut>;
|
||||||
|
fn tracks (&self) -> &Vec<Track>;
|
||||||
|
fn tracks_mut (&mut self) -> &mut Vec<Track>;
|
||||||
|
fn track_longest (&self) -> usize {
|
||||||
|
self.tracks().iter().map(|s|s.name.len()).fold(0, usize::max)
|
||||||
|
}
|
||||||
|
const WIDTH_OFFSET: usize = 1;
|
||||||
fn track (&self) -> Option<&Track> {
|
fn track (&self) -> Option<&Track> {
|
||||||
let index = Has::<Selection>::get(self).track()?;
|
self.selected().track().and_then(|s|self.tracks().get(s))
|
||||||
Has::<Vec<Track>>::get(self).get(index)
|
|
||||||
}
|
}
|
||||||
fn track_mut (&mut self) -> Option<&mut Track> {
|
fn track_mut (&mut self) -> Option<&mut Track> {
|
||||||
let index = Has::<Selection>::get(self).track()?;
|
self.selected().track().and_then(|s|self.tracks_mut().get_mut(s))
|
||||||
Has::<Vec<Track>>::get_mut(self).get_mut(index)
|
}
|
||||||
|
/// Set the color of a track
|
||||||
|
fn track_set_color (&mut self, index: usize, color: ItemTheme) -> ItemTheme {
|
||||||
|
let tracks = self.tracks_mut();
|
||||||
|
let old = tracks[index].color;
|
||||||
|
tracks[index].color = color;
|
||||||
|
old
|
||||||
|
}
|
||||||
|
/// Toggle track recording
|
||||||
|
fn track_toggle_record (&mut self) {
|
||||||
|
if let Some(t) = self.selected().track() {
|
||||||
|
let tracks = self.tracks_mut();
|
||||||
|
tracks[t-1].sequencer.recording = !tracks[t-1].sequencer.recording;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Toggle track monitoring
|
||||||
|
fn track_toggle_monitor (&mut self) {
|
||||||
|
if let Some(t) = self.selected().track() {
|
||||||
|
let tracks = self.tracks_mut();
|
||||||
|
tracks[t-1].sequencer.monitoring = !tracks[t-1].sequencer.monitoring;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasTracks for App {
|
||||||
|
fn midi_ins (&self) -> &Vec<JackMidiIn> { &self.midi_ins }
|
||||||
|
fn midi_outs (&self) -> &Vec<JackMidiOut> { &self.midi_outs }
|
||||||
|
fn tracks (&self) -> &Vec<Track> { &self.tracks }
|
||||||
|
fn tracks_mut (&mut self) -> &mut Vec<Track> { &mut self.tracks }
|
||||||
|
}
|
||||||
|
|
@ -2,12 +2,8 @@ use crate::*;
|
||||||
pub(crate) use std::fmt::Write;
|
pub(crate) use std::fmt::Write;
|
||||||
pub(crate) use ::tengri::tui::ratatui::prelude::Position;
|
pub(crate) use ::tengri::tui::ratatui::prelude::Position;
|
||||||
|
|
||||||
impl App {
|
mod view_dialog; pub use self::view_dialog::*;
|
||||||
|
mod view_output; pub use self::view_output::*;
|
||||||
pub fn update_clock (&self) {
|
|
||||||
ViewCache::update_clock(&self.view_cache, self.clock(), self.size.w() > 80)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::view(TuiOut)]
|
#[tengri_proc::view(TuiOut)]
|
||||||
impl App {
|
impl App {
|
||||||
|
|
@ -17,116 +13,490 @@ impl App {
|
||||||
pub fn view_status (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.update_clock();
|
self.update_clock();
|
||||||
let cache = self.view_cache.read().unwrap();
|
let cache = self.view_cache.read().unwrap();
|
||||||
view_status(Some(self.project.selection.describe(self.tracks(), self.scenes())),
|
view_status(self.selected.describe(&self.tracks, &self.scenes),
|
||||||
cache.sr.view.clone(), cache.buf.view.clone(), cache.lat.view.clone())
|
cache.sr.view.clone(), cache.buf.view.clone(), cache.lat.view.clone())
|
||||||
}
|
}
|
||||||
pub fn view_transport (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_transport (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.update_clock();
|
self.update_clock();
|
||||||
let cache = self.view_cache.read().unwrap();
|
let cache = self.view_cache.read().unwrap();
|
||||||
view_transport(self.project.clock.is_rolling(),
|
view_transport(self.clock.is_rolling(),
|
||||||
cache.bpm.view.clone(), cache.beat.view.clone(), cache.time.view.clone())
|
cache.bpm.view.clone(), cache.beat.view.clone(), cache.time.view.clone())
|
||||||
}
|
}
|
||||||
|
pub fn view_arranger (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
ArrangerView::new(self)
|
||||||
|
}
|
||||||
|
pub fn view_pool (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
self.pool().map(|p|Fixed::x(self.w_sidebar(), PoolView(self.is_editing(), p)))
|
||||||
|
}
|
||||||
pub fn view_editor (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_editor (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.editor().map(|e|Bsp::n(Bsp::e(e.clip_status(), e.edit_status()), e))
|
self.editor().map(|e|Bsp::n(Bsp::e(e.clip_status(), e.edit_status()), e))
|
||||||
}
|
}
|
||||||
pub fn view_arranger (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
ArrangerView::new(&self.project, self.editor.as_ref())
|
|
||||||
}
|
|
||||||
pub fn view_pool (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
PoolView(&self.project.pool)
|
|
||||||
}
|
|
||||||
pub fn view_samples_keys (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_samples_keys (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.project.sampler().map(|s|s.view_list(false, self.editor().unwrap()))
|
self.sampler().map(|s|s.view_list(false, self.editor().unwrap()))
|
||||||
}
|
}
|
||||||
pub fn view_samples_grid (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_samples_grid (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.project.sampler().map(|s|s.view_grid())
|
self.sampler().map(|s|s.view_grid())
|
||||||
}
|
}
|
||||||
pub fn view_sample_viewer (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_sample_viewer (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.project.sampler().map(|s|s.view_sample(self.editor().unwrap().get_note_pos()))
|
self.sampler().map(|s|s.view_sample(self.editor().unwrap().get_note_pos()))
|
||||||
}
|
}
|
||||||
pub fn view_sample_info (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_sample_info (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.project.sampler().map(|s|s.view_sample_info(self.editor().unwrap().get_note_pos()))
|
self.sampler().map(|s|s.view_sample_info(self.editor().unwrap().get_note_pos()))
|
||||||
}
|
}
|
||||||
pub fn view_meters_input (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_meters_input (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.project.sampler().map(|s|s.view_meters_input())
|
self.sampler().map(|s|s.view_meters_input())
|
||||||
}
|
}
|
||||||
pub fn view_meters_output (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_meters_output (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.project.sampler().map(|s|s.view_meters_output())
|
self.sampler().map(|s|s.view_meters_output())
|
||||||
}
|
}
|
||||||
pub fn view_dialog (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_dialog (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
When(self.dialog.is_some(), Bsp::b( "",
|
view_dialog(self)
|
||||||
Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
|
|
||||||
Repeat(" "), Outer(true, Style::default().fg(Tui::g(96)))
|
|
||||||
.enclose(self.dialog.as_ref().map(|dialog|match dialog {
|
|
||||||
Dialog::Menu(_) =>
|
|
||||||
self.view_dialog_menu().boxed(),
|
|
||||||
Dialog::Help(offset) =>
|
|
||||||
self.view_dialog_help(*offset).boxed(),
|
|
||||||
Dialog::Save(browser) =>
|
|
||||||
self.view_dialog_save().boxed(),
|
|
||||||
Dialog::Load(browser) =>
|
|
||||||
self.view_dialog_load().boxed(),
|
|
||||||
Dialog::Options =>
|
|
||||||
self.view_dialog_options().boxed(),
|
|
||||||
Dialog::Device(index) =>
|
|
||||||
self.view_dialog_device(*index).boxed(),
|
|
||||||
Dialog::Message(message) =>
|
|
||||||
self.view_dialog_message(message).boxed(),
|
|
||||||
}))
|
|
||||||
)))
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn view_dialog_menu (&self) -> impl Content<TuiOut> {
|
|
||||||
let options = ||["Projects", "Settings", "Help", "Quit"].iter();
|
/// Spacing between tracks.
|
||||||
let option = |a,i|Tui::fg(Rgb(255,255,255), format!("{}", a));
|
pub(crate) const TRACK_SPACING: usize = 0;
|
||||||
Bsp::s(Tui::bold(true, "tek!"), Bsp::s("", Map::south(1, options, option)))
|
|
||||||
|
/// Default scene height.
|
||||||
|
pub(crate) const H_SCENE: usize = 2;
|
||||||
|
|
||||||
|
/// Default editor height.
|
||||||
|
pub(crate) const H_EDITOR: usize = 15;
|
||||||
|
|
||||||
|
pub(crate) fn inputs_with_sizes (&self) -> impl PortsSizes<'_> {
|
||||||
|
let mut y = 0;
|
||||||
|
self.midi_ins.iter().enumerate().map(move|(i, input)|{
|
||||||
|
let height = 1 + input.conn().len();
|
||||||
|
let data = (i, input.name(), input.conn(), y, y + height);
|
||||||
|
y += height;
|
||||||
|
data
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pub fn view_dialog_help <'a> (&'a self, offset: usize) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
Bsp::s(Tui::bold(true, "Help"), Bsp::s("", Map::south(1,
|
pub(crate) fn tracks_with_sizes (&self) -> impl TracksSizes<'_> {
|
||||||
move||self.config.keys.layers.iter()
|
use Selection::*;
|
||||||
.filter_map(|a|(a.0)(self).then_some(a.1))
|
let mut x = 0;
|
||||||
.flat_map(|a|a)
|
let editing = self.is_editing();
|
||||||
.filter_map(|x|if let Value::Exp(_, iter)=x.value{ Some(iter) } else { None })
|
let active = match self.selected() {
|
||||||
.skip(offset)
|
Track(t) if editing => Some(t),
|
||||||
.take(20),
|
TrackClip { track, .. } if editing => Some(track),
|
||||||
|mut b,i|Fixed::x(60, Align::w(Bsp::e("(", Bsp::e(
|
_ => None
|
||||||
b.next().map(|t|Fixed::x(16, Align::w(Tui::fg(Rgb(64,224,0), format!("{}", t.value))))),
|
};
|
||||||
Bsp::e(" ", Align::w(format!("{}", b.0.0.trim()))))))))))
|
let bigger = self.editor_w();
|
||||||
|
self.tracks().iter().enumerate().map(move |(index, track)|{
|
||||||
|
let width = if Some(index) == active.copied() { bigger } else { track.width.max(8) };
|
||||||
|
let data = (index, track, x, x + width);
|
||||||
|
x += width + App::TRACK_SPACING;
|
||||||
|
data
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pub fn view_dialog_device (&self, index: usize) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
let choices = ||self.device_kinds().iter();
|
pub(crate) fn scenes_with_sizes (&self, editing: bool, height: usize, larger: usize)
|
||||||
let choice = move|label, i|
|
-> impl ScenesSizes<'_>
|
||||||
Fill::x(Tui::bg(if i == index { Rgb(64,128,32) } else { Rgb(0,0,0) },
|
{
|
||||||
Bsp::e(if i == index { "[ " } else { " " },
|
use Selection::*;
|
||||||
Bsp::w(if i == index { " ]" } else { " " },
|
let (selected_track, selected_scene) = match self.selected() {
|
||||||
label))));
|
Track(t) => (Some(*t), None),
|
||||||
Bsp::s(Tui::bold(true, "Add device"), Map::south(1, choices, choice))
|
Scene(s) => (None, Some(*s)),
|
||||||
|
TrackClip { track, scene } => (Some(*track), Some(*scene)),
|
||||||
|
_ => (None, None)
|
||||||
|
};
|
||||||
|
let mut y = 0;
|
||||||
|
self.scenes().iter().enumerate().map(move|(s, scene)|{
|
||||||
|
let active = editing && selected_track.is_some() && selected_scene == Some(s);
|
||||||
|
let height = if active { larger } else { height };
|
||||||
|
let data = (s, scene, y, y + height);
|
||||||
|
y += height;
|
||||||
|
data
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pub fn view_dialog_message <'a> (&'a self, message: &'a Message) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
Bsp::s(message, Bsp::s("", "[ OK ]"))
|
pub fn update_clock (&self) {
|
||||||
|
ViewCache::update_clock(&self.view_cache, self.clock(), self.size.w() > 80)
|
||||||
}
|
}
|
||||||
pub fn view_dialog_save <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
Bsp::s(
|
}
|
||||||
Fill::x(Align::w(Margin::xy(1, 1, Bsp::e(
|
|
||||||
Tui::bold(true, " Save project: "),
|
pub(crate) struct ArrangerView<'a> {
|
||||||
Shrink::x(3, Fixed::y(1, RepeatH("🭻"))))))),
|
app: &'a App,
|
||||||
Outer(true, Style::default().fg(Tui::g(96)))
|
|
||||||
.enclose(Fill::xy("todo file browser")))
|
is_editing: bool,
|
||||||
|
|
||||||
|
width: u16,
|
||||||
|
width_mid: u16,
|
||||||
|
width_side: u16,
|
||||||
|
|
||||||
|
inputs_count: usize,
|
||||||
|
inputs_height: u16,
|
||||||
|
|
||||||
|
outputs_count: usize,
|
||||||
|
outputs_height: u16,
|
||||||
|
|
||||||
|
scene_last: usize,
|
||||||
|
scene_count: usize,
|
||||||
|
scene_scroll: Fill<Fixed<u16, ScrollbarV>>,
|
||||||
|
scene_selected: Option<usize>,
|
||||||
|
scenes_height: u16,
|
||||||
|
|
||||||
|
track_scroll: Fill<Fixed<u16, ScrollbarH>>,
|
||||||
|
track_count: usize,
|
||||||
|
track_selected: Option<usize>,
|
||||||
|
tracks_height: u16,
|
||||||
|
|
||||||
|
show_debug_info: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Content<TuiOut> for ArrangerView<'a> {
|
||||||
|
fn content (&self) -> impl Render<TuiOut> {
|
||||||
|
let ins = |x|Bsp::n(self.inputs(), x);
|
||||||
|
let tracks = |x|Bsp::s(self.tracks(), x);
|
||||||
|
let devices = |x|Bsp::s(self.devices(), x);
|
||||||
|
let outs = |x|Bsp::s(self.outputs(), x);
|
||||||
|
let bg = |x|Tui::bg(Reset, x);
|
||||||
|
//let track_scroll = |x|Bsp::s(&self.track_scroll, x);
|
||||||
|
//let scene_scroll = |x|Bsp::e(&self.scene_scroll, x);
|
||||||
|
outs(tracks(devices(ins(bg(self.scenes())))))
|
||||||
}
|
}
|
||||||
pub fn view_dialog_load <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
}
|
||||||
Bsp::s(
|
|
||||||
Fill::x(Align::w(Margin::xy(1, 1, Bsp::e(
|
impl<'a> ArrangerView<'a> {
|
||||||
Tui::bold(true, " Load project: "),
|
pub fn new (app: &'a App) -> Self {
|
||||||
Shrink::x(3, Fixed::y(1, RepeatH("🭻"))))))),
|
Self {
|
||||||
Outer(true, Style::default().fg(Tui::g(96)))
|
app,
|
||||||
.enclose(Fill::xy("todo file browser")))
|
is_editing: app.is_editing(),
|
||||||
|
|
||||||
|
width: app.w(),
|
||||||
|
width_mid: app.w_tracks_area(),
|
||||||
|
width_side: app.w_sidebar(),
|
||||||
|
|
||||||
|
inputs_height: app.h_inputs(),
|
||||||
|
inputs_count: app.midi_ins.len(),
|
||||||
|
|
||||||
|
outputs_height: app.h_outputs(),
|
||||||
|
outputs_count: app.midi_outs.len(),
|
||||||
|
|
||||||
|
scenes_height: app.h_scenes_area(),
|
||||||
|
scene_selected: app.selected().scene(),
|
||||||
|
scene_count: app.scenes.len(),
|
||||||
|
scene_last: app.scenes.len().saturating_sub(1),
|
||||||
|
scene_scroll: Fill::y(Fixed::x(1, ScrollbarV {
|
||||||
|
offset: app.scene_scroll,
|
||||||
|
length: app.h_scenes_area() as usize,
|
||||||
|
total: app.h_scenes() as usize,
|
||||||
|
})),
|
||||||
|
|
||||||
|
tracks_height: app.h_tracks_area(),
|
||||||
|
track_count: app.tracks.len(),
|
||||||
|
track_selected: app.selected().track(),
|
||||||
|
track_scroll: Fill::x(Fixed::y(1, ScrollbarH {
|
||||||
|
offset: app.track_scroll,
|
||||||
|
length: app.h_tracks_area() as usize,
|
||||||
|
total: app.h_scenes() as usize,
|
||||||
|
})),
|
||||||
|
|
||||||
|
show_debug_info: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn view_dialog_options <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
"TODO"
|
/// Render input matrix.
|
||||||
|
pub(crate) fn inputs (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tui::bg(Reset, Bsp::s(
|
||||||
|
self.input_intos(),
|
||||||
|
Bsp::s(self.input_routes(), self.input_ports()),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Render device switches.
|
||||||
|
pub(crate) fn devices (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
let Self { width_side, width_mid, track_count, track_selected, is_editing, .. } = self;
|
||||||
|
Tryptich::top(1)
|
||||||
|
.left(*width_side, button_3("d", "devices", format!("{}", 0), *is_editing))
|
||||||
|
.right(*width_side, button_2("D", "add device", *is_editing))
|
||||||
|
.middle(*width_mid, per_track_top(*width_mid, ||self.tracks_with_sizes_scrolled(),
|
||||||
|
move|index, track|{
|
||||||
|
let bg = if *track_selected == Some(index) {
|
||||||
|
track.color.light
|
||||||
|
} else {
|
||||||
|
track.color.base
|
||||||
|
};
|
||||||
|
let fg = Tui::g(224);
|
||||||
|
track.devices.get(0).map(|device|wrap(bg.rgb, fg, device.name()))
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render track headers
|
||||||
|
pub(crate) fn tracks (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
let Self { width_side, width_mid, track_count, track_selected, is_editing, .. } = self;
|
||||||
|
Tryptich::center(3)
|
||||||
|
.left(*width_side, button_3("t", "track", format!("{}", *track_count), *is_editing))
|
||||||
|
.right(*width_side, button_2("T", "add track", *is_editing))
|
||||||
|
.middle(*width_mid, per_track(*width_mid, ||self.tracks_with_sizes_scrolled(),
|
||||||
|
|index, track|wrap(
|
||||||
|
if *track_selected == Some(index) {
|
||||||
|
track.color.light
|
||||||
|
} else {
|
||||||
|
track.color.base
|
||||||
|
}.rgb,
|
||||||
|
track.color.lightest.rgb,
|
||||||
|
Tui::bold(true, Fill::xy(Align::nw(&track.name)))
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_routes (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tryptich::top(self.inputs_height)
|
||||||
|
.left(self.width_side,
|
||||||
|
io_ports(Tui::g(224), Tui::g(32), ||self.app.inputs_with_sizes()))
|
||||||
|
.middle(self.width_mid,
|
||||||
|
per_track_top(self.width_mid, ||self.tracks_with_sizes_scrolled(),
|
||||||
|
move|_, &Track { color, .. }|io_conns(
|
||||||
|
color.dark.rgb,
|
||||||
|
color.darker.rgb,
|
||||||
|
||self.app.inputs_with_sizes()
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_ports (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tryptich::top(1)
|
||||||
|
.left(self.width_side,
|
||||||
|
button_3("i", "midi ins", format!("{}", self.inputs_count), self.is_editing))
|
||||||
|
.right(self.width_side,
|
||||||
|
button_2("I", "add midi in", self.is_editing))
|
||||||
|
.middle(self.width_mid,
|
||||||
|
per_track_top(
|
||||||
|
self.width_mid,
|
||||||
|
||self.tracks_with_sizes_scrolled(),
|
||||||
|
move|t, track|{
|
||||||
|
let rec = track.sequencer.recording;
|
||||||
|
let mon = track.sequencer.monitoring;
|
||||||
|
let rec = if rec { White } else { track.color.darkest.rgb };
|
||||||
|
let mon = if mon { White } else { track.color.darkest.rgb };
|
||||||
|
let bg = if self.track_selected == Some(t) {
|
||||||
|
track.color.light.rgb
|
||||||
|
} else {
|
||||||
|
track.color.base.rgb
|
||||||
|
};
|
||||||
|
//let bg2 = if t > 0 { track.color.base.rgb } else { Reset };
|
||||||
|
wrap(bg, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(
|
||||||
|
Tui::fg_bg(rec, bg, "Rec "),
|
||||||
|
Tui::fg_bg(mon, bg, "Mon "),
|
||||||
|
))))
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_intos (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tryptich::top(2)
|
||||||
|
.left(self.width_side,
|
||||||
|
Bsp::s(Align::e("Input:"), Align::e("Into clip:")))
|
||||||
|
.middle(self.width_mid,
|
||||||
|
per_track_top(
|
||||||
|
self.width_mid,
|
||||||
|
||self.tracks_with_sizes_scrolled(),
|
||||||
|
|_, _|Tui::bg(Reset, Align::c(Bsp::s(OctaveVertical::default(), " ------ ")))))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render scenes with clips
|
||||||
|
pub(crate) fn scenes (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
|
||||||
|
let Self {
|
||||||
|
width, width_side, width_mid,
|
||||||
|
scenes_height, scene_last, scene_selected,
|
||||||
|
track_selected, is_editing, app: App { editor, .. }, ..
|
||||||
|
} = self;
|
||||||
|
|
||||||
|
let scene_headers = Map::new(||self.scenes_with_scene_colors(),
|
||||||
|
move|(s, scene, y1, y2, previous): SceneWithColor, _|{
|
||||||
|
let height = (1 + y2 - y1) as u16;
|
||||||
|
let name = Some(scene.name.clone());
|
||||||
|
let content = Fill::x(Align::w(Tui::bold(true, Bsp::e(" ⯈ ", name))));
|
||||||
|
let same_track = true;
|
||||||
|
let selected = same_track && *scene_selected == Some(s);
|
||||||
|
let neighbor = same_track && s > 0 && *scene_selected == Some(s - 1);
|
||||||
|
let is_last = *scene_last == s;
|
||||||
|
let theme = scene.color;
|
||||||
|
let fg = theme.lightest.rgb;
|
||||||
|
let bg = if selected { theme.light } else { theme.base }.rgb;
|
||||||
|
let hi = if let Some(previous) = previous {
|
||||||
|
if neighbor {
|
||||||
|
previous.light.rgb
|
||||||
|
} else {
|
||||||
|
previous.base.rgb
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Reset
|
||||||
|
};
|
||||||
|
let lo = if is_last {
|
||||||
|
Reset
|
||||||
|
} else if selected {
|
||||||
|
theme.light.rgb
|
||||||
|
} else {
|
||||||
|
theme.base.rgb
|
||||||
|
};
|
||||||
|
Fill::x(map_south(y1 as u16, height, Fixed::y(height, Phat {
|
||||||
|
width: 0, height: 0, content, colors: [fg, bg, hi, lo]
|
||||||
|
})))
|
||||||
|
});
|
||||||
|
|
||||||
|
let scene_track_clips = per_track(*width_mid, ||self.tracks_with_sizes_scrolled(),
|
||||||
|
move|track_index, track|Map::new(move||self.scenes_with_track_colors(track_index),
|
||||||
|
move|(s, scene, y1, y2, previous): SceneWithColor<'a>, _|{
|
||||||
|
let (name, theme) = if let Some(clip) = &scene.clips[track_index] {
|
||||||
|
let clip = clip.read().unwrap();
|
||||||
|
(Some(clip.name.clone()), clip.color)
|
||||||
|
} else {
|
||||||
|
(None, ItemTheme::G[32])
|
||||||
|
};
|
||||||
|
let height = (1 + y2 - y1) as u16;
|
||||||
|
let content = Fill::x(Align::w(Tui::bold(true, Bsp::e(" ⏹ ", name))));
|
||||||
|
let same_track = *track_selected == Some(track_index);
|
||||||
|
let selected = same_track && *scene_selected == Some(s);
|
||||||
|
let neighbor = same_track && s > 0 && *scene_selected == Some(s - 1);
|
||||||
|
let is_last = *scene_last == s;
|
||||||
|
let fg = theme.lightest.rgb;
|
||||||
|
let bg = if selected { theme.light } else { theme.base }.rgb;
|
||||||
|
let hi = if let Some(previous) = previous {
|
||||||
|
if neighbor {
|
||||||
|
previous.light.rgb
|
||||||
|
} else {
|
||||||
|
previous.base.rgb
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Reset
|
||||||
|
};
|
||||||
|
let lo = if is_last {
|
||||||
|
Reset
|
||||||
|
} else if selected {
|
||||||
|
theme.light.rgb
|
||||||
|
} else {
|
||||||
|
theme.base.rgb
|
||||||
|
};
|
||||||
|
map_south(y1 as u16, height, Bsp::b(Fixed::y(height, Phat {
|
||||||
|
width: 0, height: 0, content, colors: [fg, bg, hi, lo]
|
||||||
|
}), When(
|
||||||
|
*is_editing && same_track && *scene_selected == Some(s),
|
||||||
|
editor
|
||||||
|
)))
|
||||||
|
}));
|
||||||
|
|
||||||
|
Tryptich::center(*scenes_height)
|
||||||
|
.left(*width_side, scene_headers)
|
||||||
|
.middle(*width_mid, scene_track_clips)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn tracks_with_sizes_scrolled (&'a self)
|
||||||
|
-> impl TracksSizes<'a>
|
||||||
|
{
|
||||||
|
let width = self.width_mid;
|
||||||
|
self.app.tracks_with_sizes().map_while(move|(t, track, x1, x2)|{
|
||||||
|
(width > x2 as u16).then_some((t, track, x1, x2))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn scenes_with_scene_colors (&self)
|
||||||
|
-> impl ScenesColors<'_>
|
||||||
|
{
|
||||||
|
self.app.scenes_with_sizes(self.is_editing, App::H_SCENE, App::H_EDITOR).map_while(
|
||||||
|
move|(s, scene, y1, y2)|if y2 as u16 > self.scenes_height {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some((s, scene, y1, y2, if s == 0 {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(self.app.scenes()[s-1].color)
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn scenes_with_track_colors (&self, track: usize)
|
||||||
|
-> impl ScenesColors<'_>
|
||||||
|
{
|
||||||
|
self.app.scenes_with_sizes(self.is_editing, App::H_SCENE, App::H_EDITOR).map_while(
|
||||||
|
move|(s, scene, y1, y2)|if y2 as u16 > self.scenes_height {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some((s, scene, y1, y2, if s == 0 {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(self.app.scenes[s-1].clips[track].as_ref()
|
||||||
|
.map(|c|c.read().unwrap().color)
|
||||||
|
.unwrap_or(ItemTheme::G[32]))
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Iterator over scenes with their sizes and colors.
|
||||||
|
pub(crate) trait ScenesColors<'a> =
|
||||||
|
Iterator<Item=SceneWithColor<'a>>;
|
||||||
|
|
||||||
|
/// A scene with size and color.
|
||||||
|
pub(crate) type SceneWithColor<'a> =
|
||||||
|
(usize, &'a Scene, usize, usize, Option<ItemTheme>);
|
||||||
|
|
||||||
|
/// Define a type alias for iterators of sized items (columns).
|
||||||
|
macro_rules! def_sizes_iter {
|
||||||
|
($Type:ident => $($Item:ty),+) => {
|
||||||
|
pub(crate) trait $Type<'a> =
|
||||||
|
Iterator<Item=(usize, $(&'a $Item,)+ usize, usize)> + Send + Sync + 'a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def_sizes_iter!(ScenesSizes => Scene);
|
||||||
|
|
||||||
|
def_sizes_iter!(TracksSizes => Track);
|
||||||
|
|
||||||
|
def_sizes_iter!(InputsSizes => JackMidiIn);
|
||||||
|
|
||||||
|
def_sizes_iter!(OutputsSizes => JackMidiOut);
|
||||||
|
|
||||||
|
def_sizes_iter!(PortsSizes => Arc<str>, [PortConnect]);
|
||||||
|
|
||||||
|
pub(crate) fn wrap (bg: Color, fg: Color, content: impl Content<TuiOut>) -> impl Content<TuiOut> {
|
||||||
|
let left = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("▐")));
|
||||||
|
let right = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("▌")));
|
||||||
|
Bsp::e(left, Bsp::w(right, Tui::fg_bg(fg, bg, content)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn button_2 <'a> (
|
||||||
|
key: impl Content<TuiOut> + 'a, label: impl Content<TuiOut> + 'a, editing: bool,
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
let key = Tui::fg_bg(Tui::g(0), Tui::orange(), Bsp::e(
|
||||||
|
Tui::fg_bg(Tui::orange(), Reset, "▐"),
|
||||||
|
Bsp::e(key, Tui::fg(Tui::g(96), "▐"))
|
||||||
|
));
|
||||||
|
let label = When::new(!editing, Tui::fg_bg(Tui::g(255), Tui::g(96), label));
|
||||||
|
Tui::bold(true, Bsp::e(key, label))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn button_3 <'a, K, L, V> (
|
||||||
|
key: K,
|
||||||
|
label: L,
|
||||||
|
value: V,
|
||||||
|
editing: bool,
|
||||||
|
) -> impl Content<TuiOut> + 'a where
|
||||||
|
K: Content<TuiOut> + 'a,
|
||||||
|
L: Content<TuiOut> + 'a,
|
||||||
|
V: Content<TuiOut> + 'a,
|
||||||
|
{
|
||||||
|
let key = Tui::fg_bg(Tui::g(0), Tui::orange(),
|
||||||
|
Bsp::e(Tui::fg_bg(Tui::orange(), Reset, "▐"), Bsp::e(key, Tui::fg(if editing {
|
||||||
|
Tui::g(128)
|
||||||
|
} else {
|
||||||
|
Tui::g(96)
|
||||||
|
}, "▐"))));
|
||||||
|
let label = Bsp::e(
|
||||||
|
When::new(!editing, Bsp::e(
|
||||||
|
Tui::fg_bg(Tui::g(255), Tui::g(96), label),
|
||||||
|
Tui::fg_bg(Tui::g(128), Tui::g(96), "▐"),
|
||||||
|
)),
|
||||||
|
Bsp::e(
|
||||||
|
Tui::fg_bg(Tui::g(224), Tui::g(128), value),
|
||||||
|
Tui::fg_bg(Tui::g(128), Reset, "▌"),
|
||||||
|
));
|
||||||
|
Tui::bold(true, Bsp::e(key, label))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn heading <'a> (
|
pub(crate) fn heading <'a> (
|
||||||
|
|
@ -140,6 +510,57 @@ pub(crate) fn heading <'a> (
|
||||||
Fill::xy(Align::w(Bsp::s(Fill::x(Align::w(button_3(key, label, count, editing))), content)))
|
Fill::xy(Align::w(Bsp::s(Fill::x(Align::w(button_3(key, label, count, editing))), content)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn io_ports <'a, T: PortsSizes<'a>> (
|
||||||
|
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Map::new(iter, move|(
|
||||||
|
index, name, connections, y, y2
|
||||||
|
): (usize, &'a Arc<str>, &'a [PortConnect], usize, usize), _|
|
||||||
|
map_south(y as u16, (y2-y) as u16, Bsp::s(
|
||||||
|
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(Bsp::e(" ", name))))),
|
||||||
|
Map::new(||connections.iter(), move|connect: &'a PortConnect, index|map_south(index as u16, 1,
|
||||||
|
Fill::x(Align::w(Tui::bold(false, Tui::fg_bg(fg, bg,
|
||||||
|
&connect.info)))))))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn io_conns <'a, T: PortsSizes<'a>> (
|
||||||
|
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Map::new(iter, move|(
|
||||||
|
index, name, connections, y, y2
|
||||||
|
): (usize, &'a Arc<str>, &'a [PortConnect], usize, usize), _|
|
||||||
|
map_south(y as u16, (y2-y) as u16, Bsp::s(
|
||||||
|
Fill::x(Tui::bold(true, wrap(bg, fg, Fill::x(Align::w("▞▞▞▞ ▞▞▞▞"))))),
|
||||||
|
Map::new(||connections.iter(), move|connect, index|map_south(index as u16, 1,
|
||||||
|
Fill::x(Align::w(Tui::bold(false, wrap(bg, fg, Fill::x(""))))))))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
|
||||||
|
width: u16,
|
||||||
|
tracks: impl Fn() -> U + Send + Sync + 'a,
|
||||||
|
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Align::x(Tui::bg(Reset, Map::new(tracks,
|
||||||
|
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{
|
||||||
|
let width = (x2 - x1) as u16;
|
||||||
|
map_east(x1 as u16, width, Fixed::x(width, Tui::fg_bg(
|
||||||
|
track.color.lightest.rgb,
|
||||||
|
track.color.base.rgb,
|
||||||
|
callback(index, track))))})))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn per_track <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
|
||||||
|
width: u16,
|
||||||
|
tracks: impl Fn() -> U + Send + Sync + 'a,
|
||||||
|
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
per_track_top(
|
||||||
|
width,
|
||||||
|
tracks,
|
||||||
|
move|index, track|Fill::y(Align::y(callback(index, track)))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Clear a pre-allocated buffer, then write into it.
|
/// Clear a pre-allocated buffer, then write into it.
|
||||||
#[macro_export] macro_rules! rewrite {
|
#[macro_export] macro_rules! rewrite {
|
||||||
($buf:ident, $($rest:tt)*) => { |$buf,_,_|{ $buf.clear(); write!($buf, $($rest)*) } }
|
($buf:ident, $($rest:tt)*) => { |$buf,_,_|{ $buf.clear(); write!($buf, $($rest)*) } }
|
||||||
|
|
|
||||||
99
crates/app/src/view/view_dialog.rs
Normal file
99
crates/app/src/view/view_dialog.rs
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
pub(crate) fn view_dialog (app: &App) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
When::new(app.dialog.is_some(), Bsp::b(
|
||||||
|
"",
|
||||||
|
Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
|
||||||
|
Repeat(" "),
|
||||||
|
Outer(true, Style::default().fg(Tui::g(96)))
|
||||||
|
.enclose(app.dialog.as_ref().map(|dialog|match dialog {
|
||||||
|
Dialog::Menu => app.view_dialog_menu().boxed(),
|
||||||
|
Dialog::Help => app.view_dialog_help().boxed(),
|
||||||
|
Dialog::Save => app.view_dialog_save().boxed(),
|
||||||
|
Dialog::Load => app.view_dialog_load().boxed(),
|
||||||
|
Dialog::Options => app.view_dialog_options().boxed(),
|
||||||
|
Dialog::Device(index) => app.view_dialog_device(*index).boxed(),
|
||||||
|
Dialog::Message(message) => app.view_dialog_message(message).boxed(),
|
||||||
|
}))
|
||||||
|
)))
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn view_dialog_menu (&self) -> impl Content<TuiOut> {
|
||||||
|
let options = ||["Projects", "Settings", "Help", "Quit"].iter();
|
||||||
|
let option = |a,i|Tui::fg(Rgb(255,255,255), format!("{}", a));
|
||||||
|
Bsp::s(Tui::bold(true, "tek!"), Bsp::s("", Map::south(1, options, option)))
|
||||||
|
}
|
||||||
|
pub fn view_dialog_help <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
//let bindings = ;
|
||||||
|
//let binding = ;[> Bsp::e(
|
||||||
|
//Fixed::x(15, Align::w(Tui::bold(true, Tui::fg(Rgb(255,192,0), if let Some(Token {
|
||||||
|
//value: Value::Sym(key), ..
|
||||||
|
//}) = binding.next() {
|
||||||
|
//Some(key.to_string())
|
||||||
|
//} else {
|
||||||
|
//None
|
||||||
|
//})))),
|
||||||
|
//Bsp::e(" ", Tui::fg(Rgb(255,255,255), if let Some(Token {
|
||||||
|
//value: Value::Key(command), ..
|
||||||
|
//}) = binding.next() {
|
||||||
|
//Some(command.to_string())
|
||||||
|
//} else {
|
||||||
|
//None
|
||||||
|
//})),
|
||||||
|
//);*/
|
||||||
|
Bsp::s(Tui::bold(true, "Help"), Bsp::s("", Map::south(1,
|
||||||
|
||self.config.keys.layers.iter()
|
||||||
|
.filter_map(|a|(a.0)(self).then_some(a.1))
|
||||||
|
.flat_map(|a|a)
|
||||||
|
.filter_map(|x|if let Value::Exp(_, iter)=x.value{
|
||||||
|
Some(iter)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.take(20),
|
||||||
|
|mut b,i|Bsp::e(
|
||||||
|
Min::x(30, Max::x(60, format!("?"))),
|
||||||
|
b.next().map(|t|Min::x(16, Tui::fg(Rgb(224,64,0), format!("{}", t.value)))),
|
||||||
|
))))
|
||||||
|
//format!("{b:?}")))))
|
||||||
|
//|mut binding: TokenIter, _|Map::east(5, move||binding.clone(), |_,_|"kyp"))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_dialog_device (&self, index: usize) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
let choices = ||self.device_kinds().iter();
|
||||||
|
let choice = move|label, i|
|
||||||
|
Fill::x(Tui::bg(if i == index { Rgb(64,128,32) } else { Rgb(0,0,0) },
|
||||||
|
Bsp::e(if i == index { "[ " } else { " " },
|
||||||
|
Bsp::w(if i == index { " ]" } else { " " },
|
||||||
|
label))));
|
||||||
|
Bsp::s(Tui::bold(true, "Add device"), Map::south(1, choices, choice))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_dialog_message <'a> (&'a self, message: &'a Message) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
Bsp::s(message, Bsp::s("", "[ OK ]"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_dialog_save <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
Bsp::s(
|
||||||
|
Fill::x(Align::w(Margin::xy(1, 1, Bsp::e(
|
||||||
|
Tui::bold(true, " Save project: "),
|
||||||
|
Shrink::x(3, Fixed::y(1, RepeatH("🭻"))))))),
|
||||||
|
Outer(true, Style::default().fg(Tui::g(96)))
|
||||||
|
.enclose(Fill::xy("todo file browser")))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_dialog_load <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
Bsp::s(
|
||||||
|
Fill::x(Align::w(Margin::xy(1, 1, Bsp::e(
|
||||||
|
Tui::bold(true, " Load project: "),
|
||||||
|
Shrink::x(3, Fixed::y(1, RepeatH("🭻"))))))),
|
||||||
|
Outer(true, Style::default().fg(Tui::g(96)))
|
||||||
|
.enclose(Fill::xy("todo file browser")))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_dialog_options <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
"TODO"
|
||||||
|
}
|
||||||
|
}
|
||||||
92
crates/app/src/view/view_output.rs
Normal file
92
crates/app/src/view/view_output.rs
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
/// Outputs.
|
||||||
|
impl App {
|
||||||
|
pub(crate) fn outputs_with_sizes (&self) -> impl PortsSizes<'_> {
|
||||||
|
let mut y = 0;
|
||||||
|
self.midi_outs.iter().enumerate().map(move|(i, output)|{
|
||||||
|
let height = 1 + output.conn().len();
|
||||||
|
let data = (i, output.name(), output.conn(), y, y + height);
|
||||||
|
y += height;
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'a> ArrangerView<'a> {
|
||||||
|
fn output_nexts (&self) -> impl Content<TuiOut> + '_ {
|
||||||
|
Tryptich::top(2)
|
||||||
|
.left(self.width_side, Align::ne("From clip:"))
|
||||||
|
.middle(self.width_mid, per_track_top(
|
||||||
|
self.width_mid,
|
||||||
|
||self.tracks_with_sizes_scrolled(),
|
||||||
|
|_, _|Tui::bg(Reset, Align::c(Bsp::s(" ------ ", OctaveVertical::default())))))
|
||||||
|
}
|
||||||
|
/// Render output matrix.
|
||||||
|
pub(crate) fn outputs (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tui::bg(Reset, Align::n(Bsp::s(
|
||||||
|
Bsp::s(self.output_ports(), self.output_conns()),
|
||||||
|
Bsp::s(self.output_nexts(), self.output_froms()),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
fn output_froms (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
let label = Align::ne("Next clip:");
|
||||||
|
Tryptich::top(2).left(self.width_side, label).middle(self.width_mid, per_track_top(
|
||||||
|
self.width_mid, ||self.tracks_with_sizes_scrolled(), |t, track|{
|
||||||
|
let queued = track.sequencer.next_clip.is_some();
|
||||||
|
let queued_blank = Thunk::new(||Tui::bg(Reset, " ------ "));
|
||||||
|
let queued_clip = Thunk::new(||{
|
||||||
|
Tui::bg(Reset, if let Some((_, clip)) = track.sequencer.next_clip.as_ref() {
|
||||||
|
if let Some(clip) = clip {
|
||||||
|
clip.read().unwrap().name.clone()
|
||||||
|
} else {
|
||||||
|
"Stop".into()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"".into()
|
||||||
|
})
|
||||||
|
});
|
||||||
|
Either(queued, queued_clip, queued_blank)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
fn output_ports (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tryptich::top(1)
|
||||||
|
.left(self.width_side, self.output_count())
|
||||||
|
.right(self.width_side, self.output_add())
|
||||||
|
.middle(self.width_mid, self.output_map())
|
||||||
|
}
|
||||||
|
fn output_count (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
button_3("o", "midi outs", format!("{}", self.outputs_count), self.is_editing)
|
||||||
|
}
|
||||||
|
fn output_add (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
button_2("O", "add midi out", self.is_editing)
|
||||||
|
}
|
||||||
|
fn output_map (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
per_track_top(self.width_mid, ||self.tracks_with_sizes_scrolled(), move|i, t|{
|
||||||
|
let mute = false;
|
||||||
|
let solo = false;
|
||||||
|
let mute = if mute { White } else { t.color.darkest.rgb };
|
||||||
|
let solo = if solo { White } else { t.color.darkest.rgb };
|
||||||
|
let bg_1 = if self.track_selected == Some(i) {
|
||||||
|
t.color.light.rgb
|
||||||
|
} else {
|
||||||
|
t.color.base.rgb
|
||||||
|
};
|
||||||
|
let bg_2 = if i > 0 { t.color.base.rgb } else { Reset };
|
||||||
|
let mute = Tui::fg_bg(mute, bg_1, "Play ");
|
||||||
|
let solo = Tui::fg_bg(solo, bg_1, "Solo ");
|
||||||
|
wrap(bg_1, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(mute, solo))))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn output_conns (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tryptich::top(self.outputs_height)
|
||||||
|
.left(self.width_side, io_ports(Tui::g(224), Tui::g(32), ||self.app.outputs_with_sizes()))
|
||||||
|
.middle(self.width_mid, per_track_top(
|
||||||
|
self.width_mid,
|
||||||
|
||self.tracks_with_sizes_scrolled(),
|
||||||
|
|_, t|io_conns(
|
||||||
|
t.color.dark.rgb,
|
||||||
|
t.color.darker.rgb,
|
||||||
|
||self.app.outputs_with_sizes()
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -72,24 +72,28 @@ pub enum LaunchMode {
|
||||||
|
|
||||||
impl Cli {
|
impl Cli {
|
||||||
pub fn run (&self) -> Usually<()> {
|
pub fn run (&self) -> Usually<()> {
|
||||||
let name = self.name.as_ref().map_or("tek", |x|x.as_str());
|
let name = self.name.as_ref().map_or("tek", |x|x.as_str());
|
||||||
let empty = &[] as &[&str];
|
let mode = &self.mode;
|
||||||
let mut midi_ins = vec![];
|
let empty = &[] as &[&str];
|
||||||
let mut midi_outs = vec![];
|
let midi_froms = PortConnect::collect(&self.midi_from, empty, &self.midi_from_re);
|
||||||
let mut tracks = vec![];
|
let midi_tos = PortConnect::collect(&self.midi_to, empty, &self.midi_to_re);
|
||||||
let mut scenes = vec![];
|
let left_froms = PortConnect::collect(&self.left_from, empty, empty);
|
||||||
let midi_froms = PortConnect::collect(&self.midi_from, empty, &self.midi_from_re);
|
let left_tos = PortConnect::collect(&self.left_to, empty, empty);
|
||||||
let midi_tos = PortConnect::collect(&self.midi_to, empty, &self.midi_to_re);
|
let right_froms = PortConnect::collect(&self.right_from, empty, empty);
|
||||||
let left_froms = PortConnect::collect(&self.left_from, empty, empty);
|
let right_tos = PortConnect::collect(&self.right_to, empty, empty);
|
||||||
let left_tos = PortConnect::collect(&self.left_to, empty, empty);
|
let audio_froms = &[left_froms.as_slice(), right_froms.as_slice()];
|
||||||
let right_froms = PortConnect::collect(&self.right_from, empty, empty);
|
let audio_tos = &[left_tos.as_slice(), right_tos.as_slice()];
|
||||||
let right_tos = PortConnect::collect(&self.right_to, empty, empty);
|
let clip = match mode {
|
||||||
let audio_froms = &[left_froms.as_slice(), right_froms.as_slice()];
|
LaunchMode::Sequencer | LaunchMode::Groovebox =>
|
||||||
let audio_tos = &[left_tos.as_slice(), right_tos.as_slice()];
|
Some(Arc::new(RwLock::new(MidiClip::new(
|
||||||
let clip = Arc::new(RwLock::new(MidiClip::new(
|
"Clip", true, 384usize, None, Some(ItemColor::random().into())),
|
||||||
"Clip", true, 384usize, None, Some(ItemColor::random().into())),
|
))),
|
||||||
));
|
_ => None,
|
||||||
|
};
|
||||||
|
let scenes = vec![];
|
||||||
Tui::new()?.run(&Jack::new(name)?.run(|jack|{
|
Tui::new()?.run(&Jack::new(name)?.run(|jack|{
|
||||||
|
let mut midi_ins = vec![];
|
||||||
|
let mut midi_outs = vec![];
|
||||||
for (index, connect) in midi_froms.iter().enumerate() {
|
for (index, connect) in midi_froms.iter().enumerate() {
|
||||||
let port = JackMidiIn::new(jack, &format!("M/{index}"), &[connect.clone()])?;
|
let port = JackMidiIn::new(jack, &format!("M/{index}"), &[connect.clone()])?;
|
||||||
midi_ins.push(port);
|
midi_ins.push(port);
|
||||||
|
|
@ -98,57 +102,79 @@ impl Cli {
|
||||||
let port = JackMidiOut::new(jack, &format!("{index}/M"), &[connect.clone()])?;
|
let port = JackMidiOut::new(jack, &format!("{index}/M"), &[connect.clone()])?;
|
||||||
midi_outs.push(port);
|
midi_outs.push(port);
|
||||||
};
|
};
|
||||||
let config = Configuration::new(&match self.mode {
|
let config_path = match mode {
|
||||||
LaunchMode::Clock => "config/config_transport.edn",
|
LaunchMode::Clock => "config/config_transport.edn",
|
||||||
LaunchMode::Sequencer => "config/config_sequencer.edn",
|
LaunchMode::Sequencer => "config/config_sequencer.edn",
|
||||||
LaunchMode::Groovebox => "config/config_groovebox.edn",
|
LaunchMode::Groovebox => "config/config_groovebox.edn",
|
||||||
LaunchMode::Arranger { .. } => "config/config_arranger.edn",
|
LaunchMode::Arranger { .. } => "config/config_arranger.edn",
|
||||||
LaunchMode::Sampler => "config/config_sampler.edn",
|
LaunchMode::Sampler => "config/config_sampler.edn",
|
||||||
_ => todo!("{:?}", self.mode),
|
_ => todo!("{mode:?}"),
|
||||||
}, false)?;
|
};
|
||||||
let clock = Clock::new(jack, self.bpm)?;
|
let config = Configuration::new(&config_path, false)?;
|
||||||
match self.mode {
|
let clock = Clock::new(jack, self.bpm)?;
|
||||||
LaunchMode::Sequencer => tracks.push(Track::new(
|
|
||||||
&name, None, jack, Some(&clock), Some(&clip),
|
|
||||||
midi_froms.as_slice(), midi_tos.as_slice()
|
|
||||||
)?),
|
|
||||||
LaunchMode::Groovebox | LaunchMode::Sampler => tracks.push(Track::new_with_sampler(
|
|
||||||
&name, None, jack, Some(&clock), Some(&clip),
|
|
||||||
midi_froms.as_slice(), midi_tos.as_slice(), audio_froms, audio_tos,
|
|
||||||
)?),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
jack: jack.clone(),
|
jack: jack.clone(),
|
||||||
config,
|
|
||||||
color: ItemTheme::random(),
|
color: ItemTheme::random(),
|
||||||
editor: match self.mode {
|
pool: match mode {
|
||||||
LaunchMode::Sequencer | LaunchMode::Groovebox => Some((&clip).into()),
|
LaunchMode::Sequencer | LaunchMode::Groovebox => clip.as_ref().map(Into::into),
|
||||||
|
LaunchMode::Arranger { .. } => Some(Default::default()),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
editor: match mode {
|
||||||
|
LaunchMode::Sequencer | LaunchMode::Groovebox => clip.as_ref().map(Into::into),
|
||||||
|
LaunchMode::Arranger { .. } => Some(Default::default()),
|
||||||
_ => None
|
_ => None
|
||||||
},
|
},
|
||||||
project: Arrangement {
|
midi_ins,
|
||||||
name: Default::default(),
|
midi_outs,
|
||||||
color: ItemTheme::random(),
|
midi_buf: match mode {
|
||||||
jack: jack.clone(),
|
LaunchMode::Clock |
|
||||||
clock,
|
LaunchMode::Sampler =>
|
||||||
tracks,
|
vec![],
|
||||||
scenes,
|
LaunchMode::Sequencer |
|
||||||
selection: Selection::TrackClip { track: 0, scene: 0 },
|
LaunchMode::Groovebox |
|
||||||
midi_ins,
|
LaunchMode::Arranger {..} =>
|
||||||
midi_outs,
|
vec![vec![];65536],
|
||||||
pool: match self.mode {
|
_ => todo!("{mode:?}"),
|
||||||
LaunchMode::Sequencer | LaunchMode::Groovebox => (&clip).into(),
|
|
||||||
_ => Default::default()
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
},
|
},
|
||||||
|
tracks: match mode {
|
||||||
|
LaunchMode::Sequencer => vec![
|
||||||
|
Track::new(
|
||||||
|
&name,
|
||||||
|
None,
|
||||||
|
jack,
|
||||||
|
Some(&clock),
|
||||||
|
clip.as_ref(),
|
||||||
|
midi_froms.as_slice(),
|
||||||
|
midi_tos.as_slice()
|
||||||
|
)?
|
||||||
|
],
|
||||||
|
LaunchMode::Groovebox | LaunchMode::Sampler => vec![
|
||||||
|
Track::new_with_sampler(
|
||||||
|
&name,
|
||||||
|
None,
|
||||||
|
jack,
|
||||||
|
Some(&clock),
|
||||||
|
clip.as_ref(),
|
||||||
|
midi_froms.as_slice(),
|
||||||
|
midi_tos.as_slice(),
|
||||||
|
audio_froms,
|
||||||
|
audio_tos,
|
||||||
|
)?
|
||||||
|
],
|
||||||
|
_ => vec![]
|
||||||
|
},
|
||||||
|
scenes,
|
||||||
|
selected: Selection::TrackClip { track: 0, scene: 0 },
|
||||||
|
config,
|
||||||
|
clock,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
if let LaunchMode::Arranger { scenes, tracks, track_width, .. } = self.mode {
|
if let &LaunchMode::Arranger { scenes, tracks, track_width, .. } = mode {
|
||||||
app.project.arranger = Default::default();
|
app.arranger = Default::default();
|
||||||
app.project.selection = Selection::TrackClip { track: 1, scene: 1 };
|
app.selected = Selection::TrackClip { track: 1, scene: 1 };
|
||||||
app.project.scenes_add(scenes)?;
|
app.scenes_add(scenes)?;
|
||||||
app.project.tracks_add(tracks, Some(track_width), &[], &[])?;
|
app.tracks_add(tracks, Some(track_width), &[], &[])?;
|
||||||
}
|
}
|
||||||
jack.sync_lead(self.sync_lead, |mut state|{
|
jack.sync_lead(self.sync_lead, |mut state|{
|
||||||
let clock = app.clock();
|
let clock = app.clock();
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,8 @@ wavers = { workspace = true, optional = true }
|
||||||
winit = { workspace = true, optional = true }
|
winit = { workspace = true, optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "browser", "clock", "editor", "sequencer", "sampler", "lv2", "arranger" ]
|
default = [ "browser", "clock", "editor", "sequencer", "sampler", "lv2" ]
|
||||||
clock = []
|
clock = []
|
||||||
arranger = [ "editor" ]
|
|
||||||
editor = []
|
editor = []
|
||||||
meter = []
|
meter = []
|
||||||
mixer = []
|
mixer = []
|
||||||
|
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
/// Define a type alias for iterators of sized items (columns).
|
|
||||||
macro_rules! def_sizes_iter {
|
|
||||||
($Type:ident => $($Item:ty),+) => {
|
|
||||||
pub(crate) trait $Type<'a> =
|
|
||||||
Iterator<Item=(usize, $(&'a $Item,)+ usize, usize)> + Send + Sync + 'a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod arranger_api; pub use self::arranger_api::*;
|
|
||||||
mod arranger_clip; pub use self::arranger_clip::*;
|
|
||||||
mod arranger_model; pub use self::arranger_model::*;
|
|
||||||
mod arranger_port; pub use self::arranger_port::*;
|
|
||||||
mod arranger_scene; pub use self::arranger_scene::*;
|
|
||||||
mod arranger_scenes; pub use self::arranger_scenes::*;
|
|
||||||
mod arranger_select; pub use self::arranger_select::*;
|
|
||||||
mod arranger_track; pub use self::arranger_track::*;
|
|
||||||
mod arranger_tracks; pub use self::arranger_tracks::*;
|
|
||||||
mod arranger_view; pub use self::arranger_view::*;
|
|
||||||
|
|
||||||
def_sizes_iter!(ScenesSizes => Scene);
|
|
||||||
def_sizes_iter!(TracksSizes => Track);
|
|
||||||
def_sizes_iter!(InputsSizes => JackMidiIn);
|
|
||||||
def_sizes_iter!(OutputsSizes => JackMidiOut);
|
|
||||||
def_sizes_iter!(PortsSizes => Arc<str>, [PortConnect]);
|
|
||||||
|
|
||||||
pub(crate) fn wrap (bg: Color, fg: Color, content: impl Content<TuiOut>) -> impl Content<TuiOut> {
|
|
||||||
let left = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("▐")));
|
|
||||||
let right = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("▌")));
|
|
||||||
Bsp::e(left, Bsp::w(right, Tui::fg_bg(fg, bg, content)))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn io_ports <'a, T: PortsSizes<'a>> (
|
|
||||||
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
Map::new(iter, move|(
|
|
||||||
index, name, connections, y, y2
|
|
||||||
): (usize, &'a Arc<str>, &'a [PortConnect], usize, usize), _|
|
|
||||||
map_south(y as u16, (y2-y) as u16, Bsp::s(
|
|
||||||
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(Bsp::e(" ", name))))),
|
|
||||||
Map::new(||connections.iter(), move|connect: &'a PortConnect, index|map_south(index as u16, 1,
|
|
||||||
Fill::x(Align::w(Tui::bold(false, Tui::fg_bg(fg, bg,
|
|
||||||
&connect.info)))))))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn io_conns <'a, T: PortsSizes<'a>> (
|
|
||||||
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
Map::new(iter, move|(
|
|
||||||
index, name, connections, y, y2
|
|
||||||
): (usize, &'a Arc<str>, &'a [PortConnect], usize, usize), _|
|
|
||||||
map_south(y as u16, (y2-y) as u16, Bsp::s(
|
|
||||||
Fill::x(Tui::bold(true, wrap(bg, fg, Fill::x(Align::w("▞▞▞▞ ▞▞▞▞"))))),
|
|
||||||
Map::new(||connections.iter(), move|connect, index|map_south(index as u16, 1,
|
|
||||||
Fill::x(Align::w(Tui::bold(false, wrap(bg, fg, Fill::x(""))))))))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait HasWidth {
|
|
||||||
const MIN_WIDTH: usize;
|
|
||||||
/// Increment track width.
|
|
||||||
fn width_inc (&mut self);
|
|
||||||
/// Decrement track width, down to a hardcoded minimum of [Self::MIN_WIDTH].
|
|
||||||
fn width_dec (&mut self);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HasWidth for Track {
|
|
||||||
const MIN_WIDTH: usize = 9;
|
|
||||||
fn width_inc (&mut self) {
|
|
||||||
self.width += 1;
|
|
||||||
}
|
|
||||||
fn width_dec (&mut self) {
|
|
||||||
if self.width > Track::MIN_WIDTH {
|
|
||||||
self.width -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,211 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
#[tengri_proc::expose]
|
|
||||||
impl Arrangement {
|
|
||||||
fn _todo_usize_stub_ (&self) -> usize { todo!() }
|
|
||||||
fn _todo_arc_str_stub_ (&self) -> Arc<str> { todo!() }
|
|
||||||
fn _todo_item_theme_stub (&self) -> ItemTheme { todo!() }
|
|
||||||
fn _todo_opt_item_theme_stub (&self) -> Option<ItemTheme> { todo!() }
|
|
||||||
fn select_nothing (&self) -> Selection {
|
|
||||||
Selection::Nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::command(Arrangement)]
|
|
||||||
impl ArrangementCommand {
|
|
||||||
/// Set the selection
|
|
||||||
fn select (arranger: &mut Arrangement, s: Selection) -> Perhaps<Self> {
|
|
||||||
*arranger.selection_mut() = s;
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
/// Launch a clip or scene
|
|
||||||
fn launch (arranger: &mut Arrangement) -> Perhaps<Self> {
|
|
||||||
match *arranger.selection() {
|
|
||||||
Selection::Track(t) => {
|
|
||||||
arranger.tracks[t].sequencer.enqueue_next(None)
|
|
||||||
},
|
|
||||||
Selection::TrackClip { track, scene } => {
|
|
||||||
arranger.tracks[track].sequencer.enqueue_next(arranger.scenes[scene].clips[track].as_ref())
|
|
||||||
},
|
|
||||||
Selection::Scene(s) => {
|
|
||||||
for t in 0..arranger.tracks.len() {
|
|
||||||
arranger.tracks[t].sequencer.enqueue_next(arranger.scenes[s].clips[t].as_ref())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
/// Set the color of the selected entity
|
|
||||||
fn set_color (arranger: &mut Arrangement, palette: Option<ItemTheme>) -> Perhaps<Self> {
|
|
||||||
let mut palette = palette.unwrap_or_else(||ItemTheme::random());
|
|
||||||
let selection = *arranger.selection();
|
|
||||||
Ok(Some(Self::SetColor { palette: Some(match selection {
|
|
||||||
Selection::Mix => {
|
|
||||||
std::mem::swap(&mut palette, &mut arranger.color);
|
|
||||||
palette
|
|
||||||
},
|
|
||||||
Selection::Scene(s) => {
|
|
||||||
std::mem::swap(&mut palette, &mut arranger.scenes[s].color);
|
|
||||||
palette
|
|
||||||
}
|
|
||||||
Selection::Track(t) => {
|
|
||||||
std::mem::swap(&mut palette, &mut arranger.tracks[t].color);
|
|
||||||
palette
|
|
||||||
}
|
|
||||||
Selection::TrackClip { track, scene } => {
|
|
||||||
if let Some(ref clip) = arranger.scenes[scene].clips[track] {
|
|
||||||
let mut clip = clip.write().unwrap();
|
|
||||||
std::mem::swap(&mut palette, &mut clip.color);
|
|
||||||
palette
|
|
||||||
} else {
|
|
||||||
return Ok(None)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => todo!()
|
|
||||||
}) }))
|
|
||||||
}
|
|
||||||
fn track (arranger: &mut Arrangement, track: TrackCommand) -> Perhaps<Self> {
|
|
||||||
todo!("delegate")
|
|
||||||
}
|
|
||||||
fn track_add (arranger: &mut Arrangement) -> Perhaps<Self> {
|
|
||||||
let index = arranger.track_add(None, None, &[], &[])?.0;
|
|
||||||
*arranger.selection_mut() = match arranger.selection() {
|
|
||||||
Selection::Track(_) => Selection::Track(index),
|
|
||||||
Selection::TrackClip { track, scene } => Selection::TrackClip {
|
|
||||||
track: index, scene: *scene
|
|
||||||
},
|
|
||||||
_ => *arranger.selection()
|
|
||||||
};
|
|
||||||
Ok(Some(Self::TrackDelete { index }))
|
|
||||||
}
|
|
||||||
fn track_swap (arranger: &mut Arrangement, index: usize, other: usize) -> Perhaps<Self> {
|
|
||||||
todo!();
|
|
||||||
Ok(Some(Self::TrackSwap { index, other }))
|
|
||||||
}
|
|
||||||
fn track_delete (arranger: &mut Arrangement, index: usize) -> Perhaps<Self> {
|
|
||||||
let exists = arranger.tracks().get(index).is_some();
|
|
||||||
if exists {
|
|
||||||
let track = arranger.tracks_mut().remove(index);
|
|
||||||
let Track { sequencer: Sequencer { midi_ins, midi_outs, .. }, .. } = track;
|
|
||||||
for port in midi_ins.into_iter() {
|
|
||||||
port.close()?;
|
|
||||||
}
|
|
||||||
for port in midi_outs.into_iter() {
|
|
||||||
port.close()?;
|
|
||||||
}
|
|
||||||
for scene in arranger.scenes_mut().iter_mut() {
|
|
||||||
scene.clips.remove(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
//TODO:Ok(Some(Self::TrackAdd ( index, track: Some(deleted_track) })
|
|
||||||
}
|
|
||||||
fn midi_in (arranger: &mut Arrangement, input: MidiInputCommand) -> Perhaps<Self> {
|
|
||||||
todo!("delegate");
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn midi_in_add (arranger: &mut Arrangement) -> Perhaps<Self> {
|
|
||||||
arranger.midi_in_add()?;
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn midi_out (arranger: &mut Arrangement, input: MidiOutputCommand) -> Perhaps<Self> {
|
|
||||||
todo!("delegate");
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn midi_out_add (arranger: &mut Arrangement) -> Perhaps<Self> {
|
|
||||||
arranger.midi_out_add()?;
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn device (arranger: &mut Arrangement, input: DeviceCommand) -> Perhaps<Self> {
|
|
||||||
todo!("delegate");
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn device_add (arranger: &mut Arrangement, i: usize) -> Perhaps<Self> {
|
|
||||||
todo!("delegate");
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn scene (arranger: &mut Arrangement, scene: SceneCommand) -> Perhaps<Self> {
|
|
||||||
todo!("delegate");
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn scene_add (arranger: &mut Arrangement) -> Perhaps<Self> {
|
|
||||||
let index = arranger.scene_add(None, None)?.0;
|
|
||||||
*arranger.selection_mut() = match arranger.selection() {
|
|
||||||
Selection::Scene(_) => Selection::Scene(index),
|
|
||||||
Selection::TrackClip { track, scene } => Selection::TrackClip {
|
|
||||||
track: *track,
|
|
||||||
scene: index
|
|
||||||
},
|
|
||||||
_ => *arranger.selection()
|
|
||||||
};
|
|
||||||
Ok(None) // TODO
|
|
||||||
}
|
|
||||||
fn scene_swap (arranger: &mut Arrangement, index: usize, other: usize) -> Perhaps<Self> {
|
|
||||||
todo!();
|
|
||||||
Ok(Some(Self::SceneSwap { index, other }))
|
|
||||||
}
|
|
||||||
fn scene_delete (arranger: &mut Arrangement, index: usize) -> Perhaps<Self> {
|
|
||||||
let scenes = arranger.scenes_mut();
|
|
||||||
Ok(if scenes.get(index).is_some() {
|
|
||||||
let _scene = scenes.remove(index);
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
})
|
|
||||||
}
|
|
||||||
fn scene_launch (arranger: &mut Arrangement, index: usize) -> Perhaps<Self> {
|
|
||||||
for track in 0..arranger.tracks.len() {
|
|
||||||
let clip = arranger.scenes[index].clips[track].as_ref();
|
|
||||||
arranger.tracks[track].sequencer.enqueue_next(clip);
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn clip (arranger: &mut Arrangement, scene: ClipCommand) -> Perhaps<Self> {
|
|
||||||
todo!("delegate")
|
|
||||||
}
|
|
||||||
fn clip_get (arranger: &mut Arrangement, a: usize, b: usize) -> Perhaps<Self> {
|
|
||||||
//(Get [a: usize, b: usize] cmd_todo!("\n\rtodo: clip: get: {a} {b}"))
|
|
||||||
//("get" [a: usize, b: usize] Some(Self::Get(a.unwrap(), b.unwrap())))
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn clip_put (arranger: &mut Arrangement, a: usize, b: usize) -> Perhaps<Self> {
|
|
||||||
//(Put [t: usize, s: usize, c: MaybeClip]
|
|
||||||
//Some(Self::Put(t, s, arranger.clip_put(t, s, c))))
|
|
||||||
//("put" [a: usize, b: usize, c: MaybeClip] Some(Self::Put(a.unwrap(), b.unwrap(), c.unwrap())))
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn clip_del (arranger: &mut Arrangement, a: usize, b: usize) -> Perhaps<Self> {
|
|
||||||
//("delete" [a: usize, b: usize] Some(Self::Put(a.unwrap(), b.unwrap(), None))))
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn clip_enqueue (arranger: &mut Arrangement, a: usize, b: usize) -> Perhaps<Self> {
|
|
||||||
//(Enqueue [t: usize, s: usize]
|
|
||||||
//cmd!(arranger.tracks[t].sequencer.enqueue_next(arranger.scenes[s].clips[t].as_ref())))
|
|
||||||
//("enqueue" [a: usize, b: usize] Some(Self::Enqueue(a.unwrap(), b.unwrap())))
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn clip_edit (arranger: &mut Arrangement, a: usize, b: usize) -> Perhaps<Self> {
|
|
||||||
//(Edit [clip: MaybeClip] cmd_todo!("\n\rtodo: clip: edit: {clip:?}"))
|
|
||||||
//("edit" [a: MaybeClip] Some(Self::Edit(a.unwrap())))
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'state> Context<'state, MidiInputCommand> for Arrangement {
|
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<MidiInputCommand> {
|
|
||||||
Context::get(&self, iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'state> Context<'state, MidiOutputCommand> for Arrangement {
|
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<MidiOutputCommand> {
|
|
||||||
Context::get(&self, iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'state> Context<'state, DeviceCommand> for Arrangement {
|
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<DeviceCommand> {
|
|
||||||
Context::get(&self, iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl<'state> Context<'state, ClipCommand> for Arrangement {
|
|
||||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<ClipCommand> {
|
|
||||||
Context::get(&self, iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::expose]
|
|
||||||
impl MidiClip {
|
|
||||||
fn _todo_opt_bool_stub_ (&self) -> Option<bool> { todo!() }
|
|
||||||
fn _todo_bool_stub_ (&self) -> bool { todo!() }
|
|
||||||
fn _todo_usize_stub_ (&self) -> usize { todo!() }
|
|
||||||
fn _todo_arc_str_stub_ (&self) -> Arc<str> { todo!() }
|
|
||||||
fn _todo_item_theme_stub (&self) -> ItemTheme { todo!() }
|
|
||||||
fn _todo_opt_item_theme_stub (&self) -> Option<ItemTheme> { todo!() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::command(MidiClip)]
|
|
||||||
impl ClipCommand {
|
|
||||||
fn set_color (clip: &mut MidiClip, color: Option<ItemTheme>) -> Perhaps<Self> {
|
|
||||||
//(SetColor [t: usize, s: usize, c: ItemTheme]
|
|
||||||
//clip.clip_set_color(t, s, c).map(|o|Self::SetColor(t, s, o)))));
|
|
||||||
//("color" [a: usize, b: usize] Some(Self::SetColor(a.unwrap(), b.unwrap(), ItemTheme::random())))
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn set_loop (clip: &mut MidiClip, looping: Option<bool>) -> Perhaps<Self> {
|
|
||||||
//(SetLoop [t: usize, s: usize, l: bool] cmd_todo!("\n\rtodo: {self:?}"))
|
|
||||||
//("loop" [a: usize, b: usize, c: bool] Some(Self::SetLoop(a.unwrap(), b.unwrap(), c.unwrap())))
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Arrangement {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,175 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
|
||||||
pub struct Arrangement {
|
|
||||||
/// Project name.
|
|
||||||
pub name: Arc<str>,
|
|
||||||
/// Base color.
|
|
||||||
pub color: ItemTheme,
|
|
||||||
/// Jack client handle
|
|
||||||
pub jack: Jack,
|
|
||||||
/// Source of time
|
|
||||||
pub clock: Clock,
|
|
||||||
/// List of global midi inputs
|
|
||||||
pub midi_ins: Vec<JackMidiIn>,
|
|
||||||
/// List of global midi outputs
|
|
||||||
pub midi_outs: Vec<JackMidiOut>,
|
|
||||||
/// List of global audio inputs
|
|
||||||
pub audio_ins: Vec<JackAudioIn>,
|
|
||||||
/// List of global audio outputs
|
|
||||||
pub audio_outs: Vec<JackAudioOut>,
|
|
||||||
/// Last track number (to avoid duplicate port names)
|
|
||||||
pub track_last: usize,
|
|
||||||
/// List of tracks
|
|
||||||
pub tracks: Vec<Track>,
|
|
||||||
/// Scroll offset of tracks
|
|
||||||
pub track_scroll: usize,
|
|
||||||
/// List of scenes
|
|
||||||
pub scenes: Vec<Scene>,
|
|
||||||
/// Scroll offset of scenes
|
|
||||||
pub scene_scroll: usize,
|
|
||||||
/// Selected UI element
|
|
||||||
pub selection: Selection,
|
|
||||||
/// Contains a render of the project arrangement, redrawn on update.
|
|
||||||
/// TODO rename to "render_cache" or smth
|
|
||||||
pub arranger: Arc<RwLock<Buffer>>,
|
|
||||||
/// Display size
|
|
||||||
pub size: Measure<TuiOut>,
|
|
||||||
/// Contains all clips in arrangement
|
|
||||||
pub pool: Pool,
|
|
||||||
}
|
|
||||||
|
|
||||||
has!(Jack: |self: Arrangement|self.jack);
|
|
||||||
has!(Clock: |self: Arrangement|self.clock);
|
|
||||||
has!(Selection: |self: Arrangement|self.selection);
|
|
||||||
has!(Vec<JackMidiIn>: |self: Arrangement|self.midi_ins);
|
|
||||||
has!(Vec<JackMidiOut>: |self: Arrangement|self.midi_outs);
|
|
||||||
has!(Vec<Scene>: |self: Arrangement|self.scenes);
|
|
||||||
has!(Vec<Track>: |self: Arrangement|self.tracks);
|
|
||||||
has!(Measure<TuiOut>: |self: Arrangement|self.size);
|
|
||||||
|
|
||||||
impl Arrangement {
|
|
||||||
/// Width of display
|
|
||||||
pub fn w (&self) -> u16 {
|
|
||||||
self.size.w() as u16
|
|
||||||
}
|
|
||||||
/// Width allocated for sidebar.
|
|
||||||
pub fn w_sidebar (&self, is_editing: bool) -> u16 {
|
|
||||||
self.w() / if is_editing { 16 } else { 8 } as u16
|
|
||||||
}
|
|
||||||
/// Width taken by all tracks.
|
|
||||||
pub fn w_tracks (&self) -> u16 {
|
|
||||||
self.tracks_with_sizes(&self.selection(), None).last()
|
|
||||||
.map(|(_, _, _, x)|x as u16).unwrap_or(0)
|
|
||||||
}
|
|
||||||
/// Width available to display tracks.
|
|
||||||
pub fn w_tracks_area (&self, is_editing: bool) -> u16 {
|
|
||||||
self.w().saturating_sub(2 * self.w_sidebar(is_editing))
|
|
||||||
}
|
|
||||||
/// Height of display
|
|
||||||
pub fn h (&self) -> u16 {
|
|
||||||
self.size.h() as u16
|
|
||||||
}
|
|
||||||
/// Height available to display track headers.
|
|
||||||
pub fn h_tracks_area (&self) -> u16 {
|
|
||||||
5 // FIXME
|
|
||||||
//self.h().saturating_sub(self.h_inputs() + self.h_outputs())
|
|
||||||
}
|
|
||||||
/// Height available to display tracks.
|
|
||||||
pub fn h_scenes_area (&self) -> u16 {
|
|
||||||
//15
|
|
||||||
self.h().saturating_sub(
|
|
||||||
self.h_inputs() +
|
|
||||||
self.h_outputs() +
|
|
||||||
self.h_devices() +
|
|
||||||
13 // FIXME
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/// Height taken by all scenes.
|
|
||||||
pub fn h_scenes (&self, is_editing: bool) -> u16 {
|
|
||||||
self.scenes_with_sizes(
|
|
||||||
is_editing,
|
|
||||||
ArrangerView::H_SCENE,
|
|
||||||
ArrangerView::H_EDITOR,
|
|
||||||
self.selection().track(),
|
|
||||||
self.selection().scene(),
|
|
||||||
)
|
|
||||||
.last()
|
|
||||||
.map(|(_, _, _, y)|y as u16).unwrap_or(0)
|
|
||||||
}
|
|
||||||
/// Height taken by all inputs.
|
|
||||||
pub fn h_inputs (&self) -> u16 {
|
|
||||||
self.midi_ins_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
|
||||||
}
|
|
||||||
/// Height taken by all outputs.
|
|
||||||
pub fn h_outputs (&self) -> u16 {
|
|
||||||
self.midi_outs_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
|
||||||
}
|
|
||||||
/// Height taken by visible device slots.
|
|
||||||
pub fn h_devices (&self) -> u16 {
|
|
||||||
2
|
|
||||||
//1 + self.devices_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
|
||||||
}
|
|
||||||
/// Get the active track
|
|
||||||
fn get_track (&self) -> Option<&Track> {
|
|
||||||
let index = self.selection().track()?;
|
|
||||||
Has::<Vec<Track>>::get(self).get(index)
|
|
||||||
}
|
|
||||||
/// Get a mutable reference to the active track
|
|
||||||
fn get_track_mut (&mut self) -> Option<&mut Track> {
|
|
||||||
let index = self.selection().track()?;
|
|
||||||
Has::<Vec<Track>>::get_mut(self).get_mut(index)
|
|
||||||
}
|
|
||||||
/// Get the active scene
|
|
||||||
fn get_scene (&self) -> Option<&Scene> {
|
|
||||||
let index = self.selection().scene()?;
|
|
||||||
Has::<Vec<Scene>>::get(self).get(index)
|
|
||||||
}
|
|
||||||
/// Get a mutable reference to the active scene
|
|
||||||
fn get_scene_mut (&mut self) -> Option<&mut Scene> {
|
|
||||||
let index = self.selection().scene()?;
|
|
||||||
Has::<Vec<Scene>>::get_mut(self).get_mut(index)
|
|
||||||
}
|
|
||||||
/// Get the active clip
|
|
||||||
fn get_clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
|
||||||
self.get_scene()?.clips.get(self.selection().track()?)?.clone()
|
|
||||||
}
|
|
||||||
/// Put a clip in a slot
|
|
||||||
pub fn clip_put (
|
|
||||||
&mut self, track: usize, scene: usize, clip: Option<Arc<RwLock<MidiClip>>>
|
|
||||||
) -> Option<Arc<RwLock<MidiClip>>> {
|
|
||||||
let old = self.scenes[scene].clips[track].clone();
|
|
||||||
self.scenes[scene].clips[track] = clip;
|
|
||||||
old
|
|
||||||
}
|
|
||||||
/// Change the color of a clip, returning the previous one
|
|
||||||
pub fn clip_set_color (&self, track: usize, scene: usize, color: ItemTheme)
|
|
||||||
-> Option<ItemTheme>
|
|
||||||
{
|
|
||||||
self.scenes[scene].clips[track].as_ref().map(|clip|{
|
|
||||||
let mut clip = clip.write().unwrap();
|
|
||||||
let old = clip.color.clone();
|
|
||||||
clip.color = color.clone();
|
|
||||||
panic!("{color:?} {old:?}");
|
|
||||||
old
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/// Toggle looping for the active clip
|
|
||||||
pub fn toggle_loop (&mut self) {
|
|
||||||
if let Some(clip) = self.get_clip() {
|
|
||||||
clip.write().unwrap().toggle_loop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "sampler")]
|
|
||||||
impl Arrangement {
|
|
||||||
/// Get the first sampler of the active track
|
|
||||||
pub fn sampler (&self) -> Option<&Sampler> {
|
|
||||||
self.get_track()?.sampler(0)
|
|
||||||
}
|
|
||||||
/// Get the first sampler of the active track
|
|
||||||
pub fn sampler_mut (&mut self) -> Option<&mut Sampler> {
|
|
||||||
self.get_track_mut()?.sampler_mut(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,143 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl<'a> ArrangerView<'a> {
|
|
||||||
|
|
||||||
pub(crate) fn input_routes (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
Tryptich::top(self.inputs_height)
|
|
||||||
.left(self.width_side,
|
|
||||||
io_ports(Tui::g(224), Tui::g(32), ||self.arrangement.midi_ins_with_sizes()))
|
|
||||||
.middle(self.width_mid,
|
|
||||||
per_track_top(self.width_mid, ||self.tracks_with_sizes_scrolled(),
|
|
||||||
move|_, &Track { color, .. }|io_conns(
|
|
||||||
color.dark.rgb,
|
|
||||||
color.darker.rgb,
|
|
||||||
||self.arrangement.midi_ins_with_sizes()
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn input_ports (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
Tryptich::top(1)
|
|
||||||
.left(self.width_side,
|
|
||||||
button_3("i", "midi ins", format!("{}", self.arrangement.midi_ins().len()), self.is_editing))
|
|
||||||
.right(self.width_side,
|
|
||||||
button_2("I", "add midi in", self.is_editing))
|
|
||||||
.middle(self.width_mid,
|
|
||||||
per_track_top(
|
|
||||||
self.width_mid,
|
|
||||||
||self.tracks_with_sizes_scrolled(),
|
|
||||||
move|t, track|{
|
|
||||||
let rec = track.sequencer.recording;
|
|
||||||
let mon = track.sequencer.monitoring;
|
|
||||||
let rec = if rec { White } else { track.color.darkest.rgb };
|
|
||||||
let mon = if mon { White } else { track.color.darkest.rgb };
|
|
||||||
let bg = if self.track_selected == Some(t) {
|
|
||||||
track.color.light.rgb
|
|
||||||
} else {
|
|
||||||
track.color.base.rgb
|
|
||||||
};
|
|
||||||
//let bg2 = if t > 0 { track.color.base.rgb } else { Reset };
|
|
||||||
wrap(bg, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(
|
|
||||||
Tui::fg_bg(rec, bg, "Rec "),
|
|
||||||
Tui::fg_bg(mon, bg, "Mon "),
|
|
||||||
))))
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn input_intos (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
Tryptich::top(2)
|
|
||||||
.left(self.width_side,
|
|
||||||
Bsp::s(Align::e("Input:"), Align::e("Into clip:")))
|
|
||||||
.middle(self.width_mid,
|
|
||||||
per_track_top(
|
|
||||||
self.width_mid,
|
|
||||||
||self.tracks_with_sizes_scrolled(),
|
|
||||||
|_, _|Tui::bg(Reset, Align::c(Bsp::s(OctaveVertical::default(), " ------ ")))))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ArrangerView<'a> {
|
|
||||||
|
|
||||||
pub(crate) fn output_nexts (&self) -> impl Content<TuiOut> + '_ {
|
|
||||||
Tryptich::top(2)
|
|
||||||
.left(self.width_side, Align::ne("From clip:"))
|
|
||||||
.middle(self.width_mid, per_track_top(
|
|
||||||
self.width_mid,
|
|
||||||
||self.tracks_with_sizes_scrolled(),
|
|
||||||
|_, _|Tui::bg(Reset, Align::c(Bsp::s(" ------ ", OctaveVertical::default())))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn output_froms (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
let label = Align::ne("Next clip:");
|
|
||||||
Tryptich::top(2).left(self.width_side, label).middle(self.width_mid, per_track_top(
|
|
||||||
self.width_mid, ||self.tracks_with_sizes_scrolled(), |t, track|{
|
|
||||||
let queued = track.sequencer.next_clip.is_some();
|
|
||||||
let queued_blank = Thunk::new(||Tui::bg(Reset, " ------ "));
|
|
||||||
let queued_clip = Thunk::new(||{
|
|
||||||
Tui::bg(Reset, if let Some((_, clip)) = track.sequencer.next_clip.as_ref() {
|
|
||||||
if let Some(clip) = clip {
|
|
||||||
clip.read().unwrap().name.clone()
|
|
||||||
} else {
|
|
||||||
"Stop".into()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
"".into()
|
|
||||||
})
|
|
||||||
});
|
|
||||||
Either(queued, queued_clip, queued_blank)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn output_ports (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
Tryptich::top(1)
|
|
||||||
.left(self.width_side, self.output_count())
|
|
||||||
.right(self.width_side, self.output_add())
|
|
||||||
.middle(self.width_mid, self.output_map())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn output_count (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
button_3(
|
|
||||||
"o",
|
|
||||||
"midi outs",
|
|
||||||
format!("{}", self.arrangement.midi_outs().len()),
|
|
||||||
self.is_editing
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn output_add (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
button_2("O", "add midi out", self.is_editing)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn output_map (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
per_track_top(self.width_mid, ||self.tracks_with_sizes_scrolled(), move|i, t|{
|
|
||||||
let mute = false;
|
|
||||||
let solo = false;
|
|
||||||
let mute = if mute { White } else { t.color.darkest.rgb };
|
|
||||||
let solo = if solo { White } else { t.color.darkest.rgb };
|
|
||||||
let bg_1 = if self.track_selected == Some(i) {
|
|
||||||
t.color.light.rgb
|
|
||||||
} else {
|
|
||||||
t.color.base.rgb
|
|
||||||
};
|
|
||||||
let bg_2 = if i > 0 { t.color.base.rgb } else { Reset };
|
|
||||||
let mute = Tui::fg_bg(mute, bg_1, "Play ");
|
|
||||||
let solo = Tui::fg_bg(solo, bg_1, "Solo ");
|
|
||||||
wrap(bg_1, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(mute, solo))))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn output_conns (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
Tryptich::top(self.outputs_height)
|
|
||||||
.left(self.width_side, io_ports(
|
|
||||||
Tui::g(224), Tui::g(32), ||self.arrangement.midi_outs_with_sizes()))
|
|
||||||
.middle(self.width_mid, per_track_top(
|
|
||||||
self.width_mid,
|
|
||||||
||self.tracks_with_sizes_scrolled(),
|
|
||||||
|_, t|io_conns(
|
|
||||||
t.color.dark.rgb,
|
|
||||||
t.color.darker.rgb,
|
|
||||||
||self.arrangement.midi_outs_with_sizes()
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl<T: Has<Vec<Scene>> + Send + Sync> HasScenes for T {}
|
|
||||||
|
|
||||||
pub trait HasScenes: Has<Vec<Scene>> + Send + Sync {
|
|
||||||
fn scenes (&self) -> &Vec<Scene> {
|
|
||||||
Has::<Vec<Scene>>::get(self)
|
|
||||||
}
|
|
||||||
fn scenes_mut (&mut self) -> &mut Vec<Scene> {
|
|
||||||
Has::<Vec<Scene>>::get_mut(self)
|
|
||||||
}
|
|
||||||
fn scenes_with_sizes (
|
|
||||||
&self,
|
|
||||||
editing: bool,
|
|
||||||
height: usize,
|
|
||||||
larger: usize,
|
|
||||||
selected_track: Option<usize>,
|
|
||||||
selected_scene: Option<usize>,
|
|
||||||
) -> impl ScenesSizes<'_> {
|
|
||||||
let mut y = 0;
|
|
||||||
self.scenes().iter().enumerate().map(move|(s, scene)|{
|
|
||||||
let active = editing && selected_track.is_some() && selected_scene == Some(s);
|
|
||||||
let height = if active { larger } else { height };
|
|
||||||
let data = (s, scene, y, y + height);
|
|
||||||
y += height;
|
|
||||||
data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/// Generate the default name for a new scene
|
|
||||||
fn scene_default_name (&self) -> Arc<str> {
|
|
||||||
format!("Sc{:3>}", self.scenes().len() + 1).into()
|
|
||||||
}
|
|
||||||
fn scene_longest_name (&self) -> usize {
|
|
||||||
self.scenes().iter().map(|s|s.name.len()).fold(0, usize::max)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: HasScenes + HasTracks> AddScene for T {}
|
|
||||||
|
|
||||||
pub trait AddScene: HasScenes + HasTracks {
|
|
||||||
/// Add multiple scenes
|
|
||||||
fn scenes_add (&mut self, n: usize) -> Usually<()> {
|
|
||||||
let scene_color_1 = ItemColor::random();
|
|
||||||
let scene_color_2 = ItemColor::random();
|
|
||||||
for i in 0..n {
|
|
||||||
let _ = self.scene_add(None, Some(
|
|
||||||
scene_color_1.mix(scene_color_2, i as f32 / n as f32).into()
|
|
||||||
))?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
/// Add a scene
|
|
||||||
fn scene_add (&mut self, name: Option<&str>, color: Option<ItemTheme>)
|
|
||||||
-> Usually<(usize, &mut Scene)>
|
|
||||||
{
|
|
||||||
let scene = Scene {
|
|
||||||
name: name.map_or_else(||self.scene_default_name(), |x|x.to_string().into()),
|
|
||||||
clips: vec![None;self.tracks().len()],
|
|
||||||
color: color.unwrap_or_else(ItemTheme::random),
|
|
||||||
};
|
|
||||||
self.scenes_mut().push(scene);
|
|
||||||
let index = self.scenes().len() - 1;
|
|
||||||
Ok((index, &mut self.scenes_mut()[index]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,146 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl<T: Has<Vec<Track>> + Send + Sync> HasTracks for T {}
|
|
||||||
|
|
||||||
pub trait HasTracks: Has<Vec<Track>> + Send + Sync {
|
|
||||||
fn tracks (&self) -> &Vec<Track> {
|
|
||||||
Has::<Vec<Track>>::get(self)
|
|
||||||
}
|
|
||||||
fn tracks_mut (&mut self) -> &mut Vec<Track> {
|
|
||||||
Has::<Vec<Track>>::get_mut(self)
|
|
||||||
}
|
|
||||||
/// Run audio callbacks for every track and every device
|
|
||||||
fn process_tracks (&mut self, client: &Client, scope: &ProcessScope) -> Control {
|
|
||||||
for track in self.tracks_mut().iter_mut() {
|
|
||||||
if Control::Quit == Audio::process(&mut track.sequencer, client, scope) {
|
|
||||||
return Control::Quit
|
|
||||||
}
|
|
||||||
for device in track.devices.iter_mut() {
|
|
||||||
if Control::Quit == DeviceAudio(device).process(client, scope) {
|
|
||||||
return Control::Quit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Control::Continue
|
|
||||||
}
|
|
||||||
fn track_longest_name (&self) -> usize {
|
|
||||||
self.tracks().iter().map(|s|s.name.len()).fold(0, usize::max)
|
|
||||||
}
|
|
||||||
/// Stop all playing clips
|
|
||||||
fn tracks_stop_all (&mut self) {
|
|
||||||
for track in self.tracks_mut().iter_mut() {
|
|
||||||
track.sequencer.enqueue_next(None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Stop all playing clips
|
|
||||||
fn tracks_launch (&mut self, clips: Option<Vec<Option<Arc<RwLock<MidiClip>>>>>) {
|
|
||||||
if let Some(clips) = clips {
|
|
||||||
for (clip, track) in clips.iter().zip(self.tracks_mut()) {
|
|
||||||
track.sequencer.enqueue_next(clip.as_ref());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for track in self.tracks_mut().iter_mut() {
|
|
||||||
track.sequencer.enqueue_next(None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Iterate over tracks with their corresponding sizes.
|
|
||||||
fn tracks_with_sizes (
|
|
||||||
&self,
|
|
||||||
selection: &Selection,
|
|
||||||
editor_width: Option<usize>
|
|
||||||
) -> impl TracksSizes<'_> {
|
|
||||||
let mut x = 0;
|
|
||||||
let active_track = if let Some(width) = editor_width {
|
|
||||||
selection.track()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
self.tracks().iter().enumerate().map(move |(index, track)|{
|
|
||||||
let width = active_track
|
|
||||||
.and_then(|_|editor_width)
|
|
||||||
.unwrap_or(track.width.max(8));
|
|
||||||
let data = (index, track, x, x + width);
|
|
||||||
x += width + Self::TRACK_SPACING;
|
|
||||||
data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/// Spacing between tracks.
|
|
||||||
const TRACK_SPACING: usize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ArrangerView<'a> {
|
|
||||||
pub(crate) fn tracks_with_sizes_scrolled (&'a self)
|
|
||||||
-> impl TracksSizes<'a>
|
|
||||||
{
|
|
||||||
self.arrangement
|
|
||||||
.tracks_with_sizes(
|
|
||||||
&self.arrangement.selection(),
|
|
||||||
self.is_editing.then_some(20/*FIXME*/)
|
|
||||||
)
|
|
||||||
.map_while(move|(t, track, x1, x2)|{
|
|
||||||
(self.width_mid > x2 as u16).then_some((t, track, x1, x2))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Arrangement {
|
|
||||||
/// Add multiple tracks
|
|
||||||
pub fn tracks_add (
|
|
||||||
&mut self,
|
|
||||||
count: usize,
|
|
||||||
width: Option<usize>,
|
|
||||||
mins: &[PortConnect],
|
|
||||||
mouts: &[PortConnect],
|
|
||||||
) -> Usually<()> {
|
|
||||||
let jack = self.jack().clone();
|
|
||||||
let track_color_1 = ItemColor::random();
|
|
||||||
let track_color_2 = ItemColor::random();
|
|
||||||
for i in 0..count {
|
|
||||||
let color = track_color_1.mix(track_color_2, i as f32 / count as f32).into();
|
|
||||||
let mut track = self.track_add(None, Some(color), mins, mouts)?.1;
|
|
||||||
if let Some(width) = width {
|
|
||||||
track.width = width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a track
|
|
||||||
pub fn track_add (
|
|
||||||
&mut self,
|
|
||||||
name: Option<&str>,
|
|
||||||
color: Option<ItemTheme>,
|
|
||||||
mins: &[PortConnect],
|
|
||||||
mouts: &[PortConnect],
|
|
||||||
) -> Usually<(usize, &mut Track)> {
|
|
||||||
self.track_last += 1;
|
|
||||||
let name: Arc<str> = name.map_or_else(
|
|
||||||
||format!("Track{:02}", self.track_last).into(),
|
|
||||||
|x|x.to_string().into()
|
|
||||||
);
|
|
||||||
let mut track = Track {
|
|
||||||
width: (name.len() + 2).max(12),
|
|
||||||
color: color.unwrap_or_else(ItemTheme::random),
|
|
||||||
sequencer: Sequencer::new(
|
|
||||||
&format!("{name}"),
|
|
||||||
self.jack(),
|
|
||||||
Some(self.clock()),
|
|
||||||
None,
|
|
||||||
mins,
|
|
||||||
mouts
|
|
||||||
)?,
|
|
||||||
name,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
self.tracks_mut().push(track);
|
|
||||||
let len = self.tracks().len();
|
|
||||||
let index = len - 1;
|
|
||||||
for scene in self.scenes_mut().iter_mut() {
|
|
||||||
while scene.clips.len() < len {
|
|
||||||
scene.clips.push(None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok((index, &mut self.tracks_mut()[index]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,289 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
pub struct ArrangerView<'a> {
|
|
||||||
pub arrangement: &'a Arrangement,
|
|
||||||
|
|
||||||
pub is_editing: bool,
|
|
||||||
|
|
||||||
pub width: u16,
|
|
||||||
pub width_mid: u16,
|
|
||||||
pub width_side: u16,
|
|
||||||
|
|
||||||
pub inputs_height: u16,
|
|
||||||
pub outputs_height: u16,
|
|
||||||
|
|
||||||
pub scene_last: usize,
|
|
||||||
pub scene_scroll: Fill<Fixed<u16, ScrollbarV>>,
|
|
||||||
pub scene_selected: Option<usize>,
|
|
||||||
pub scenes_height: u16,
|
|
||||||
|
|
||||||
pub track_scroll: Fill<Fixed<u16, ScrollbarH>>,
|
|
||||||
pub track_selected: Option<usize>,
|
|
||||||
pub tracks_height: u16,
|
|
||||||
|
|
||||||
pub show_debug_info: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ArrangerView<'a> {
|
|
||||||
pub fn new (
|
|
||||||
arrangement: &'a Arrangement,
|
|
||||||
editor: Option<&'a MidiEditor>
|
|
||||||
) -> Self {
|
|
||||||
let is_editing = editor.is_some();
|
|
||||||
let h_tracks_area = arrangement.h_tracks_area();
|
|
||||||
let h_scenes_area = arrangement.h_scenes_area();
|
|
||||||
let h_scenes = arrangement.h_scenes(is_editing);
|
|
||||||
Self {
|
|
||||||
arrangement,
|
|
||||||
is_editing,
|
|
||||||
|
|
||||||
width: arrangement.w(),
|
|
||||||
width_mid: arrangement.w_tracks_area(is_editing),
|
|
||||||
width_side: arrangement.w_sidebar(is_editing),
|
|
||||||
|
|
||||||
inputs_height: arrangement.h_inputs(),
|
|
||||||
outputs_height: arrangement.h_outputs(),
|
|
||||||
|
|
||||||
scenes_height: h_scenes_area,
|
|
||||||
scene_selected: arrangement.selection().scene(),
|
|
||||||
scene_last: arrangement.scenes.len().saturating_sub(1),
|
|
||||||
scene_scroll: Fill::y(Fixed::x(1, ScrollbarV {
|
|
||||||
offset: arrangement.scene_scroll,
|
|
||||||
length: h_scenes_area as usize,
|
|
||||||
total: h_scenes as usize,
|
|
||||||
})),
|
|
||||||
|
|
||||||
tracks_height: h_tracks_area,
|
|
||||||
track_selected: arrangement.selection().track(),
|
|
||||||
track_scroll: Fill::x(Fixed::y(1, ScrollbarH {
|
|
||||||
offset: arrangement.track_scroll,
|
|
||||||
length: h_tracks_area as usize,
|
|
||||||
total: h_scenes as usize,
|
|
||||||
})),
|
|
||||||
|
|
||||||
show_debug_info: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Content<TuiOut> for ArrangerView<'a> {
|
|
||||||
fn content (&self) -> impl Render<TuiOut> {
|
|
||||||
let ins = |x|Bsp::n(self.inputs(), x);
|
|
||||||
let tracks = |x|Bsp::s(self.tracks(), x);
|
|
||||||
let devices = |x|Bsp::s(self.devices(), x);
|
|
||||||
let outs = |x|Bsp::s(self.outputs(), x);
|
|
||||||
let bg = |x|Tui::bg(Reset, x);
|
|
||||||
//let track_scroll = |x|Bsp::s(&self.track_scroll, x);
|
|
||||||
//let scene_scroll = |x|Bsp::e(&self.scene_scroll, x);
|
|
||||||
outs(tracks(devices(ins(bg(self.scenes(&None))))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ArrangerView<'a> {
|
|
||||||
/// Render input matrix.
|
|
||||||
pub(crate) fn inputs (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
Tui::bg(Reset, Bsp::s(
|
|
||||||
self.input_intos(),
|
|
||||||
Bsp::s(self.input_routes(), self.input_ports()),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Render output matrix.
|
|
||||||
pub(crate) fn outputs (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
Tui::bg(Reset, Align::n(Bsp::s(
|
|
||||||
Bsp::s(self.output_ports(), self.output_conns()),
|
|
||||||
Bsp::s(self.output_nexts(), self.output_froms()),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Render track headers
|
|
||||||
pub(crate) fn tracks (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
let Self { width_side, width_mid, track_selected, is_editing, .. } = self;
|
|
||||||
Tryptich::center(3)
|
|
||||||
.left(*width_side, button_3("t", "track", format!("{}", self.arrangement.tracks.len()), *is_editing))
|
|
||||||
.right(*width_side, button_2("T", "add track", *is_editing))
|
|
||||||
.middle(*width_mid, per_track(*width_mid, ||self.tracks_with_sizes_scrolled(),
|
|
||||||
|index, track|wrap(
|
|
||||||
if *track_selected == Some(index) {
|
|
||||||
track.color.light
|
|
||||||
} else {
|
|
||||||
track.color.base
|
|
||||||
}.rgb,
|
|
||||||
track.color.lightest.rgb,
|
|
||||||
Tui::bold(true, Fill::xy(Align::nw(&track.name)))
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Render device switches.
|
|
||||||
pub(crate) fn devices (&'a self) -> impl Content<TuiOut> + 'a {
|
|
||||||
let Self { width_side, width_mid, track_selected, is_editing, .. } = self;
|
|
||||||
Tryptich::top(1)
|
|
||||||
.left(*width_side, button_3("d", "devices", format!("{}", 0), *is_editing))
|
|
||||||
.right(*width_side, button_2("D", "add device", *is_editing))
|
|
||||||
.middle(*width_mid, per_track_top(*width_mid, ||self.tracks_with_sizes_scrolled(),
|
|
||||||
move|index, track|{
|
|
||||||
let bg = if *track_selected == Some(index) {
|
|
||||||
track.color.light
|
|
||||||
} else {
|
|
||||||
track.color.base
|
|
||||||
};
|
|
||||||
let fg = Tui::g(224);
|
|
||||||
track.devices.get(0).map(|device|wrap(bg.rgb, fg, device.name()))
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Default scene height.
|
|
||||||
pub(crate) const H_SCENE: usize = 2;
|
|
||||||
|
|
||||||
/// Default editor height.
|
|
||||||
pub(crate) const H_EDITOR: usize = 15;
|
|
||||||
|
|
||||||
/// Render scenes with clips
|
|
||||||
pub(crate) fn scenes (&'a self, editor: &'a Option<MidiEditor>) -> impl Content<TuiOut> + 'a {
|
|
||||||
/// A scene with size and color.
|
|
||||||
type SceneWithColor<'a> = (usize, &'a Scene, usize, usize, Option<ItemTheme>);
|
|
||||||
let Self {
|
|
||||||
arrangement,
|
|
||||||
width, width_side, width_mid,
|
|
||||||
scenes_height, scene_last, scene_selected,
|
|
||||||
track_selected, is_editing, ..
|
|
||||||
} = self;
|
|
||||||
|
|
||||||
let selection = Has::<Selection>::get(self.arrangement);
|
|
||||||
let selected_track = selection.track();
|
|
||||||
let selected_scene = selection.scene();
|
|
||||||
Tryptich::center(*scenes_height)
|
|
||||||
|
|
||||||
.left(*width_side, Map::new(
|
|
||||||
move||arrangement.scenes_with_sizes(
|
|
||||||
*is_editing, Self::H_SCENE, Self::H_EDITOR, selected_track, selected_scene,
|
|
||||||
).map_while(|(s, scene, y1, y2)|if y2 as u16 > *scenes_height {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some((s, scene, y1, y2, if s == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(arrangement.scenes()[s-1].color)
|
|
||||||
}))
|
|
||||||
}),
|
|
||||||
move |(s, scene, y1, y2, previous): SceneWithColor, _|{
|
|
||||||
let height = (1 + y2 - y1) as u16;
|
|
||||||
let name = Some(scene.name.clone());
|
|
||||||
let content = Fill::x(Align::w(Tui::bold(true, Bsp::e(" ⯈ ", name))));
|
|
||||||
let same_track = true;
|
|
||||||
let selected = same_track && *scene_selected == Some(s);
|
|
||||||
let neighbor = same_track && s > 0 && *scene_selected == Some(s - 1);
|
|
||||||
let is_last = *scene_last == s;
|
|
||||||
let theme = scene.color;
|
|
||||||
let fg = theme.lightest.rgb;
|
|
||||||
let bg = if selected { theme.light } else { theme.base }.rgb;
|
|
||||||
let hi = if let Some(previous) = previous {
|
|
||||||
if neighbor {
|
|
||||||
previous.light.rgb
|
|
||||||
} else {
|
|
||||||
previous.base.rgb
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Reset
|
|
||||||
};
|
|
||||||
let lo = if is_last {
|
|
||||||
Reset
|
|
||||||
} else if selected {
|
|
||||||
theme.light.rgb
|
|
||||||
} else {
|
|
||||||
theme.base.rgb
|
|
||||||
};
|
|
||||||
Fill::x(map_south(y1 as u16, height, Fixed::y(height, Phat {
|
|
||||||
width: 0, height: 0, content, colors: [fg, bg, hi, lo]
|
|
||||||
})))
|
|
||||||
}))
|
|
||||||
|
|
||||||
.middle(*width_mid, per_track(
|
|
||||||
*width_mid,
|
|
||||||
||self.tracks_with_sizes_scrolled(),
|
|
||||||
move|track_index, track|Map::new(
|
|
||||||
move||arrangement.scenes_with_sizes(
|
|
||||||
self.is_editing,
|
|
||||||
Self::H_SCENE,
|
|
||||||
Self::H_EDITOR,
|
|
||||||
selected_track,
|
|
||||||
selected_scene,
|
|
||||||
).map_while(move|(s, scene, y1, y2)|if y2 as u16 > self.scenes_height {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some((s, scene, y1, y2, if s == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(self.arrangement.scenes[s-1].clips[track_index].as_ref()
|
|
||||||
.map(|c|c.read().unwrap().color)
|
|
||||||
.unwrap_or(ItemTheme::G[32]))
|
|
||||||
}))
|
|
||||||
}),
|
|
||||||
move|(s, scene, y1, y2, previous): SceneWithColor<'a>, _|{
|
|
||||||
let (name, theme) = if let Some(clip) = &scene.clips[track_index] {
|
|
||||||
let clip = clip.read().unwrap();
|
|
||||||
(Some(clip.name.clone()), clip.color)
|
|
||||||
} else {
|
|
||||||
(None, ItemTheme::G[32])
|
|
||||||
};
|
|
||||||
let height = (1 + y2 - y1) as u16;
|
|
||||||
let content = Fill::x(Align::w(Tui::bold(true, Bsp::e(" ⏹ ", name))));
|
|
||||||
let same_track = *track_selected == Some(track_index);
|
|
||||||
let selected = same_track && *scene_selected == Some(s);
|
|
||||||
let neighbor = same_track && s > 0 && *scene_selected == Some(s - 1);
|
|
||||||
let is_last = *scene_last == s;
|
|
||||||
let fg = theme.lightest.rgb;
|
|
||||||
let bg = if selected { theme.light } else { theme.base }.rgb;
|
|
||||||
let hi = if let Some(previous) = previous {
|
|
||||||
if neighbor {
|
|
||||||
previous.light.rgb
|
|
||||||
} else {
|
|
||||||
previous.base.rgb
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Reset
|
|
||||||
};
|
|
||||||
let lo = if is_last {
|
|
||||||
Reset
|
|
||||||
} else if selected {
|
|
||||||
theme.light.rgb
|
|
||||||
} else {
|
|
||||||
theme.base.rgb
|
|
||||||
};
|
|
||||||
map_south(y1 as u16, height, Bsp::b(Fixed::y(height, Phat {
|
|
||||||
width: 0, height: 0, content, colors: [fg, bg, hi, lo]
|
|
||||||
}), When(
|
|
||||||
*is_editing && same_track && *scene_selected == Some(s),
|
|
||||||
editor
|
|
||||||
)))
|
|
||||||
})))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
|
|
||||||
width: u16,
|
|
||||||
tracks: impl Fn() -> U + Send + Sync + 'a,
|
|
||||||
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
Align::x(Tui::bg(Reset, Map::new(tracks,
|
|
||||||
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{
|
|
||||||
let width = (x2 - x1) as u16;
|
|
||||||
map_east(x1 as u16, width, Fixed::x(width, Tui::fg_bg(
|
|
||||||
track.color.lightest.rgb,
|
|
||||||
track.color.base.rgb,
|
|
||||||
callback(index, track))))})))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn per_track <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
|
|
||||||
width: u16,
|
|
||||||
tracks: impl Fn() -> U + Send + Sync + 'a,
|
|
||||||
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
per_track_top(
|
|
||||||
width,
|
|
||||||
tracks,
|
|
||||||
move|index, track|Fill::y(Align::y(callback(index, track)))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -2,31 +2,19 @@ use crate::*;
|
||||||
|
|
||||||
#[tengri_proc::expose]
|
#[tengri_proc::expose]
|
||||||
impl Browser {
|
impl Browser {
|
||||||
fn _todo_stub_path_buf (&self) -> PathBuf {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn _todo_stub_usize (&self) -> usize {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn _todo_stub_arc_str (&self) -> Arc<str> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tengri_proc::command(Browser)]
|
#[tengri_proc::command(Browser)]
|
||||||
impl BrowserCommand {
|
impl BrowserCommand {
|
||||||
fn set_visible (browser: &mut Browser) -> Perhaps<Self> {
|
//fn set_address (browser: &mut Browser, address: PathBuf) -> Perhaps<Self> {
|
||||||
Ok(None)
|
//Ok(None)
|
||||||
}
|
//}
|
||||||
fn set_path (browser: &mut Browser, address: PathBuf) -> Perhaps<Self> {
|
//fn set_search (browser: &mut Browser, filter: Arc<str>) -> Perhaps<Self> {
|
||||||
Ok(None)
|
//Ok(None)
|
||||||
}
|
//}
|
||||||
fn set_search (browser: &mut Browser, filter: Arc<str>) -> Perhaps<Self> {
|
//fn set_cursor (browser: &mut Browser, cursor: usize) -> Perhaps<Self> {
|
||||||
Ok(None)
|
//Ok(None)
|
||||||
}
|
//}
|
||||||
fn set_cursor (browser: &mut Browser, cursor: usize) -> Perhaps<Self> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commands supported by [Browser]
|
// Commands supported by [Browser]
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::ffi::OsString;
|
|
||||||
|
|
||||||
/// Browses for phrase to import/export
|
/// Browses for phrase to import/export
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
pub cwd: PathBuf,
|
pub cwd: PathBuf,
|
||||||
pub dirs: Vec<(OsString, String)>,
|
pub dirs: Vec<(OsString, String)>,
|
||||||
pub files: Vec<(OsString, String)>,
|
pub files: Vec<(OsString, String)>,
|
||||||
pub filter: String,
|
pub filter: String,
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
pub scroll: usize,
|
pub scroll: usize,
|
||||||
pub size: Measure<TuiOut>,
|
pub size: Measure<TuiOut>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Browser {
|
impl Browser {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
mod clock_api; pub use self::clock_api::*;
|
mod clock_api; pub use self::clock_api::*;
|
||||||
mod clock_model; pub use self::clock_model::*;
|
mod clock_model; pub use self::clock_model::*;
|
||||||
mod clock_view; pub use self::clock_view::*;
|
mod clock_view; pub use self::clock_view::*;
|
||||||
|
|
@ -9,11 +7,11 @@ pub trait HasClock: Send + Sync {
|
||||||
fn clock_mut (&mut self) -> &mut Clock;
|
fn clock_mut (&mut self) -> &mut Clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Has<Clock>> HasClock for T {
|
#[macro_export] macro_rules! has_clock {
|
||||||
fn clock (&self) -> &Clock {
|
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||||
self.get()
|
impl $(<$($L),*$($T $(: $U)?),*>)? HasClock for $Struct $(<$($L),*$($T),*>)? {
|
||||||
}
|
fn clock (&$self) -> &Clock { &$cb }
|
||||||
fn clock_mut (&mut self) -> &mut Clock {
|
fn clock_mut (&mut $self) -> &mut Clock { &mut $cb }
|
||||||
self.get_mut()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,25 +177,4 @@ impl Clock {
|
||||||
pub fn next_launch_instant (&self) -> Moment {
|
pub fn next_launch_instant (&self) -> Moment {
|
||||||
Moment::from_pulse(self.timebase(), self.next_launch_pulse() as f64)
|
Moment::from_pulse(self.timebase(), self.next_launch_pulse() as f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get index of first sample to populate.
|
|
||||||
///
|
|
||||||
/// Greater than 0 means that the first pulse of the clip
|
|
||||||
/// falls somewhere in the middle of the chunk.
|
|
||||||
pub fn get_sample_offset (&self, scope: &ProcessScope, started: &Moment) -> usize{
|
|
||||||
(scope.last_frame_time() as usize).saturating_sub(
|
|
||||||
started.sample.get() as usize +
|
|
||||||
self.started.read().unwrap().as_ref().unwrap().sample.get() as usize
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get iterator that emits sample paired with pulse.
|
|
||||||
//
|
|
||||||
// * Sample: index into output buffer at which to write MIDI event
|
|
||||||
// * Pulse: index into clip from which to take the MIDI event
|
|
||||||
//
|
|
||||||
// Emitted for each sample of the output buffer that corresponds to a MIDI pulse.
|
|
||||||
pub fn get_pulses (&self, scope: &ProcessScope, offset: usize) -> TicksIterator {
|
|
||||||
self.timebase().pulses_between_samples(offset, offset + scope.n_frames() as usize)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,14 @@ pub fn view_transport (
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view_status (
|
pub fn view_status (
|
||||||
sel: Option<Arc<str>>,
|
sel: Arc<str>,
|
||||||
sr: Arc<RwLock<String>>,
|
sr: Arc<RwLock<String>>,
|
||||||
buf: Arc<RwLock<String>>,
|
buf: Arc<RwLock<String>>,
|
||||||
lat: Arc<RwLock<String>>,
|
lat: Arc<RwLock<String>>,
|
||||||
) -> impl Content<TuiOut> {
|
) -> impl Content<TuiOut> {
|
||||||
let theme = ItemTheme::G[96];
|
let theme = ItemTheme::G[96];
|
||||||
Tui::bg(Black, row!(Bsp::a(
|
Tui::bg(Black, row!(Bsp::a(
|
||||||
Fill::xy(Align::w(sel.map(|sel|FieldH(theme, "Selected", sel)))),
|
Fill::xy(Align::w(FieldH(theme, "Selected", sel))),
|
||||||
Fill::xy(Align::e(row!(
|
Fill::xy(Align::e(row!(
|
||||||
FieldH(theme, "SR", sr),
|
FieldH(theme, "SR", sr),
|
||||||
FieldH(theme, "Buf", buf),
|
FieldH(theme, "Buf", buf),
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,5 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
impl<T: Has<Vec<Device>> + Has<Track>> HasDevices for T {
|
|
||||||
fn devices (&self) -> &Vec<Device> {
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
fn devices_mut (&mut self) -> &mut Vec<Device> {
|
|
||||||
self.get_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait HasDevices: Has<Track> {
|
|
||||||
fn devices (&self) -> &Vec<Device>;
|
|
||||||
fn devices_mut (&mut self) -> &mut Vec<Device>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Device {
|
pub enum Device {
|
||||||
#[cfg(feature = "sampler")]
|
#[cfg(feature = "sampler")]
|
||||||
|
|
@ -63,7 +49,3 @@ audio!(|self: DeviceAudio<'a>, client, scope|{
|
||||||
Sf2 => { todo!() }, // TODO
|
Sf2 => { todo!() }, // TODO
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#[tengri_proc::command(Device)]
|
|
||||||
impl DeviceCommand {
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ pub struct MidiEditor {
|
||||||
pub mode: PianoHorizontal,
|
pub mode: PianoHorizontal,
|
||||||
}
|
}
|
||||||
|
|
||||||
has!(Measure<TuiOut>: |self: MidiEditor|self.size);
|
|
||||||
|
|
||||||
impl std::fmt::Debug for MidiEditor {
|
impl std::fmt::Debug for MidiEditor {
|
||||||
fn fmt (&self, f: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
fn fmt (&self, f: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||||
f.debug_struct("MidiEditor")
|
f.debug_struct("MidiEditor")
|
||||||
|
|
@ -104,8 +102,8 @@ impl MidiViewer for MidiEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasEditor {
|
pub trait HasEditor {
|
||||||
fn editor (&self) -> Option<&MidiEditor>;
|
fn editor (&self) -> &Option<MidiEditor>;
|
||||||
fn editor_mut (&mut self) -> Option<&mut MidiEditor>;
|
fn editor_mut (&mut self) -> &Option<MidiEditor>;
|
||||||
fn is_editing (&self) -> bool { true }
|
fn is_editing (&self) -> bool { true }
|
||||||
fn editor_w (&self) -> usize { 0 }
|
fn editor_w (&self) -> usize { 0 }
|
||||||
fn editor_h (&self) -> usize { 0 }
|
fn editor_h (&self) -> usize { 0 }
|
||||||
|
|
@ -119,12 +117,17 @@ pub trait HasEditor {
|
||||||
is_editing = $e3:expr;
|
is_editing = $e3:expr;
|
||||||
}) => {
|
}) => {
|
||||||
impl HasEditor for $Struct {
|
impl HasEditor for $Struct {
|
||||||
fn editor (&$self) -> Option<&MidiEditor> { $e0.as_ref() }
|
fn editor (&$self) -> &Option<MidiEditor> { &$e0 }
|
||||||
fn editor_mut (&mut $self) -> Option<&mut MidiEditor> { $e0.as_mut() }
|
fn editor_mut (&mut $self) -> &Option<MidiEditor> { &mut $e0 }
|
||||||
fn editor_w (&$self) -> usize { $e1 }
|
fn editor_w (&$self) -> usize { $e1 }
|
||||||
fn editor_h (&$self) -> usize { $e2 }
|
fn editor_h (&$self) -> usize { $e2 }
|
||||||
fn is_editing (&$self) -> bool { $e3 }
|
fn is_editing (&$self) -> bool { $e3 }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||||
|
impl $(<$($L),*$($T $(: $U)?),*>)? HasEditor for $Struct $(<$($L),*$($T),*>)? {
|
||||||
|
fn editor (&$self) -> &MidiEditor { &$cb }
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
has_size!(<TuiOut>|self: MidiEditor|&self.size);
|
||||||
|
|
||||||
content!(TuiOut: |self: MidiEditor| {
|
content!(TuiOut: |self: MidiEditor| {
|
||||||
self.autoscroll();
|
self.autoscroll();
|
||||||
//self.autozoom();
|
//self.autozoom();
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ pub struct PianoHorizontal {
|
||||||
pub keys_width: u16,
|
pub keys_width: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
has!(Measure<TuiOut>:|self:PianoHorizontal|self.size);
|
|
||||||
|
|
||||||
impl PianoHorizontal {
|
impl PianoHorizontal {
|
||||||
pub fn new (clip: Option<&Arc<RwLock<MidiClip>>>) -> Self {
|
pub fn new (clip: Option<&Arc<RwLock<MidiClip>>>) -> Self {
|
||||||
let size = Measure::new();
|
let size = Measure::new();
|
||||||
|
|
@ -229,6 +227,8 @@ impl PianoHorizontal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has_size!(<TuiOut>|self:PianoHorizontal|&self.size);
|
||||||
|
|
||||||
impl TimeRange for PianoHorizontal {
|
impl TimeRange for PianoHorizontal {
|
||||||
fn time_len (&self) -> &AtomicUsize { self.range.time_len() }
|
fn time_len (&self) -> &AtomicUsize { self.range.time_len() }
|
||||||
fn time_zoom (&self) -> &AtomicUsize { self.range.time_zoom() }
|
fn time_zoom (&self) -> &AtomicUsize { self.range.time_zoom() }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(trait_alias)]
|
|
||||||
#![feature(if_let_guard)]
|
|
||||||
|
|
||||||
pub(crate) use std::cmp::Ord;
|
pub(crate) use std::cmp::Ord;
|
||||||
pub(crate) use std::fmt::{Debug, Formatter};
|
pub(crate) use std::fmt::{Debug, Formatter};
|
||||||
|
|
@ -12,8 +10,7 @@ pub(crate) use std::path::PathBuf;
|
||||||
pub(crate) use std::error::Error;
|
pub(crate) use std::error::Error;
|
||||||
pub(crate) use std::ffi::OsString;
|
pub(crate) use std::ffi::OsString;
|
||||||
|
|
||||||
pub(crate) use ::tengri::{from, Usually, Perhaps, Has};
|
pub(crate) use ::tengri::{Usually, Perhaps, dsl::*, input::*, output::*, tui::{*, ratatui::prelude::*}};
|
||||||
pub(crate) use ::tengri::{dsl::*, input::*, output::*, tui::{*, ratatui::prelude::*}};
|
|
||||||
pub(crate) use ::tek_engine::*;
|
pub(crate) use ::tek_engine::*;
|
||||||
pub(crate) use ::tek_engine::midi::{u7, LiveEvent, MidiMessage};
|
pub(crate) use ::tek_engine::midi::{u7, LiveEvent, MidiMessage};
|
||||||
pub(crate) use ::tek_engine::jack::{Control, ProcessScope, MidiWriter, RawMidi};
|
pub(crate) use ::tek_engine::jack::{Control, ProcessScope, MidiWriter, RawMidi};
|
||||||
|
|
@ -23,9 +20,6 @@ pub(crate) use Color::*;
|
||||||
mod device;
|
mod device;
|
||||||
pub use self::device::*;
|
pub use self::device::*;
|
||||||
|
|
||||||
#[cfg(feature = "arranger")] mod arranger;
|
|
||||||
#[cfg(feature = "arranger")] pub use self::arranger::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "browser")] mod browser;
|
#[cfg(feature = "browser")] mod browser;
|
||||||
#[cfg(feature = "browser")] pub use self::browser::*;
|
#[cfg(feature = "browser")] pub use self::browser::*;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ use crate::*;
|
||||||
pub struct Pool {
|
pub struct Pool {
|
||||||
pub visible: bool,
|
pub visible: bool,
|
||||||
/// Collection of clips
|
/// Collection of clips
|
||||||
pub clips: Arc<RwLock<Vec<Arc<RwLock<MidiClip>>>>>,
|
pub clips: Arc<RwLock<Vec<Arc<RwLock<MidiClip>>>>>,
|
||||||
/// Selected clip
|
/// Selected clip
|
||||||
pub clip: AtomicUsize,
|
pub clip: AtomicUsize,
|
||||||
/// Mode switch
|
/// Mode switch
|
||||||
pub mode: Option<PoolMode>,
|
pub mode: Option<PoolMode>,
|
||||||
/// Embedded file browser
|
/// Embedded file browser
|
||||||
pub browser: Option<Browser>,
|
pub browser: Option<Browser>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,31 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub struct PoolView<'a>(pub &'a Pool);
|
pub struct PoolView<'a>(pub bool, pub &'a Pool);
|
||||||
|
|
||||||
content!(TuiOut: |self: PoolView<'a>| {
|
content!(TuiOut: |self: PoolView<'a>| {
|
||||||
let Self(pool) = self;
|
let Self(compact, model) = self;
|
||||||
|
let Pool { clips, .. } = self.1;
|
||||||
//let color = self.1.clip().map(|c|c.read().unwrap().color).unwrap_or_else(||Tui::g(32).into());
|
//let color = self.1.clip().map(|c|c.read().unwrap().color).unwrap_or_else(||Tui::g(32).into());
|
||||||
//let on_bg = |x|x;//Bsp::b(Repeat(" "), Tui::bg(color.darkest.rgb, x));
|
let on_bg = |x|x;//Bsp::b(Repeat(" "), Tui::bg(color.darkest.rgb, x));
|
||||||
//let border = |x|x;//Outer(Style::default().fg(color.dark.rgb).bg(color.darkest.rgb)).enclose(x);
|
let border = |x|x;//Outer(Style::default().fg(color.dark.rgb).bg(color.darkest.rgb)).enclose(x);
|
||||||
let height = pool.clips.read().unwrap().len() as u16;
|
let iter = | |model.clips().clone().into_iter();
|
||||||
Fixed::x(20, Fill::y(Align::c(Map::new(
|
let height = clips.read().unwrap().len() as u16;
|
||||||
||pool.clips().clone().into_iter(),
|
Tui::bg(Reset, Fixed::y(height, on_bg(border(Map::new(iter, move|clip: Arc<RwLock<MidiClip>>, i|{
|
||||||
move|clip: Arc<RwLock<MidiClip>>, i: usize|{
|
|
||||||
let item_height = 1;
|
let item_height = 1;
|
||||||
let item_offset = i as u16 * item_height;
|
let item_offset = i as u16 * item_height;
|
||||||
let selected = i == pool.clip_index();
|
let selected = i == model.clip_index();
|
||||||
let MidiClip { ref name, color, length, .. } = *clip.read().unwrap();
|
let MidiClip { ref name, color, length, .. } = *clip.read().unwrap();
|
||||||
let bg = if selected { color.light.rgb } else { color.base.rgb };
|
let bg = if selected { color.light.rgb } else { color.base.rgb };
|
||||||
let fg = color.lightest.rgb;
|
let fg = color.lightest.rgb;
|
||||||
let name = if false { format!(" {i:>3}") } else { format!(" {i:>3} {name}") };
|
let name = if *compact { format!(" {i:>3}") } else { format!(" {i:>3} {name}") };
|
||||||
let length = if false { String::default() } else { format!("{length} ") };
|
let length = if *compact { String::default() } else { format!("{length} ") };
|
||||||
Fixed::y(1, map_south(item_offset, item_height, Tui::bg(bg, lay!(
|
Fixed::y(1, map_south(item_offset, item_height, Tui::bg(bg, lay!(
|
||||||
Fill::x(Align::w(Tui::fg(fg, Tui::bold(selected, name)))),
|
Fill::x(Align::w(Tui::fg(fg, Tui::bold(selected, name)))),
|
||||||
Fill::x(Align::e(Tui::fg(fg, Tui::bold(selected, length)))),
|
Fill::x(Align::e(Tui::fg(fg, Tui::bold(selected, length)))),
|
||||||
Fill::x(Align::w(When::new(selected, Tui::bold(true, Tui::fg(Tui::g(255), "▶"))))),
|
Fill::x(Align::w(When::new(selected, Tui::bold(true, Tui::fg(Tui::g(255), "▶"))))),
|
||||||
Fill::x(Align::e(When::new(selected, Tui::bold(true, Tui::fg(Tui::g(255), "◀"))))),
|
Fill::x(Align::e(When::new(selected, Tui::bold(true, Tui::fg(Tui::g(255), "◀"))))),
|
||||||
))))
|
))))
|
||||||
}))))
|
})))))
|
||||||
});
|
});
|
||||||
|
|
||||||
content!(TuiOut: |self: ClipLength| {
|
content!(TuiOut: |self: ClipLength| {
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,82 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
/// Hosts the JACK callback for a single MIDI sequencer
|
||||||
|
pub struct PlayerAudio<'a, T: MidiSequencer>(
|
||||||
|
/// Player
|
||||||
|
pub &'a mut T,
|
||||||
|
/// Note buffer
|
||||||
|
pub &'a mut Vec<u8>,
|
||||||
|
/// Note chunk buffer
|
||||||
|
pub &'a mut Vec<Vec<Vec<u8>>>,
|
||||||
|
);
|
||||||
|
|
||||||
/// JACK process callback for a sequencer's clip sequencer/recorder.
|
/// JACK process callback for a sequencer's clip sequencer/recorder.
|
||||||
impl Audio for Sequencer {
|
impl<T: MidiSequencer> Audio for PlayerAudio<'_, T> {
|
||||||
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||||
if self.clock().is_rolling() {
|
let model = &mut self.0;
|
||||||
self.process_rolling(scope)
|
let note_buf = &mut self.1;
|
||||||
} else {
|
let midi_buf = &mut self.2;
|
||||||
self.process_stopped(scope)
|
// Clear output buffer(s)
|
||||||
|
model.clear(scope, midi_buf, false);
|
||||||
|
// Write chunk of clip to output, handle switchover
|
||||||
|
if model.play(scope, note_buf, midi_buf) {
|
||||||
|
model.switchover(scope, note_buf, midi_buf);
|
||||||
}
|
}
|
||||||
|
if model.has_midi_ins() {
|
||||||
|
if model.recording() || model.monitoring() {
|
||||||
|
// Record and/or monitor input
|
||||||
|
model.record(scope, midi_buf)
|
||||||
|
} else if model.has_midi_outs() && model.monitoring() {
|
||||||
|
// Monitor input to output
|
||||||
|
model.monitor(scope, midi_buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Write to output port(s)
|
||||||
|
model.write(scope, midi_buf);
|
||||||
|
Control::Continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sequencer {
|
pub trait MidiSequencer: MidiRecorder + MidiPlayer + Send + Sync {}
|
||||||
fn process_rolling (&mut self, scope: &ProcessScope) -> Control {
|
|
||||||
self.process_clear(scope, false);
|
impl MidiSequencer for Sequencer {}
|
||||||
// Write chunk of clip to output, handle switchover
|
|
||||||
if self.process_playback(scope) {
|
pub trait MidiRecorder: HasClock + HasPlayClip + HasMidiIns {
|
||||||
self.process_switchover(scope);
|
fn notes_in (&self) -> &Arc<RwLock<[bool;128]>>;
|
||||||
}
|
|
||||||
// Monitor input to output
|
fn recording (&self) -> bool;
|
||||||
self.process_monitoring(scope);
|
|
||||||
// Record and/or monitor input
|
fn recording_mut (&mut self) -> &mut bool;
|
||||||
self.process_recording(scope);
|
|
||||||
// Emit contents of MIDI buffers to JACK MIDI output ports.
|
fn toggle_record (&mut self) {
|
||||||
self.midi_outs_emit(scope);
|
*self.recording_mut() = !self.recording();
|
||||||
Control::Continue
|
|
||||||
}
|
}
|
||||||
fn process_stopped (&mut self, scope: &ProcessScope) -> Control {
|
|
||||||
if self.monitoring() && self.midi_ins().len() > 0 && self.midi_outs().len() > 0 {
|
fn monitoring (&self) -> bool;
|
||||||
self.process_monitoring(scope)
|
|
||||||
}
|
fn monitoring_mut (&mut self) -> &mut bool;
|
||||||
Control::Continue
|
|
||||||
|
fn toggle_monitor (&mut self) {
|
||||||
|
*self.monitoring_mut() = !self.monitoring();
|
||||||
}
|
}
|
||||||
fn process_monitoring (&mut self, scope: &ProcessScope) {
|
|
||||||
let notes_in = self.notes_in().clone(); // For highlighting keys and note repeat
|
fn overdub (&self) -> bool;
|
||||||
|
|
||||||
|
fn overdub_mut (&mut self) -> &mut bool;
|
||||||
|
|
||||||
|
fn toggle_overdub (&mut self) {
|
||||||
|
*self.overdub_mut() = !self.overdub();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn monitor (&mut self, scope: &ProcessScope, midi_buf: &mut Vec<Vec<Vec<u8>>>) {
|
||||||
|
// For highlighting keys and note repeat
|
||||||
|
let notes_in = self.notes_in().clone();
|
||||||
let monitoring = self.monitoring();
|
let monitoring = self.monitoring();
|
||||||
for input in self.midi_ins.iter() {
|
for input in self.midi_ins_mut().iter() {
|
||||||
for (sample, event, bytes) in input.parsed(scope) {
|
for (sample, event, bytes) in parse_midi_input(input.port().iter(scope)) {
|
||||||
if let LiveEvent::Midi { message, .. } = event {
|
if let LiveEvent::Midi { message, .. } = event {
|
||||||
if monitoring {
|
if monitoring {
|
||||||
self.midi_buf[sample].push(bytes.to_vec());
|
midi_buf[sample].push(bytes.to_vec());
|
||||||
}
|
}
|
||||||
// FIXME: don't lock on every event!
|
// FIXME: don't lock on every event!
|
||||||
update_keys(&mut notes_in.write().unwrap(), &message);
|
update_keys(&mut notes_in.write().unwrap(), &message);
|
||||||
|
|
@ -47,143 +84,28 @@ impl Sequencer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Clear the section of the output buffer that we will be using,
|
|
||||||
/// emitting "all notes off" at start of buffer if requested.
|
fn record (&mut self, scope: &ProcessScope, midi_buf: &mut Vec<Vec<Vec<u8>>>) {
|
||||||
fn process_clear (&mut self, scope: &ProcessScope, reset: bool) {
|
|
||||||
let n_frames = (scope.n_frames() as usize).min(self.midi_buf_mut().len());
|
|
||||||
for frame in &mut self.midi_buf_mut()[0..n_frames] {
|
|
||||||
frame.clear();
|
|
||||||
}
|
|
||||||
if reset {
|
|
||||||
all_notes_off(self.midi_buf_mut());
|
|
||||||
}
|
|
||||||
for port in self.midi_outs_mut().iter_mut() {
|
|
||||||
// Clear output buffer(s)
|
|
||||||
port.buffer_clear(scope, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn process_recording (&mut self, scope: &ProcessScope) {
|
|
||||||
if self.monitoring() {
|
if self.monitoring() {
|
||||||
self.monitor(scope);
|
self.monitor(scope, midi_buf);
|
||||||
}
|
}
|
||||||
if let Some((started, ref clip)) = self.play_clip.clone() {
|
if !self.clock().is_rolling() {
|
||||||
self.record_clip(scope, started, clip);
|
return
|
||||||
|
}
|
||||||
|
if let Some((started, ref clip)) = self.play_clip().clone() {
|
||||||
|
self.record_clip(scope, started, clip, midi_buf);
|
||||||
}
|
}
|
||||||
if let Some((_start_at, _clip)) = &self.next_clip() {
|
if let Some((_start_at, _clip)) = &self.next_clip() {
|
||||||
self.record_next();
|
self.record_next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn process_playback (&mut self, scope: &ProcessScope) -> bool {
|
|
||||||
// If a clip is playing, write a chunk of MIDI events from it to the output buffer.
|
|
||||||
// If no clip is playing, prepare for switchover immediately.
|
|
||||||
if let Some((started, clip)) = &self.play_clip {
|
|
||||||
// Length of clip, to repeat or stop on end.
|
|
||||||
let length = clip.as_ref().map_or(0, |p|p.read().unwrap().length);
|
|
||||||
// Index of first sample to populate.
|
|
||||||
let offset = self.clock().get_sample_offset(scope, &started);
|
|
||||||
// Write MIDI events from clip at sample offsets corresponding to pulses.
|
|
||||||
for (sample, pulse) in self.clock().get_pulses(scope, offset) {
|
|
||||||
// If a next clip is enqueued, and we're past the end of the current one,
|
|
||||||
// break the loop here (FIXME count pulse correctly)
|
|
||||||
let past_end = if clip.is_some() { pulse >= length } else { true };
|
|
||||||
// Is it time for switchover?
|
|
||||||
if self.next_clip().is_some() && past_end {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// If there's a currently playing clip, output notes from it to buffer:
|
|
||||||
if let Some(ref clip) = clip {
|
|
||||||
// Source clip from which the MIDI events will be taken.
|
|
||||||
let clip = clip.read().unwrap();
|
|
||||||
// Clip with zero length is not processed
|
|
||||||
if clip.length > 0 {
|
|
||||||
// Current pulse index in source clip
|
|
||||||
let pulse = pulse % clip.length;
|
|
||||||
// Output each MIDI event from clip at appropriate frames of output buffer:
|
|
||||||
for message in clip.notes[pulse].iter() {
|
|
||||||
for port in self.midi_outs.iter_mut() {
|
|
||||||
port.buffer_write(sample, LiveEvent::Midi {
|
|
||||||
channel: 0.into(), /* TODO */
|
|
||||||
message: *message
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Handle switchover from current to next playing clip.
|
|
||||||
fn process_switchover (&mut self, scope: &ProcessScope) {
|
|
||||||
let midi_buf = self.midi_buf_mut();
|
|
||||||
let sample0 = scope.last_frame_time() as usize;
|
|
||||||
//let samples = scope.n_frames() as usize;
|
|
||||||
if let Some((start_at, clip)) = &self.next_clip() {
|
|
||||||
let start = start_at.sample.get() as usize;
|
|
||||||
let sample = self.clock().started.read().unwrap()
|
|
||||||
.as_ref().unwrap().sample.get() as usize;
|
|
||||||
// If it's time to switch to the next clip:
|
|
||||||
if start <= sample0.saturating_sub(sample) {
|
|
||||||
// Samples elapsed since clip was supposed to start
|
|
||||||
let _skipped = sample0 - start;
|
|
||||||
// Switch over to enqueued clip
|
|
||||||
let started = Moment::from_sample(self.clock().timebase(), start as f64);
|
|
||||||
// Launch enqueued clip
|
|
||||||
*self.play_clip_mut() = Some((started, clip.clone()));
|
|
||||||
// Unset enqueuement (TODO: where to implement looping?)
|
|
||||||
*self.next_clip_mut() = None;
|
|
||||||
// Fill in remaining ticks of chunk from next clip.
|
|
||||||
self.process_playback(scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait HasMidiBuffers {
|
|
||||||
fn note_buf_mut (&mut self) -> &mut Vec<u8>;
|
|
||||||
fn midi_buf_mut (&mut self) -> &mut Vec<Vec<Vec<u8>>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HasMidiBuffers for Sequencer {
|
|
||||||
fn note_buf_mut (&mut self) -> &mut Vec<u8> {
|
|
||||||
&mut self.note_buf
|
|
||||||
}
|
|
||||||
fn midi_buf_mut (&mut self) -> &mut Vec<Vec<Vec<u8>>> {
|
|
||||||
&mut self.midi_buf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait MidiMonitor: HasMidiIns + HasMidiBuffers {
|
|
||||||
fn notes_in (&self) -> &Arc<RwLock<[bool;128]>>;
|
|
||||||
fn monitoring (&self) -> bool;
|
|
||||||
fn monitoring_mut (&mut self) -> &mut bool;
|
|
||||||
fn toggle_monitor (&mut self) {
|
|
||||||
*self.monitoring_mut() = !self.monitoring();
|
|
||||||
}
|
|
||||||
fn monitor (&mut self, scope: &ProcessScope) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait MidiRecord: MidiMonitor + HasClock + HasPlayClip {
|
|
||||||
fn recording (&self) -> bool;
|
|
||||||
fn recording_mut (&mut self) -> &mut bool;
|
|
||||||
fn toggle_record (&mut self) {
|
|
||||||
*self.recording_mut() = !self.recording();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn overdub (&self) -> bool;
|
|
||||||
fn overdub_mut (&mut self) -> &mut bool;
|
|
||||||
fn toggle_overdub (&mut self) {
|
|
||||||
*self.overdub_mut() = !self.overdub();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn record_clip (
|
fn record_clip (
|
||||||
&mut self,
|
&mut self,
|
||||||
scope: &ProcessScope,
|
scope: &ProcessScope,
|
||||||
started: Moment,
|
started: Moment,
|
||||||
clip: &Option<Arc<RwLock<MidiClip>>>,
|
clip: &Option<Arc<RwLock<MidiClip>>>,
|
||||||
|
_midi_buf: &mut Vec<Vec<Vec<u8>>>
|
||||||
) {
|
) {
|
||||||
if let Some(clip) = clip {
|
if let Some(clip) = clip {
|
||||||
let sample0 = scope.last_frame_time() as usize;
|
let sample0 = scope.last_frame_time() as usize;
|
||||||
|
|
@ -191,7 +113,7 @@ pub trait MidiRecord: MidiMonitor + HasClock + HasPlayClip {
|
||||||
let _recording = self.recording();
|
let _recording = self.recording();
|
||||||
let timebase = self.clock().timebase().clone();
|
let timebase = self.clock().timebase().clone();
|
||||||
let quant = self.clock().quant.get();
|
let quant = self.clock().quant.get();
|
||||||
let mut clip = clip.write().unwrap();
|
let mut clip = clip.write().unwrap();
|
||||||
let length = clip.length;
|
let length = clip.length;
|
||||||
for input in self.midi_ins_mut().iter() {
|
for input in self.midi_ins_mut().iter() {
|
||||||
for (sample, event, _bytes) in parse_midi_input(input.port().iter(scope)) {
|
for (sample, event, _bytes) in parse_midi_input(input.port().iter(scope)) {
|
||||||
|
|
@ -211,4 +133,173 @@ pub trait MidiRecord: MidiMonitor + HasClock + HasPlayClip {
|
||||||
fn record_next (&mut self) {
|
fn record_next (&mut self) {
|
||||||
// TODO switch to next clip and record into it
|
// TODO switch to next clip and record into it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait MidiPlayer: HasPlayClip + HasClock + HasMidiOuts {
|
||||||
|
|
||||||
|
fn notes_out (&self) -> &Arc<RwLock<[bool;128]>>;
|
||||||
|
|
||||||
|
/// Clear the section of the output buffer that we will be using,
|
||||||
|
/// emitting "all notes off" at start of buffer if requested.
|
||||||
|
fn clear (
|
||||||
|
&mut self, scope: &ProcessScope, out: &mut [Vec<Vec<u8>>], reset: bool
|
||||||
|
) {
|
||||||
|
let n_frames = (scope.n_frames() as usize).min(out.len());
|
||||||
|
for frame in &mut out[0..n_frames] {
|
||||||
|
frame.clear();
|
||||||
|
}
|
||||||
|
if reset {
|
||||||
|
all_notes_off(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Output notes from clip to MIDI output ports.
|
||||||
|
fn play (
|
||||||
|
&mut self, scope: &ProcessScope, note_buf: &mut Vec<u8>, out: &mut [Vec<Vec<u8>>]
|
||||||
|
) -> bool {
|
||||||
|
if !self.clock().is_rolling() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// If a clip is playing, write a chunk of MIDI events from it to the output buffer.
|
||||||
|
// If no clip is playing, prepare for switchover immediately.
|
||||||
|
if let Some((started, clip)) = self.play_clip() {
|
||||||
|
self.play_chunk(scope, note_buf, out, started, clip)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn play_chunk (
|
||||||
|
&self,
|
||||||
|
scope: &ProcessScope,
|
||||||
|
note_buf: &mut Vec<u8>,
|
||||||
|
out: &mut [Vec<Vec<u8>>],
|
||||||
|
started: &Moment,
|
||||||
|
clip: &Option<Arc<RwLock<MidiClip>>>
|
||||||
|
) -> bool {
|
||||||
|
// Index of first sample to populate.
|
||||||
|
let offset = self.get_sample_offset(scope, started);
|
||||||
|
// Notes active during current chunk.
|
||||||
|
let notes = &mut self.notes_out().write().unwrap();
|
||||||
|
// Length of clip.
|
||||||
|
let length = clip.as_ref().map_or(0, |p|p.read().unwrap().length);
|
||||||
|
// Write MIDI events from clip at sample offsets corresponding to pulses.
|
||||||
|
for (sample, pulse) in self.get_pulses(scope, offset) {
|
||||||
|
// If a next clip is enqueued, and we're past the end of the current one,
|
||||||
|
// break the loop here (FIXME count pulse correctly)
|
||||||
|
let past_end = if clip.is_some() { pulse >= length } else { true };
|
||||||
|
// Is it time for switchover?
|
||||||
|
if self.next_clip().is_some() && past_end {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// If there's a currently playing clip, output notes from it to buffer:
|
||||||
|
if let Some(ref clip) = clip {
|
||||||
|
Self::play_pulse(clip, pulse, sample, note_buf, out, notes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get index of first sample to populate.
|
||||||
|
///
|
||||||
|
/// Greater than 0 means that the first pulse of the clip
|
||||||
|
/// falls somewhere in the middle of the chunk.
|
||||||
|
fn get_sample_offset (&self, scope: &ProcessScope, started: &Moment) -> usize{
|
||||||
|
(scope.last_frame_time() as usize).saturating_sub(
|
||||||
|
started.sample.get() as usize +
|
||||||
|
self.clock().started.read().unwrap().as_ref().unwrap().sample.get() as usize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get iterator that emits sample paired with pulse.
|
||||||
|
//
|
||||||
|
// * Sample: index into output buffer at which to write MIDI event
|
||||||
|
// * Pulse: index into clip from which to take the MIDI event
|
||||||
|
//
|
||||||
|
// Emitted for each sample of the output buffer that corresponds to a MIDI pulse.
|
||||||
|
fn get_pulses (&self, scope: &ProcessScope, offset: usize) -> TicksIterator {
|
||||||
|
self.clock().timebase().pulses_between_samples(
|
||||||
|
offset, offset + scope.n_frames() as usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle switchover from current to next playing clip.
|
||||||
|
fn switchover (
|
||||||
|
&mut self, scope: &ProcessScope, note_buf: &mut Vec<u8>, out: &mut [Vec<Vec<u8>>]
|
||||||
|
) {
|
||||||
|
if !self.clock().is_rolling() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let sample0 = scope.last_frame_time() as usize;
|
||||||
|
//let samples = scope.n_frames() as usize;
|
||||||
|
if let Some((start_at, clip)) = &self.next_clip() {
|
||||||
|
let start = start_at.sample.get() as usize;
|
||||||
|
let sample = self.clock().started.read().unwrap()
|
||||||
|
.as_ref().unwrap().sample.get() as usize;
|
||||||
|
// If it's time to switch to the next clip:
|
||||||
|
if start <= sample0.saturating_sub(sample) {
|
||||||
|
// Samples elapsed since clip was supposed to start
|
||||||
|
let _skipped = sample0 - start;
|
||||||
|
// Switch over to enqueued clip
|
||||||
|
let started = Moment::from_sample(self.clock().timebase(), start as f64);
|
||||||
|
// Launch enqueued clip
|
||||||
|
*self.play_clip_mut() = Some((started, clip.clone()));
|
||||||
|
// Unset enqueuement (TODO: where to implement looping?)
|
||||||
|
*self.next_clip_mut() = None;
|
||||||
|
// Fill in remaining ticks of chunk from next clip.
|
||||||
|
self.play(scope, note_buf, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn play_pulse (
|
||||||
|
clip: &RwLock<MidiClip>,
|
||||||
|
pulse: usize,
|
||||||
|
sample: usize,
|
||||||
|
note_buf: &mut Vec<u8>,
|
||||||
|
out: &mut [Vec<Vec<u8>>],
|
||||||
|
notes: &mut [bool;128]
|
||||||
|
) {
|
||||||
|
// Source clip from which the MIDI events will be taken.
|
||||||
|
let clip = clip.read().unwrap();
|
||||||
|
// Clip with zero length is not processed
|
||||||
|
if clip.length > 0 {
|
||||||
|
// Current pulse index in source clip
|
||||||
|
let pulse = pulse % clip.length;
|
||||||
|
// Output each MIDI event from clip at appropriate frames of output buffer:
|
||||||
|
for message in clip.notes[pulse].iter() {
|
||||||
|
// Clear output buffer for this MIDI event.
|
||||||
|
note_buf.clear();
|
||||||
|
// TODO: support MIDI channels other than CH1.
|
||||||
|
let channel = 0.into();
|
||||||
|
// Serialize MIDI event into message buffer.
|
||||||
|
LiveEvent::Midi { channel, message: *message }
|
||||||
|
.write(note_buf)
|
||||||
|
.unwrap();
|
||||||
|
// Append serialized message to output buffer.
|
||||||
|
out[sample].push(note_buf.clone());
|
||||||
|
// Update the list of currently held notes.
|
||||||
|
update_keys(&mut*notes, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write a chunk of MIDI data from the output buffer to all assigned output ports.
|
||||||
|
fn write (&mut self, scope: &ProcessScope, out: &[Vec<Vec<u8>>]) {
|
||||||
|
let samples = scope.n_frames() as usize;
|
||||||
|
for port in self.midi_outs_mut().iter_mut() {
|
||||||
|
Self::write_port(&mut port.port_mut().writer(scope), samples, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write a chunk of MIDI data from the output buffer to an output port.
|
||||||
|
fn write_port (writer: &mut MidiWriter, samples: usize, out: &[Vec<Vec<u8>>]) {
|
||||||
|
for (time, events) in out.iter().enumerate().take(samples) {
|
||||||
|
for bytes in events.iter() {
|
||||||
|
writer.write(&RawMidi { time: time as u32, bytes }).unwrap_or_else(|_|{
|
||||||
|
panic!("Failed to write MIDI data: {bytes:?}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
//! MIDI sequencer
|
//! MIDI sequencer
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
impl<T: Has<Sequencer>> HasSequencer for T {
|
pub trait HasSequencer {
|
||||||
fn sequencer (&self) -> &Sequencer {
|
fn sequencer (&self) -> &impl MidiSequencer;
|
||||||
self.get()
|
fn sequencer_mut (&mut self) -> &mut impl MidiSequencer;
|
||||||
}
|
|
||||||
fn sequencer_mut (&mut self) -> &mut Sequencer {
|
|
||||||
self.get_mut()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasSequencer {
|
#[macro_export] macro_rules! has_sequencer {
|
||||||
fn sequencer (&self) -> &Sequencer;
|
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||||
fn sequencer_mut (&mut self) -> &mut Sequencer;
|
impl $(<$($L),*$($T $(: $U)?),*>)? HasSequencer for $Struct $(<$($L),*$($T),*>)? {
|
||||||
|
fn sequencer (&$self) -> &impl MidiSequencer { &$cb }
|
||||||
|
fn sequencer_mut (&mut $self) -> &mut impl MidiSequencer { &mut$cb }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains state for playing a clip
|
/// Contains state for playing a clip
|
||||||
|
|
@ -41,8 +41,6 @@ pub struct Sequencer {
|
||||||
pub notes_out: Arc<RwLock<[bool; 128]>>,
|
pub notes_out: Arc<RwLock<[bool; 128]>>,
|
||||||
/// MIDI output buffer
|
/// MIDI output buffer
|
||||||
pub note_buf: Vec<u8>,
|
pub note_buf: Vec<u8>,
|
||||||
/// MIDI output buffer
|
|
||||||
pub midi_buf: Vec<Vec<Vec<u8>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Sequencer {
|
impl Default for Sequencer {
|
||||||
|
|
@ -57,7 +55,6 @@ impl Default for Sequencer {
|
||||||
notes_in: RwLock::new([false;128]).into(),
|
notes_in: RwLock::new([false;128]).into(),
|
||||||
notes_out: RwLock::new([false;128]).into(),
|
notes_out: RwLock::new([false;128]).into(),
|
||||||
note_buf: vec![0;8],
|
note_buf: vec![0;8],
|
||||||
midi_buf: vec![],
|
|
||||||
reset: true,
|
reset: true,
|
||||||
|
|
||||||
midi_ins: vec![],
|
midi_ins: vec![],
|
||||||
|
|
@ -83,10 +80,14 @@ impl Sequencer {
|
||||||
midi_outs: vec![JackMidiOut::new(jack, format!("{}/M", name.as_ref()), midi_to)?, ],
|
midi_outs: vec![JackMidiOut::new(jack, format!("{}/M", name.as_ref()), midi_to)?, ],
|
||||||
play_clip: clip.map(|clip|(Moment::zero(&clock.timebase), Some(clip.clone()))),
|
play_clip: clip.map(|clip|(Moment::zero(&clock.timebase), Some(clip.clone()))),
|
||||||
clock,
|
clock,
|
||||||
|
note_buf: vec![0;8],
|
||||||
reset: true,
|
reset: true,
|
||||||
|
recording: false,
|
||||||
|
monitoring: false,
|
||||||
|
overdub: false,
|
||||||
|
next_clip: None,
|
||||||
notes_in: RwLock::new([false;128]).into(),
|
notes_in: RwLock::new([false;128]).into(),
|
||||||
notes_out: RwLock::new([false;128]).into(),
|
notes_out: RwLock::new([false;128]).into(),
|
||||||
..Default::default()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,13 +102,25 @@ impl std::fmt::Debug for Sequencer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
has!(Clock: |self: Sequencer|self.clock);
|
has_clock!(|self: Sequencer|self.clock);
|
||||||
has!(Vec<JackMidiIn>: |self:Sequencer| self.midi_ins);
|
|
||||||
has!(Vec<JackMidiOut>: |self:Sequencer| self.midi_outs);
|
|
||||||
|
|
||||||
impl MidiMonitor for Sequencer {
|
impl HasMidiIns for Sequencer {
|
||||||
fn notes_in (&self) -> &Arc<RwLock<[bool; 128]>> {
|
fn midi_ins (&self) -> &Vec<JackMidiIn> { &self.midi_ins }
|
||||||
&self.notes_in
|
fn midi_ins_mut (&mut self) -> &mut Vec<JackMidiIn> { &mut self.midi_ins }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasMidiOuts for Sequencer {
|
||||||
|
fn midi_outs (&self) -> &Vec<JackMidiOut> { &self.midi_outs }
|
||||||
|
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut> { &mut self.midi_outs }
|
||||||
|
fn midi_note (&mut self) -> &mut Vec<u8> { &mut self.note_buf }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MidiRecorder for Sequencer {
|
||||||
|
fn recording (&self) -> bool {
|
||||||
|
self.recording
|
||||||
|
}
|
||||||
|
fn recording_mut (&mut self) -> &mut bool {
|
||||||
|
&mut self.recording
|
||||||
}
|
}
|
||||||
fn monitoring (&self) -> bool {
|
fn monitoring (&self) -> bool {
|
||||||
self.monitoring
|
self.monitoring
|
||||||
|
|
@ -115,21 +128,21 @@ impl MidiMonitor for Sequencer {
|
||||||
fn monitoring_mut (&mut self) -> &mut bool {
|
fn monitoring_mut (&mut self) -> &mut bool {
|
||||||
&mut self.monitoring
|
&mut self.monitoring
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl MidiRecord for Sequencer {
|
|
||||||
fn recording (&self) -> bool {
|
|
||||||
self.recording
|
|
||||||
}
|
|
||||||
fn recording_mut (&mut self) -> &mut bool {
|
|
||||||
&mut self.recording
|
|
||||||
}
|
|
||||||
fn overdub (&self) -> bool {
|
fn overdub (&self) -> bool {
|
||||||
self.overdub
|
self.overdub
|
||||||
}
|
}
|
||||||
fn overdub_mut (&mut self) -> &mut bool {
|
fn overdub_mut (&mut self) -> &mut bool {
|
||||||
&mut self.overdub
|
&mut self.overdub
|
||||||
}
|
}
|
||||||
|
fn notes_in (&self) -> &Arc<RwLock<[bool; 128]>> {
|
||||||
|
&self.notes_in
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MidiPlayer for Sequencer {
|
||||||
|
fn notes_out (&self) -> &Arc<RwLock<[bool; 128]>> {
|
||||||
|
&self.notes_out
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasPlayClip for Sequencer {
|
impl HasPlayClip for Sequencer {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ version = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tengri = { workspace = true }
|
tengri = { workspace = true }
|
||||||
tengri_proc = { workspace = true }
|
|
||||||
jack = { workspace = true }
|
jack = { workspace = true }
|
||||||
midly = { workspace = true }
|
midly = { workspace = true }
|
||||||
uuid = { workspace = true }
|
uuid = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@ use crate::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
use self::JackState::*;
|
use self::JackState::*;
|
||||||
|
|
||||||
impl<T: Has<Jack>> HasJack for T {
|
|
||||||
fn jack (&self) -> &Jack {
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Things that can provide a [jack::Client] reference.
|
/// Things that can provide a [jack::Client] reference.
|
||||||
pub trait HasJack {
|
pub trait HasJack {
|
||||||
/// Return the internal [jack::Client] handle
|
/// Return the internal [jack::Client] handle
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,94 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
macro_rules! impl_port {
|
||||||
|
($Name:ident : $Spec:ident -> $Pair:ident |$jack:ident, $name:ident|$port:expr) => {
|
||||||
|
#[derive(Debug)] pub struct $Name {
|
||||||
|
/// Handle to JACK client, for receiving reconnect events.
|
||||||
|
jack: Jack,
|
||||||
|
/// Port name
|
||||||
|
name: Arc<str>,
|
||||||
|
/// Port handle.
|
||||||
|
port: Port<$Spec>,
|
||||||
|
/// List of ports to connect to.
|
||||||
|
conn: Vec<PortConnect>
|
||||||
|
}
|
||||||
|
impl AsRef<Port<$Spec>> for $Name { fn as_ref (&self) -> &Port<$Spec> { &self.port } }
|
||||||
|
impl $Name {
|
||||||
|
pub fn new ($jack: &Jack, name: impl AsRef<str>, connect: &[PortConnect])
|
||||||
|
-> Usually<Self>
|
||||||
|
{
|
||||||
|
let $name = name.as_ref();
|
||||||
|
let jack = $jack.clone();
|
||||||
|
let port = $port?;
|
||||||
|
let name = $name.into();
|
||||||
|
let conn = connect.to_vec();
|
||||||
|
let port = Self { jack, port, name, conn };
|
||||||
|
port.connect_to_matching()?;
|
||||||
|
Ok(port)
|
||||||
|
}
|
||||||
|
pub fn name (&self) -> &Arc<str> { &self.name }
|
||||||
|
pub fn port (&self) -> &Port<$Spec> { &self.port }
|
||||||
|
pub fn port_mut (&mut self) -> &mut Port<$Spec> { &mut self.port }
|
||||||
|
pub fn into_port (self) -> Port<$Spec> { self.port }
|
||||||
|
pub fn close (self) -> Usually<()> {
|
||||||
|
let Self { jack, port, .. } = self;
|
||||||
|
Ok(jack.with_client(|client|client.unregister_port(port))?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl HasJack for $Name { fn jack (&self) -> &Jack { &self.jack } }
|
||||||
|
impl JackPort for $Name {
|
||||||
|
type Port = $Spec;
|
||||||
|
type Pair = $Pair;
|
||||||
|
fn port (&self) -> &Port<$Spec> { &self.port }
|
||||||
|
}
|
||||||
|
impl JackPortConnect<&str> for $Name {
|
||||||
|
fn connect_to (&self, to: &str) -> Usually<PortConnectStatus> {
|
||||||
|
self.with_client(|c|if let Some(ref port) = c.port_by_name(to.as_ref()) {
|
||||||
|
self.connect_to(port)
|
||||||
|
} else {
|
||||||
|
Ok(Missing)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl JackPortConnect<&Port<Unowned>> for $Name {
|
||||||
|
fn connect_to (&self, port: &Port<Unowned>) -> Usually<PortConnectStatus> {
|
||||||
|
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
||||||
|
Connected
|
||||||
|
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
||||||
|
Connected
|
||||||
|
} else {
|
||||||
|
Mismatch
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl JackPortConnect<&Port<$Pair>> for $Name {
|
||||||
|
fn connect_to (&self, port: &Port<$Pair>) -> Usually<PortConnectStatus> {
|
||||||
|
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
||||||
|
Connected
|
||||||
|
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
||||||
|
Connected
|
||||||
|
} else {
|
||||||
|
Mismatch
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl JackPortAutoconnect for $Name {
|
||||||
|
fn conn (&self) -> &[PortConnect] {
|
||||||
|
&self.conn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_port!(JackAudioIn: AudioIn -> AudioOut |j, n|j.register_port::<AudioIn>(n));
|
||||||
|
|
||||||
|
impl_port!(JackAudioOut: AudioOut -> AudioIn |j, n|j.register_port::<AudioOut>(n));
|
||||||
|
|
||||||
|
impl_port!(JackMidiIn: MidiIn -> MidiOut |j, n|j.register_port::<MidiIn>(n));
|
||||||
|
|
||||||
|
impl_port!(JackMidiOut: MidiOut -> MidiIn |j, n|j.register_port::<MidiOut>(n));
|
||||||
|
|
||||||
pub trait JackPort: HasJack {
|
pub trait JackPort: HasJack {
|
||||||
type Port: PortSpec;
|
type Port: PortSpec;
|
||||||
type Pair: PortSpec;
|
type Pair: PortSpec;
|
||||||
|
|
@ -147,89 +235,3 @@ impl PortConnect {
|
||||||
format!(" ({}) {} {}", status, scope, name).into()
|
format!(" ({}) {} {}", status, scope, name).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_port {
|
|
||||||
($Name:ident : $Spec:ident -> $Pair:ident |$jack:ident, $name:ident|$port:expr) => {
|
|
||||||
#[derive(Debug)] pub struct $Name {
|
|
||||||
/// Handle to JACK client, for receiving reconnect events.
|
|
||||||
jack: Jack,
|
|
||||||
/// Port name
|
|
||||||
name: Arc<str>,
|
|
||||||
/// Port handle.
|
|
||||||
port: Port<$Spec>,
|
|
||||||
/// List of ports to connect to.
|
|
||||||
conn: Vec<PortConnect>
|
|
||||||
}
|
|
||||||
impl AsRef<Port<$Spec>> for $Name { fn as_ref (&self) -> &Port<$Spec> { &self.port } }
|
|
||||||
impl $Name {
|
|
||||||
pub fn new ($jack: &Jack, name: impl AsRef<str>, connect: &[PortConnect])
|
|
||||||
-> Usually<Self>
|
|
||||||
{
|
|
||||||
let $name = name.as_ref();
|
|
||||||
let jack = $jack.clone();
|
|
||||||
let port = $port?;
|
|
||||||
let name = $name.into();
|
|
||||||
let conn = connect.to_vec();
|
|
||||||
let port = Self { jack, port, name, conn };
|
|
||||||
port.connect_to_matching()?;
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
pub fn name (&self) -> &Arc<str> { &self.name }
|
|
||||||
pub fn port (&self) -> &Port<$Spec> { &self.port }
|
|
||||||
pub fn port_mut (&mut self) -> &mut Port<$Spec> { &mut self.port }
|
|
||||||
pub fn into_port (self) -> Port<$Spec> { self.port }
|
|
||||||
pub fn close (self) -> Usually<()> {
|
|
||||||
let Self { jack, port, .. } = self;
|
|
||||||
Ok(jack.with_client(|client|client.unregister_port(port))?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl HasJack for $Name { fn jack (&self) -> &Jack { &self.jack } }
|
|
||||||
impl JackPort for $Name {
|
|
||||||
type Port = $Spec;
|
|
||||||
type Pair = $Pair;
|
|
||||||
fn port (&self) -> &Port<$Spec> { &self.port }
|
|
||||||
}
|
|
||||||
impl JackPortConnect<&str> for $Name {
|
|
||||||
fn connect_to (&self, to: &str) -> Usually<PortConnectStatus> {
|
|
||||||
self.with_client(|c|if let Some(ref port) = c.port_by_name(to.as_ref()) {
|
|
||||||
self.connect_to(port)
|
|
||||||
} else {
|
|
||||||
Ok(Missing)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl JackPortConnect<&Port<Unowned>> for $Name {
|
|
||||||
fn connect_to (&self, port: &Port<Unowned>) -> Usually<PortConnectStatus> {
|
|
||||||
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
|
||||||
Connected
|
|
||||||
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
|
||||||
Connected
|
|
||||||
} else {
|
|
||||||
Mismatch
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl JackPortConnect<&Port<$Pair>> for $Name {
|
|
||||||
fn connect_to (&self, port: &Port<$Pair>) -> Usually<PortConnectStatus> {
|
|
||||||
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
|
||||||
Connected
|
|
||||||
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
|
||||||
Connected
|
|
||||||
} else {
|
|
||||||
Mismatch
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl JackPortAutoconnect for $Name {
|
|
||||||
fn conn (&self) -> &[PortConnect] {
|
|
||||||
&self.conn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_port!(JackAudioIn: AudioIn -> AudioOut |j, n|j.register_port::<AudioIn>(n));
|
|
||||||
|
|
||||||
impl_port!(JackAudioOut: AudioOut -> AudioIn |j, n|j.register_port::<AudioOut>(n));
|
|
||||||
|
|
||||||
impl_port!(JackMidiIn: MidiIn -> MidiOut |j, n|j.register_port::<MidiIn>(n));
|
|
||||||
|
|
|
||||||
|
|
@ -9,42 +9,10 @@ pub(crate) use std::sync::{Arc, atomic::{AtomicUsize, AtomicBool, Ordering::Rela
|
||||||
pub(crate) use std::fmt::Debug;
|
pub(crate) use std::fmt::Debug;
|
||||||
pub(crate) use std::ops::{Add, Sub, Mul, Div, Rem};
|
pub(crate) use std::ops::{Add, Sub, Mul, Div, Rem};
|
||||||
|
|
||||||
pub(crate) use ::tengri::{from, Usually, Perhaps, Has, tui::*};
|
pub(crate) use ::tengri::{Usually, tui::*};
|
||||||
|
|
||||||
pub use ::atomic_float; pub(crate) use atomic_float::*;
|
pub use ::atomic_float; pub(crate) use atomic_float::*;
|
||||||
|
|
||||||
//pub trait MaybeHas<T>: Send + Sync {
|
|
||||||
//fn get (&self) -> Option<&T>;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//impl<T, U: Has<Option<T>>> MaybeHas<T> for U {
|
|
||||||
//fn get (&self) -> Option<&T> {
|
|
||||||
//Has::<Option<T>>::get(self).as_ref()
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
|
|
||||||
#[macro_export] macro_rules! has {
|
|
||||||
($T:ty: |$self:ident : $S:ty| $x:expr) => {
|
|
||||||
impl Has<$T> for $S {
|
|
||||||
fn get (&$self) -> &$T { &$x }
|
|
||||||
fn get_mut (&mut $self) -> &mut $T { &mut $x }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export] macro_rules! as_ref {
|
|
||||||
($T:ty: |$self:ident : $S:ty| $x:expr) => {
|
|
||||||
impl AsRef<$T> for $S {
|
|
||||||
fn as_ref (&$self) -> &$T { &$x }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait HasN<T>: Send + Sync {
|
|
||||||
fn get_nth (&self, key: usize) -> &T;
|
|
||||||
fn get_nth_mut (&mut self, key: usize) -> &mut T;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Gettable<T> {
|
pub trait Gettable<T> {
|
||||||
/// Returns current value
|
/// Returns current value
|
||||||
fn get (&self) -> T;
|
fn get (&self) -> T;
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,14 @@ pub use ::midly::{
|
||||||
live::*,
|
live::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod midi_in; pub use self::midi_in::*;
|
/// Update notes_in array
|
||||||
mod midi_out; pub use self::midi_out::*;
|
pub fn update_keys (keys: &mut[bool;128], message: &MidiMessage) {
|
||||||
mod midi_hold; pub use self::midi_hold::*;
|
match message {
|
||||||
|
MidiMessage::NoteOn { key, .. } => { keys[key.as_int() as usize] = true; }
|
||||||
|
MidiMessage::NoteOff { key, .. } => { keys[key.as_int() as usize] = false; },
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return boxed iterator of MIDI events
|
/// Return boxed iterator of MIDI events
|
||||||
pub fn parse_midi_input <'a> (input: ::jack::MidiIter<'a>) -> Box<dyn Iterator<Item=(usize, LiveEvent<'a>, &'a [u8])> + 'a> {
|
pub fn parse_midi_input <'a> (input: ::jack::MidiIter<'a>) -> Box<dyn Iterator<Item=(usize, LiveEvent<'a>, &'a [u8])> + 'a> {
|
||||||
|
|
@ -30,3 +35,28 @@ pub fn all_notes_off (output: &mut [Vec<Vec<u8>>]) {
|
||||||
evt.write(&mut buf).unwrap();
|
evt.write(&mut buf).unwrap();
|
||||||
output[0].push(buf);
|
output[0].push(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trait for thing that may receive MIDI.
|
||||||
|
pub trait HasMidiIns {
|
||||||
|
fn midi_ins (&self) -> &Vec<JackMidiIn>;
|
||||||
|
|
||||||
|
fn midi_ins_mut (&mut self) -> &mut Vec<JackMidiIn>;
|
||||||
|
|
||||||
|
fn has_midi_ins (&self) -> bool {
|
||||||
|
!self.midi_ins().is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Trait for thing that may output MIDI.
|
||||||
|
pub trait HasMidiOuts {
|
||||||
|
fn midi_outs (&self) -> &Vec<JackMidiOut>;
|
||||||
|
|
||||||
|
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut>;
|
||||||
|
|
||||||
|
fn has_midi_outs (&self) -> bool {
|
||||||
|
!self.midi_outs().is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Buffer for serializing a MIDI event. FIXME rename
|
||||||
|
fn midi_note (&mut self) -> &mut Vec<u8>;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
/// Update notes_in array
|
|
||||||
pub fn update_keys (keys: &mut[bool;128], message: &MidiMessage) {
|
|
||||||
match message {
|
|
||||||
MidiMessage::NoteOn { key, .. } => { keys[key.as_int() as usize] = true; }
|
|
||||||
MidiMessage::NoteOff { key, .. } => { keys[key.as_int() as usize] = false; },
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl JackMidiIn {
|
|
||||||
pub fn parsed <'a> (&'a self, scope: &'a ProcessScope) -> impl Iterator<Item=(usize, LiveEvent<'a>, &'a [u8])> {
|
|
||||||
parse_midi_input(self.port().iter(scope))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::command(JackMidiIn)]
|
|
||||||
impl MidiInputCommand {
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Has<Vec<JackMidiIn>>> HasMidiIns for T {
|
|
||||||
fn midi_ins (&self) -> &Vec<JackMidiIn> {
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
fn midi_ins_mut (&mut self) -> &mut Vec<JackMidiIn> {
|
|
||||||
self.get_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trait for thing that may receive MIDI.
|
|
||||||
pub trait HasMidiIns {
|
|
||||||
fn midi_ins (&self) -> &Vec<JackMidiIn>;
|
|
||||||
fn midi_ins_mut (&mut self) -> &mut Vec<JackMidiIn>;
|
|
||||||
/// Collect MIDI input from app ports (TODO preallocate large buffers)
|
|
||||||
fn midi_input_collect <'a> (&'a self, scope: &'a ProcessScope) -> CollectedMidiInput<'a> {
|
|
||||||
self.midi_ins().iter()
|
|
||||||
.map(|port|port.port().iter(scope)
|
|
||||||
.map(|RawMidi { time, bytes }|(time, LiveEvent::parse(bytes)))
|
|
||||||
.collect::<Vec<_>>())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
fn midi_ins_with_sizes <'a> (&'a self) ->
|
|
||||||
impl Iterator<Item=(usize, &Arc<str>, &[PortConnect], usize, usize)> + Send + Sync + 'a
|
|
||||||
{
|
|
||||||
let mut y = 0;
|
|
||||||
self.midi_ins().iter().enumerate().map(move|(i, input)|{
|
|
||||||
let height = 1 + input.conn().len();
|
|
||||||
let data = (i, input.name(), input.conn(), y, y + height);
|
|
||||||
y += height;
|
|
||||||
data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type CollectedMidiInput<'a> = Vec<Vec<(u32, Result<LiveEvent<'a>, MidiError>)>>;
|
|
||||||
|
|
||||||
impl<T: HasMidiIns + HasJack> AddMidiIn for T {
|
|
||||||
fn midi_in_add (&mut self) -> Usually<()> {
|
|
||||||
let index = self.midi_ins().len();
|
|
||||||
let port = JackMidiIn::new(self.jack(), &format!("M/{index}"), &[])?;
|
|
||||||
self.midi_ins_mut().push(port);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// May create new MIDI input ports.
|
|
||||||
pub trait AddMidiIn {
|
|
||||||
fn midi_in_add (&mut self) -> Usually<()>;
|
|
||||||
}
|
|
||||||
|
|
@ -1,198 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
#[derive(Debug)] pub struct JackMidiOut {
|
|
||||||
/// Handle to JACK client, for receiving reconnect events.
|
|
||||||
jack: Jack,
|
|
||||||
/// Port name
|
|
||||||
name: Arc<str>,
|
|
||||||
/// Port handle.
|
|
||||||
port: Port<MidiOut>,
|
|
||||||
/// List of ports to connect to.
|
|
||||||
conn: Vec<PortConnect>,
|
|
||||||
/// List of currently held notes.
|
|
||||||
held: Arc<RwLock<[bool;128]>>,
|
|
||||||
/// Buffer
|
|
||||||
note_buffer: Vec<u8>,
|
|
||||||
/// Buffer
|
|
||||||
output_buffer: Vec<Vec<Vec<u8>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
has!(Jack: |self: JackMidiOut|self.jack);
|
|
||||||
|
|
||||||
impl JackMidiOut {
|
|
||||||
pub fn new (jack: &Jack, name: impl AsRef<str>, connect: &[PortConnect])
|
|
||||||
-> Usually<Self>
|
|
||||||
{
|
|
||||||
let jack = jack.clone();
|
|
||||||
let port = jack.register_port::<MidiOut>(name.as_ref())?;
|
|
||||||
let name = name.as_ref().into();
|
|
||||||
let conn = connect.to_vec();
|
|
||||||
let port = Self {
|
|
||||||
jack,
|
|
||||||
port,
|
|
||||||
name,
|
|
||||||
conn,
|
|
||||||
held: Arc::new([false;128].into()),
|
|
||||||
note_buffer: vec![0;8],
|
|
||||||
output_buffer: vec![vec![];65536],
|
|
||||||
};
|
|
||||||
port.connect_to_matching()?;
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
pub fn name (&self) -> &Arc<str> {
|
|
||||||
&self.name
|
|
||||||
}
|
|
||||||
pub fn port (&self) -> &Port<MidiOut> {
|
|
||||||
&self.port
|
|
||||||
}
|
|
||||||
pub fn port_mut (&mut self) -> &mut Port<MidiOut> {
|
|
||||||
&mut self.port
|
|
||||||
}
|
|
||||||
pub fn into_port (self) -> Port<MidiOut> {
|
|
||||||
self.port
|
|
||||||
}
|
|
||||||
pub fn close (self) -> Usually<()> {
|
|
||||||
let Self { jack, port, .. } = self;
|
|
||||||
Ok(jack.with_client(|client|client.unregister_port(port))?)
|
|
||||||
}
|
|
||||||
/// Clear the section of the output buffer that we will be using,
|
|
||||||
/// emitting "all notes off" at start of buffer if requested.
|
|
||||||
pub fn buffer_clear (&mut self, scope: &ProcessScope, reset: bool) {
|
|
||||||
let n_frames = (scope.n_frames() as usize).min(self.output_buffer.len());
|
|
||||||
for frame in &mut self.output_buffer[0..n_frames] {
|
|
||||||
frame.clear();
|
|
||||||
}
|
|
||||||
if reset {
|
|
||||||
all_notes_off(&mut self.output_buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Write a note to the output buffer
|
|
||||||
pub fn buffer_write <'a> (
|
|
||||||
&'a mut self,
|
|
||||||
sample: usize,
|
|
||||||
event: LiveEvent,
|
|
||||||
) {
|
|
||||||
self.note_buffer.fill(0);
|
|
||||||
event.write(&mut self.note_buffer).expect("failed to serialize MIDI event");
|
|
||||||
self.output_buffer[sample].push(self.note_buffer.clone());
|
|
||||||
// Update the list of currently held notes.
|
|
||||||
if let LiveEvent::Midi { ref message, .. } = event {
|
|
||||||
update_keys(&mut*self.held.write().unwrap(), message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Write a chunk of MIDI data from the output buffer to the output port.
|
|
||||||
pub fn buffer_emit (&mut self, scope: &ProcessScope) {
|
|
||||||
let samples = scope.n_frames() as usize;
|
|
||||||
let mut writer = self.port.writer(scope);
|
|
||||||
for (time, events) in self.output_buffer.iter().enumerate().take(samples) {
|
|
||||||
for bytes in events.iter() {
|
|
||||||
writer.write(&RawMidi { time: time as u32, bytes }).unwrap_or_else(|_|{
|
|
||||||
panic!("Failed to write MIDI data: {bytes:?}");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<Port<MidiOut>> for JackMidiOut {
|
|
||||||
fn as_ref (&self) -> &Port<MidiOut> {
|
|
||||||
&self.port
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JackPort for JackMidiOut {
|
|
||||||
type Port = MidiOut;
|
|
||||||
type Pair = MidiIn;
|
|
||||||
fn port (&self) -> &Port<MidiOut> { &self.port }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JackPortConnect<&str> for JackMidiOut {
|
|
||||||
fn connect_to (&self, to: &str) -> Usually<PortConnectStatus> {
|
|
||||||
self.with_client(|c|if let Some(ref port) = c.port_by_name(to.as_ref()) {
|
|
||||||
self.connect_to(port)
|
|
||||||
} else {
|
|
||||||
Ok(Missing)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JackPortConnect<&Port<Unowned>> for JackMidiOut {
|
|
||||||
fn connect_to (&self, port: &Port<Unowned>) -> Usually<PortConnectStatus> {
|
|
||||||
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
|
||||||
Connected
|
|
||||||
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
|
||||||
Connected
|
|
||||||
} else {
|
|
||||||
Mismatch
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JackPortConnect<&Port<MidiIn>> for JackMidiOut {
|
|
||||||
fn connect_to (&self, port: &Port<MidiIn>) -> Usually<PortConnectStatus> {
|
|
||||||
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
|
||||||
Connected
|
|
||||||
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
|
||||||
Connected
|
|
||||||
} else {
|
|
||||||
Mismatch
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JackPortAutoconnect for JackMidiOut {
|
|
||||||
fn conn (&self) -> &[PortConnect] {
|
|
||||||
&self.conn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri_proc::command(JackMidiOut)]
|
|
||||||
impl MidiOutputCommand {
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Has<Vec<JackMidiOut>>> HasMidiOuts for T {
|
|
||||||
fn midi_outs (&self) -> &Vec<JackMidiOut> {
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut> {
|
|
||||||
self.get_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Trait for thing that may output MIDI.
|
|
||||||
pub trait HasMidiOuts {
|
|
||||||
fn midi_outs (&self) -> &Vec<JackMidiOut>;
|
|
||||||
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut>;
|
|
||||||
fn midi_outs_with_sizes <'a> (&'a self) ->
|
|
||||||
impl Iterator<Item=(usize, &Arc<str>, &[PortConnect], usize, usize)> + Send + Sync + 'a
|
|
||||||
{
|
|
||||||
let mut y = 0;
|
|
||||||
self.midi_outs().iter().enumerate().map(move|(i, output)|{
|
|
||||||
let height = 1 + output.conn().len();
|
|
||||||
let data = (i, output.name(), output.conn(), y, y + height);
|
|
||||||
y += height;
|
|
||||||
data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
fn midi_outs_emit (&mut self, scope: &ProcessScope) {
|
|
||||||
for port in self.midi_outs_mut().iter_mut() {
|
|
||||||
port.buffer_emit(scope)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trail for thing that may gain new MIDI ports.
|
|
||||||
impl<T: HasMidiOuts + HasJack> AddMidiOut for T {
|
|
||||||
fn midi_out_add (&mut self) -> Usually<()> {
|
|
||||||
let index = self.midi_outs().len();
|
|
||||||
let port = JackMidiOut::new(self.jack(), &format!("{index}/M"), &[])?;
|
|
||||||
self.midi_outs_mut().push(port);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// May create new MIDI output ports.
|
|
||||||
pub trait AddMidiOut {
|
|
||||||
fn midi_out_add (&mut self) -> Usually<()>;
|
|
||||||
}
|
|
||||||
2
deps/tengri
vendored
2
deps/tengri
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8bfd1a23a1f880a1d2fb104a158fc51f244acd6e
|
Subproject commit b45ac8f417b2f4e83e116a9ee5fe4bf3ad57a726
|
||||||
Loading…
Add table
Add a link
Reference in a new issue