insert duplicate phrase

This commit is contained in:
🪞👃🪞 2024-10-11 10:12:02 +03:00
parent 69a81106fc
commit db2a2efa63
4 changed files with 46 additions and 30 deletions

View file

@ -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,30 +153,28 @@ impl<E: Engine> PhraseEditor<E> {
}
}
}
impl Default for Phrase {
fn default () -> Self { Self::new("", false, 0, None) }
pub fn random_color () -> Color {
let mut rng = thread_rng();
let color: Okhsl<f32> = Okhsl::new(
rng.gen::<f32>() * 360f32 - 180f32,
rng.gen::<f32>() * 0.5 + 0.25,
rng.gen::<f32>() * 0.5 + 0.25,
);
let color: Srgb<f32> = Srgb::from_color_unclamped(color);
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>
notes: Option<PhraseData>,
color: Option<Color>,
) -> Self {
use rand::{thread_rng, prelude::*};
use palette::{*, convert::*, okhsl::*};
let mut rng = thread_rng();
let color: Okhsl<f32> = Okhsl::new(
rng.gen::<f32>() * 360f32 - 180f32,
rng.gen::<f32>() * 0.5 + 0.25,
rng.gen::<f32>() * 0.5 + 0.25,
);
let color: Srgb<f32> = Srgb::from_color_unclamped(color);
let color = Color::Rgb(
(color.red * 255.0) as u8,
(color.green * 255.0) as u8,
(color.blue * 255.0) as u8,
);
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