mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
mostly formatting
This commit is contained in:
parent
f1f3a7de10
commit
26eb5f0315
2 changed files with 51 additions and 55 deletions
|
|
@ -20,8 +20,9 @@ pub enum PhrasePoolCommand {
|
||||||
|
|
||||||
impl<T: HasPhrases> Command<T> for PhrasePoolCommand {
|
impl<T: HasPhrases> Command<T> for PhrasePoolCommand {
|
||||||
fn execute (self, model: &mut T) -> Perhaps<Self> {
|
fn execute (self, model: &mut T) -> Perhaps<Self> {
|
||||||
match self {
|
use PhrasePoolCommand::*;
|
||||||
Self::Add(mut index, phrase) => {
|
Ok(match self {
|
||||||
|
Add(mut index, phrase) => {
|
||||||
let phrase = Arc::new(RwLock::new(phrase));
|
let phrase = Arc::new(RwLock::new(phrase));
|
||||||
let phrases = model.phrases_mut();
|
let phrases = model.phrases_mut();
|
||||||
if index >= phrases.len() {
|
if index >= phrases.len() {
|
||||||
|
|
@ -30,24 +31,23 @@ impl<T: HasPhrases> Command<T> for PhrasePoolCommand {
|
||||||
} else {
|
} else {
|
||||||
phrases.insert(index, phrase);
|
phrases.insert(index, phrase);
|
||||||
}
|
}
|
||||||
return Ok(Some(Self::Delete(index)))
|
Some(Self::Delete(index))
|
||||||
},
|
},
|
||||||
Self::Delete(index) => {
|
Delete(index) => {
|
||||||
let phrase = model.phrases_mut().remove(index);
|
let phrase = model.phrases_mut().remove(index).read().unwrap().clone();
|
||||||
//view.phrase = view.phrase.min(view.model.phrases.len().saturating_sub(1));
|
Some(Self::Add(index, phrase))
|
||||||
},
|
},
|
||||||
Self::Swap(index, other) => {
|
Swap(index, other) => {
|
||||||
model.phrases_mut().swap(index, other);
|
model.phrases_mut().swap(index, other);
|
||||||
return Ok(Some(Self::Swap(index, other)))
|
Some(Self::Swap(index, other))
|
||||||
},
|
},
|
||||||
Self::Import(index, path) => {
|
Import(index, path) => {
|
||||||
let bytes = std::fs::read(&path)?;
|
let bytes = std::fs::read(&path)?;
|
||||||
let smf = Smf::parse(bytes.as_slice())?;
|
let smf = Smf::parse(bytes.as_slice())?;
|
||||||
println!("{:?}", &smf.header);
|
|
||||||
let mut t = 0u32;
|
let mut t = 0u32;
|
||||||
let mut events = vec![];
|
let mut events = vec![];
|
||||||
for (i, track) in smf.tracks.iter().enumerate() {
|
for track in smf.tracks.iter() {
|
||||||
for (j, event) in track.iter().enumerate() {
|
for event in track.iter() {
|
||||||
t += event.delta.as_int();
|
t += event.delta.as_int();
|
||||||
if let TrackEventKind::Midi { channel, message } = event.kind {
|
if let TrackEventKind::Midi { channel, message } = event.kind {
|
||||||
events.push((t, channel.as_int(), message));
|
events.push((t, channel.as_int(), message));
|
||||||
|
|
@ -56,24 +56,31 @@ impl<T: HasPhrases> Command<T> for PhrasePoolCommand {
|
||||||
}
|
}
|
||||||
let mut phrase = Phrase::new(&path, true, t as usize + 1, None, None);
|
let mut phrase = Phrase::new(&path, true, t as usize + 1, None, None);
|
||||||
for event in events.iter() {
|
for event in events.iter() {
|
||||||
println!("{event:?}");
|
|
||||||
phrase.notes[event.0 as usize].push(event.2);
|
phrase.notes[event.0 as usize].push(event.2);
|
||||||
}
|
}
|
||||||
return Self::Add(index, phrase).execute(model)
|
Self::Add(index, phrase).execute(model)?
|
||||||
},
|
},
|
||||||
Self::Export(index, path) => {
|
Export(_index, _path) => {
|
||||||
|
todo!("export phrase to midi file");
|
||||||
},
|
},
|
||||||
Self::SetName(index, name) => {
|
SetName(index, name) => {
|
||||||
|
let mut phrase = model.phrases()[index].write().unwrap();
|
||||||
|
let old_name = phrase.name.clone();
|
||||||
|
phrase.name = name;
|
||||||
|
Some(Self::SetName(index, old_name))
|
||||||
},
|
},
|
||||||
Self::SetLength(index, length) => {
|
SetLength(index, length) => {
|
||||||
|
let mut phrase = model.phrases()[index].write().unwrap();
|
||||||
|
let old_len = phrase.length;
|
||||||
|
phrase.length = length;
|
||||||
|
Some(Self::SetLength(index, old_len))
|
||||||
},
|
},
|
||||||
Self::SetColor(index, color) => {
|
SetColor(index, color) => {
|
||||||
let mut color = ItemColorTriplet::from(color);
|
let mut color = ItemColorTriplet::from(color);
|
||||||
std::mem::swap(&mut color, &mut model.phrases()[index].write().unwrap().color);
|
std::mem::swap(&mut color, &mut model.phrases()[index].write().unwrap().color);
|
||||||
return Ok(Some(Self::SetColor(index, color.base)))
|
Some(Self::SetColor(index, color.base))
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
Ok(None)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,15 +69,15 @@ impl Command<ArrangerTui> for ArrangerCommand {
|
||||||
fn execute (self, state: &mut ArrangerTui) -> Perhaps<Self> {
|
fn execute (self, state: &mut ArrangerTui) -> Perhaps<Self> {
|
||||||
use ArrangerCommand::*;
|
use ArrangerCommand::*;
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
Focus(cmd) => cmd.execute(state)?.map(Focus),
|
Focus(cmd) => cmd.execute(state)?.map(Focus),
|
||||||
Scene(cmd) => cmd.execute(state)?.map(Scene),
|
Scene(cmd) => cmd.execute(state)?.map(Scene),
|
||||||
Track(cmd) => cmd.execute(state)?.map(Track),
|
Track(cmd) => cmd.execute(state)?.map(Track),
|
||||||
Clip(cmd) => cmd.execute(state)?.map(Clip),
|
Clip(cmd) => cmd.execute(state)?.map(Clip),
|
||||||
Phrases(cmd) => cmd.execute(state)?.map(Phrases),
|
Phrases(cmd) => cmd.execute(state)?.map(Phrases),
|
||||||
Editor(cmd) => cmd.execute(state)?.map(Editor),
|
Editor(cmd) => cmd.execute(state)?.map(Editor),
|
||||||
Clock(cmd) => cmd.execute(state)?.map(Clock),
|
Clock(cmd) => cmd.execute(state)?.map(Clock),
|
||||||
Zoom(zoom) => { todo!(); },
|
Zoom(zoom) => { todo!(); },
|
||||||
Select(selected) => {
|
Select(selected) => {
|
||||||
*state.selected_mut() = selected;
|
*state.selected_mut() = selected;
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
|
@ -121,11 +121,12 @@ pub enum PhrasesCommand {
|
||||||
|
|
||||||
impl<T: PhrasesControl> Command<T> for PhrasesCommand {
|
impl<T: PhrasesControl> Command<T> for PhrasesCommand {
|
||||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||||
|
use PhrasesCommand::*;
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
Self::Phrase(command) => command.execute(state)?.map(Self::Phrase),
|
Phrase(command) => command.execute(state)?.map(Phrase),
|
||||||
Self::Rename(command) => command.execute(state)?.map(Self::Rename),
|
Rename(command) => command.execute(state)?.map(Rename),
|
||||||
Self::Length(command) => command.execute(state)?.map(Self::Length),
|
Length(command) => command.execute(state)?.map(Length),
|
||||||
Self::Select(phrase) => {
|
Select(phrase) => {
|
||||||
state.set_phrase_index(phrase);
|
state.set_phrase_index(phrase);
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
|
@ -149,32 +150,22 @@ impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
|
||||||
use PhraseLengthFocus::*;
|
use PhraseLengthFocus::*;
|
||||||
use PhraseLengthCommand::*;
|
use PhraseLengthCommand::*;
|
||||||
let mut mode = state.phrases_mode_mut().clone();
|
let mut mode = state.phrases_mode_mut().clone();
|
||||||
if let Some(PhrasesMode::Length(
|
if let Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) = mode {
|
||||||
phrase,
|
|
||||||
ref mut length,
|
|
||||||
ref mut focus,
|
|
||||||
)) = mode {
|
|
||||||
match self {
|
match self {
|
||||||
Self::Cancel => {
|
Cancel => { *state.phrases_mode_mut() = None; },
|
||||||
*state.phrases_mode_mut() = None;
|
Prev => { focus.prev() },
|
||||||
},
|
Next => { focus.next() },
|
||||||
Self::Prev => {
|
Inc => match focus {
|
||||||
focus.prev()
|
|
||||||
},
|
|
||||||
Self::Next => {
|
|
||||||
focus.next()
|
|
||||||
},
|
|
||||||
Self::Inc => match focus {
|
|
||||||
Bar => { *length += 4 * PPQ },
|
Bar => { *length += 4 * PPQ },
|
||||||
Beat => { *length += PPQ },
|
Beat => { *length += PPQ },
|
||||||
Tick => { *length += 1 },
|
Tick => { *length += 1 },
|
||||||
},
|
},
|
||||||
Self::Dec => match focus {
|
Dec => match focus {
|
||||||
Bar => { *length = length.saturating_sub(4 * PPQ) },
|
Bar => { *length = length.saturating_sub(4 * PPQ) },
|
||||||
Beat => { *length = length.saturating_sub(PPQ) },
|
Beat => { *length = length.saturating_sub(PPQ) },
|
||||||
Tick => { *length = length.saturating_sub(1) },
|
Tick => { *length = length.saturating_sub(1) },
|
||||||
},
|
},
|
||||||
Self::Set(length) => {
|
Set(length) => {
|
||||||
let mut phrase = state.phrases()[phrase].write().unwrap();
|
let mut phrase = state.phrases()[phrase].write().unwrap();
|
||||||
let old_length = phrase.length;
|
let old_length = phrase.length;
|
||||||
phrase.length = length;
|
phrase.length = length;
|
||||||
|
|
@ -210,10 +201,8 @@ where
|
||||||
{
|
{
|
||||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||||
use PhraseRenameCommand::*;
|
use PhraseRenameCommand::*;
|
||||||
if let Some(PhrasesMode::Rename(
|
let mut mode = state.phrases_mode_mut().clone();
|
||||||
phrase,
|
if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = mode {
|
||||||
ref mut old_name
|
|
||||||
)) = state.phrases_mode_mut().clone() {
|
|
||||||
match self {
|
match self {
|
||||||
Set(s) => {
|
Set(s) => {
|
||||||
state.phrases()[phrase].write().unwrap().name = s.into();
|
state.phrases()[phrase].write().unwrap().name = s.into();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue