mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +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 {
|
||||
fn execute (self, model: &mut T) -> Perhaps<Self> {
|
||||
match self {
|
||||
Self::Add(mut index, phrase) => {
|
||||
use PhrasePoolCommand::*;
|
||||
Ok(match self {
|
||||
Add(mut index, phrase) => {
|
||||
let phrase = Arc::new(RwLock::new(phrase));
|
||||
let phrases = model.phrases_mut();
|
||||
if index >= phrases.len() {
|
||||
|
|
@ -30,24 +31,23 @@ impl<T: HasPhrases> Command<T> for PhrasePoolCommand {
|
|||
} else {
|
||||
phrases.insert(index, phrase);
|
||||
}
|
||||
return Ok(Some(Self::Delete(index)))
|
||||
Some(Self::Delete(index))
|
||||
},
|
||||
Self::Delete(index) => {
|
||||
let phrase = model.phrases_mut().remove(index);
|
||||
//view.phrase = view.phrase.min(view.model.phrases.len().saturating_sub(1));
|
||||
Delete(index) => {
|
||||
let phrase = model.phrases_mut().remove(index).read().unwrap().clone();
|
||||
Some(Self::Add(index, phrase))
|
||||
},
|
||||
Self::Swap(index, other) => {
|
||||
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 smf = Smf::parse(bytes.as_slice())?;
|
||||
println!("{:?}", &smf.header);
|
||||
let mut t = 0u32;
|
||||
let mut events = vec![];
|
||||
for (i, track) in smf.tracks.iter().enumerate() {
|
||||
for (j, event) in track.iter().enumerate() {
|
||||
for track in smf.tracks.iter() {
|
||||
for event in track.iter() {
|
||||
t += event.delta.as_int();
|
||||
if let TrackEventKind::Midi { channel, message } = event.kind {
|
||||
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);
|
||||
for event in events.iter() {
|
||||
println!("{event:?}");
|
||||
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);
|
||||
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> {
|
||||
use ArrangerCommand::*;
|
||||
Ok(match self {
|
||||
Focus(cmd) => cmd.execute(state)?.map(Focus),
|
||||
Scene(cmd) => cmd.execute(state)?.map(Scene),
|
||||
Track(cmd) => cmd.execute(state)?.map(Track),
|
||||
Clip(cmd) => cmd.execute(state)?.map(Clip),
|
||||
Phrases(cmd) => cmd.execute(state)?.map(Phrases),
|
||||
Editor(cmd) => cmd.execute(state)?.map(Editor),
|
||||
Clock(cmd) => cmd.execute(state)?.map(Clock),
|
||||
Zoom(zoom) => { todo!(); },
|
||||
Select(selected) => {
|
||||
Focus(cmd) => cmd.execute(state)?.map(Focus),
|
||||
Scene(cmd) => cmd.execute(state)?.map(Scene),
|
||||
Track(cmd) => cmd.execute(state)?.map(Track),
|
||||
Clip(cmd) => cmd.execute(state)?.map(Clip),
|
||||
Phrases(cmd) => cmd.execute(state)?.map(Phrases),
|
||||
Editor(cmd) => cmd.execute(state)?.map(Editor),
|
||||
Clock(cmd) => cmd.execute(state)?.map(Clock),
|
||||
Zoom(zoom) => { todo!(); },
|
||||
Select(selected) => {
|
||||
*state.selected_mut() = selected;
|
||||
None
|
||||
},
|
||||
|
|
@ -121,11 +121,12 @@ pub enum PhrasesCommand {
|
|||
|
||||
impl<T: PhrasesControl> Command<T> for PhrasesCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhrasesCommand::*;
|
||||
Ok(match self {
|
||||
Self::Phrase(command) => command.execute(state)?.map(Self::Phrase),
|
||||
Self::Rename(command) => command.execute(state)?.map(Self::Rename),
|
||||
Self::Length(command) => command.execute(state)?.map(Self::Length),
|
||||
Self::Select(phrase) => {
|
||||
Phrase(command) => command.execute(state)?.map(Phrase),
|
||||
Rename(command) => command.execute(state)?.map(Rename),
|
||||
Length(command) => command.execute(state)?.map(Length),
|
||||
Select(phrase) => {
|
||||
state.set_phrase_index(phrase);
|
||||
None
|
||||
},
|
||||
|
|
@ -149,32 +150,22 @@ impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
|
|||
use PhraseLengthFocus::*;
|
||||
use PhraseLengthCommand::*;
|
||||
let mut mode = state.phrases_mode_mut().clone();
|
||||
if let Some(PhrasesMode::Length(
|
||||
phrase,
|
||||
ref mut length,
|
||||
ref mut focus,
|
||||
)) = mode {
|
||||
if let Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) = mode {
|
||||
match self {
|
||||
Self::Cancel => {
|
||||
*state.phrases_mode_mut() = None;
|
||||
},
|
||||
Self::Prev => {
|
||||
focus.prev()
|
||||
},
|
||||
Self::Next => {
|
||||
focus.next()
|
||||
},
|
||||
Self::Inc => match focus {
|
||||
Cancel => { *state.phrases_mode_mut() = None; },
|
||||
Prev => { focus.prev() },
|
||||
Next => { focus.next() },
|
||||
Inc => match focus {
|
||||
Bar => { *length += 4 * PPQ },
|
||||
Beat => { *length += PPQ },
|
||||
Tick => { *length += 1 },
|
||||
},
|
||||
Self::Dec => match focus {
|
||||
Dec => match focus {
|
||||
Bar => { *length = length.saturating_sub(4 * PPQ) },
|
||||
Beat => { *length = length.saturating_sub(PPQ) },
|
||||
Tick => { *length = length.saturating_sub(1) },
|
||||
},
|
||||
Self::Set(length) => {
|
||||
Set(length) => {
|
||||
let mut phrase = state.phrases()[phrase].write().unwrap();
|
||||
let old_length = phrase.length;
|
||||
phrase.length = length;
|
||||
|
|
@ -210,10 +201,8 @@ where
|
|||
{
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhraseRenameCommand::*;
|
||||
if let Some(PhrasesMode::Rename(
|
||||
phrase,
|
||||
ref mut old_name
|
||||
)) = state.phrases_mode_mut().clone() {
|
||||
let mut mode = state.phrases_mode_mut().clone();
|
||||
if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = mode {
|
||||
match self {
|
||||
Set(s) => {
|
||||
state.phrases()[phrase].write().unwrap().name = s.into();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue