mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: cleanup old code
This commit is contained in:
parent
0d7f78e74f
commit
5d3e564949
10 changed files with 1464 additions and 1512 deletions
|
|
@ -22,7 +22,7 @@ pub trait HasClips {
|
|||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct PoolModel {
|
||||
pub struct MidiPool {
|
||||
pub visible: bool,
|
||||
/// Collection of clips
|
||||
pub clips: Arc<RwLock<Vec<Arc<RwLock<MidiClip>>>>>,
|
||||
|
|
@ -43,7 +43,7 @@ pub enum PoolMode {
|
|||
/// Save clip to disk
|
||||
Export(usize, FileBrowser),
|
||||
}
|
||||
impl Default for PoolModel {
|
||||
impl Default for MidiPool {
|
||||
fn default () -> Self {
|
||||
Self {
|
||||
visible: true,
|
||||
|
|
@ -53,15 +53,15 @@ impl Default for PoolModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
from!(|clip:&Arc<RwLock<MidiClip>>|PoolModel = {
|
||||
from!(|clip:&Arc<RwLock<MidiClip>>|MidiPool = {
|
||||
let model = Self::default();
|
||||
model.clips.write().unwrap().push(clip.clone());
|
||||
model.clip.store(1, Relaxed);
|
||||
model
|
||||
});
|
||||
has_clips!(|self: PoolModel|self.clips);
|
||||
has_clip!(|self: PoolModel|self.clips().get(self.clip_index()).map(|c|c.clone()));
|
||||
impl PoolModel {
|
||||
has_clips!(|self: MidiPool|self.clips);
|
||||
has_clip!(|self: MidiPool|self.clips().get(self.clip_index()).map(|c|c.clone()));
|
||||
impl MidiPool {
|
||||
pub(crate) fn clip_index (&self) -> usize {
|
||||
self.clip.load(Relaxed)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ pub enum PoolCommand {
|
|||
/// Export to file
|
||||
Export(FileBrowserCommand),
|
||||
}
|
||||
impl EdnCommand<PoolModel> for PoolCommand {
|
||||
fn from_edn <'a> (state: &PoolModel, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
impl EdnCommand<MidiPool> for PoolCommand {
|
||||
fn from_edn <'a> (state: &MidiPool, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ impl<T: HasClips> Command<T> for PoolClipCommand {
|
|||
})
|
||||
}
|
||||
}
|
||||
command!(|self:PoolCommand, state: PoolModel|{
|
||||
command!(|self:PoolCommand, state: MidiPool|{
|
||||
use PoolCommand::*;
|
||||
match self {
|
||||
Show(visible) => {
|
||||
|
|
@ -153,14 +153,14 @@ command!(|self:PoolCommand, state: PoolModel|{
|
|||
Clip(command) => command.execute(state)?.map(Clip),
|
||||
}
|
||||
});
|
||||
input_to_command!(PoolCommand: |state: PoolModel, input: Event|match state.clips_mode() {
|
||||
input_to_command!(PoolCommand: |state: MidiPool, input: Event|match state.clips_mode() {
|
||||
Some(PoolMode::Rename(..)) => Self::Rename(ClipRenameCommand::input_to_command(state, input)?),
|
||||
Some(PoolMode::Length(..)) => Self::Length(ClipLengthCommand::input_to_command(state, input)?),
|
||||
Some(PoolMode::Import(..)) => Self::Import(FileBrowserCommand::input_to_command(state, input)?),
|
||||
Some(PoolMode::Export(..)) => Self::Export(FileBrowserCommand::input_to_command(state, input)?),
|
||||
_ => to_clips_command(state, input)?
|
||||
});
|
||||
fn to_clips_command (state: &PoolModel, input: &Event) -> Option<PoolCommand> {
|
||||
fn to_clips_command (state: &MidiPool, input: &Event) -> Option<PoolCommand> {
|
||||
use KeyCode::{Up, Down, Delete, Char};
|
||||
use PoolCommand as Cmd;
|
||||
let index = state.clip_index();
|
||||
|
|
@ -209,7 +209,7 @@ fn to_clips_command (state: &PoolModel, input: &Event) -> Option<PoolCommand> {
|
|||
_ => return None
|
||||
})
|
||||
}
|
||||
command!(|self: FileBrowserCommand, state: PoolModel|{
|
||||
command!(|self: FileBrowserCommand, state: MidiPool|{
|
||||
use PoolMode::*;
|
||||
use FileBrowserCommand::*;
|
||||
let mode = &mut state.mode;
|
||||
|
|
@ -238,7 +238,7 @@ command!(|self: FileBrowserCommand, state: PoolModel|{
|
|||
};
|
||||
None
|
||||
});
|
||||
input_to_command!(FileBrowserCommand: |state: PoolModel, input: Event|{
|
||||
input_to_command!(FileBrowserCommand: |state: MidiPool, input: Event|{
|
||||
use FileBrowserCommand::*;
|
||||
use KeyCode::{Up, Down, Left, Right, Enter, Esc, Backspace, Char};
|
||||
if let Some(PoolMode::Import(_index, browser)) = &state.mode {
|
||||
|
|
@ -283,7 +283,7 @@ pub enum ClipLengthCommand {
|
|||
Inc,
|
||||
Dec,
|
||||
}
|
||||
command!(|self: ClipLengthCommand,state:PoolModel|{
|
||||
command!(|self: ClipLengthCommand,state:MidiPool|{
|
||||
use ClipLengthCommand::*;
|
||||
use ClipLengthFocus::*;
|
||||
match state.clips_mode_mut().clone() {
|
||||
|
|
@ -317,7 +317,7 @@ command!(|self: ClipLengthCommand,state:PoolModel|{
|
|||
};
|
||||
None
|
||||
});
|
||||
input_to_command!(ClipLengthCommand: |state: PoolModel, input: Event|{
|
||||
input_to_command!(ClipLengthCommand: |state: MidiPool, input: Event|{
|
||||
if let Some(PoolMode::Length(_, length, _)) = state.clips_mode() {
|
||||
match input {
|
||||
kpat!(Up) => Self::Inc,
|
||||
|
|
@ -332,8 +332,8 @@ input_to_command!(ClipLengthCommand: |state: PoolModel, input: Event|{
|
|||
unreachable!()
|
||||
}
|
||||
});
|
||||
impl InputToCommand<Event, PoolModel> for ClipRenameCommand {
|
||||
fn input_to_command (state: &PoolModel, input: &Event) -> Option<Self> {
|
||||
impl InputToCommand<Event, MidiPool> for ClipRenameCommand {
|
||||
fn input_to_command (state: &MidiPool, input: &Event) -> Option<Self> {
|
||||
use KeyCode::{Char, Backspace, Enter, Esc};
|
||||
if let Some(PoolMode::Rename(_, ref old_name)) = state.clips_mode() {
|
||||
Some(match input {
|
||||
|
|
@ -363,8 +363,8 @@ pub enum ClipRenameCommand {
|
|||
Confirm,
|
||||
Set(Arc<str>),
|
||||
}
|
||||
impl Command<PoolModel> for ClipRenameCommand {
|
||||
fn execute (self, state: &mut PoolModel) -> Perhaps<Self> {
|
||||
impl Command<MidiPool> for ClipRenameCommand {
|
||||
fn execute (self, state: &mut MidiPool) -> Perhaps<Self> {
|
||||
use ClipRenameCommand::*;
|
||||
match state.clips_mode_mut().clone() {
|
||||
Some(PoolMode::Rename(clip, ref mut old_name)) => match self {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::*;
|
||||
pub struct PoolView<'a>(pub bool, pub &'a PoolModel);
|
||||
pub struct PoolView<'a>(pub bool, pub &'a MidiPool);
|
||||
render!(TuiOut: (self: PoolView<'a>) => {
|
||||
let Self(compact, model) = self;
|
||||
let PoolModel { clips, mode, .. } = self.1;
|
||||
let MidiPool { clips, mode, .. } = self.1;
|
||||
let color = self.1.clip().map(|c|c.read().unwrap().color).unwrap_or_else(||TuiTheme::g(32).into());
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue