mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
insert duplicate phrase
This commit is contained in:
parent
69a81106fc
commit
db2a2efa63
4 changed files with 46 additions and 30 deletions
|
|
@ -178,12 +178,12 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
let name = &(phrase as &Arc<RwLock<Phrase>>).read().unwrap().name;
|
||||
let name = format!("{}", name.read().unwrap());
|
||||
add(&name.as_str().push_x(1).fixed_x(w))?;
|
||||
color = COLOR_BG1;
|
||||
if let Some(playing_phrase) = &track.player.phrase {
|
||||
if *playing_phrase.read().unwrap() == *phrase.read().unwrap() {
|
||||
color = COLOR_PLAYING
|
||||
}
|
||||
}
|
||||
color = (phrase as &Arc<RwLock<Phrase>>).read().unwrap().color;
|
||||
//if let Some(playing_phrase) = &track.player.phrase {
|
||||
//if *playing_phrase.read().unwrap() == *phrase.read().unwrap() {
|
||||
//color = COLOR_PLAYING
|
||||
//}
|
||||
//}
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ pub(crate) use tek_core::crossterm::event::KeyCode;
|
|||
pub(crate) use tek_core::midly::{num::u7, live::LiveEvent, MidiMessage};
|
||||
pub(crate) use tek_core::jack::*;
|
||||
pub(crate) use std::sync::{Arc, RwLock};
|
||||
pub(crate) use rand::{thread_rng, prelude::*};
|
||||
pub(crate) use palette::{*, convert::*, okhsl::*};
|
||||
|
||||
submod! {
|
||||
arranger arranger_tui
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub struct PhrasePool<E: Engine> {
|
|||
pub focused: bool,
|
||||
}
|
||||
/// A MIDI sequence.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Phrase {
|
||||
pub uuid: uuid::Uuid,
|
||||
/// Name of phrase
|
||||
|
|
@ -153,18 +153,7 @@ impl<E: Engine> PhraseEditor<E> {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl Default for Phrase {
|
||||
fn default () -> Self { Self::new("", false, 0, None) }
|
||||
}
|
||||
impl Phrase {
|
||||
pub fn new (
|
||||
name: &str,
|
||||
loop_on: bool,
|
||||
length: usize,
|
||||
notes: Option<PhraseData>
|
||||
) -> Self {
|
||||
use rand::{thread_rng, prelude::*};
|
||||
use palette::{*, convert::*, okhsl::*};
|
||||
pub fn random_color () -> Color {
|
||||
let mut rng = thread_rng();
|
||||
let color: Okhsl<f32> = Okhsl::new(
|
||||
rng.gen::<f32>() * 360f32 - 180f32,
|
||||
|
|
@ -172,11 +161,20 @@ impl Phrase {
|
|||
rng.gen::<f32>() * 0.5 + 0.25,
|
||||
);
|
||||
let color: Srgb<f32> = Srgb::from_color_unclamped(color);
|
||||
let color = Color::Rgb(
|
||||
Color::Rgb(
|
||||
(color.red * 255.0) as u8,
|
||||
(color.green * 255.0) as u8,
|
||||
(color.blue * 255.0) as u8,
|
||||
);
|
||||
)
|
||||
}
|
||||
impl Phrase {
|
||||
pub fn new (
|
||||
name: &str,
|
||||
loop_on: bool,
|
||||
length: usize,
|
||||
notes: Option<PhraseData>,
|
||||
color: Option<Color>,
|
||||
) -> Self {
|
||||
Self {
|
||||
uuid: uuid::Uuid::new_v4(),
|
||||
name: Arc::new(RwLock::new(name.into())),
|
||||
|
|
@ -187,7 +185,7 @@ impl Phrase {
|
|||
loop_start: 0,
|
||||
loop_length: length,
|
||||
percussive: true,
|
||||
color
|
||||
color: color.unwrap_or_else(random_color)
|
||||
}
|
||||
}
|
||||
pub fn toggle_loop (&mut self) {
|
||||
|
|
@ -244,6 +242,9 @@ impl Phrase {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl Default for Phrase {
|
||||
fn default () -> Self { Self::new("", false, 0, None, Some(Color::Rgb(0, 0, 0))) }
|
||||
}
|
||||
impl std::cmp::PartialEq for Phrase {
|
||||
fn eq (&self, other: &Self) -> bool {
|
||||
self.uuid == other.uuid
|
||||
|
|
|
|||
|
|
@ -83,13 +83,26 @@ impl Handle<Tui> for PhrasePool<Tui> {
|
|||
key!(KeyCode::Down) => {
|
||||
self.phrase = (self.phrase + 1) % self.phrases.len()
|
||||
},
|
||||
key!(KeyCode::Char('i')) => {
|
||||
self.phrases.insert(self.phrase, Arc::new(RwLock::new(Phrase::default())));
|
||||
key!(KeyCode::Char('a')) => { // append new
|
||||
let mut phrase = Phrase::default();
|
||||
phrase.color = random_color();
|
||||
self.phrases.push(Arc::new(RwLock::new(phrase)));
|
||||
self.phrase = self.phrases.len() - 1;
|
||||
},
|
||||
key!(KeyCode::Char('i')) => { // insert new
|
||||
let mut phrase = Phrase::default();
|
||||
phrase.color = random_color();
|
||||
self.phrases.insert(self.phrase, Arc::new(RwLock::new(phrase)));
|
||||
self.phrase += 1;
|
||||
},
|
||||
key!(KeyCode::Char('a')) => {
|
||||
self.phrases.push(Arc::new(RwLock::new(Phrase::default())));
|
||||
self.phrase = self.phrases.len() - 1;
|
||||
key!(KeyCode::Char('d')) => { // insert duplicate
|
||||
let phrase = (*self.phrases[self.phrase].read().unwrap()).clone();
|
||||
self.phrases.insert(self.phrase, Arc::new(RwLock::new(phrase)));
|
||||
self.phrase += 1;
|
||||
},
|
||||
key!(KeyCode::Char('c')) => { // change color
|
||||
let mut phrase = self.phrases[self.phrase].write().unwrap();
|
||||
phrase.color = random_color();
|
||||
},
|
||||
_ => return Ok(None),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue