migrate Color -> ItemColor and remove unused

This commit is contained in:
🪞👃🪞 2024-11-02 14:54:02 +02:00
parent 33600e890f
commit eb1e3179a4
6 changed files with 59 additions and 76 deletions

View file

@ -79,7 +79,7 @@ pub enum PhrasePoolMode {
/// All notes are displayed with minimum length
pub percussive: bool,
/// Identifying color of phrase
pub color: Color,
pub color: ItemColor,
}
/// Contains state for viewing and editing a phrase
pub struct PhraseEditor<E: Engine> {
@ -205,7 +205,7 @@ impl<E: Engine> PhrasePool<E> {
}
return None
}
fn new_phrase (name: Option<&str>, color: Option<Color>) -> Arc<RwLock<Phrase>> {
fn new_phrase (name: Option<&str>, color: Option<ItemColor>) -> Arc<RwLock<Phrase>> {
Arc::new(RwLock::new(Phrase::new(
String::from(name.unwrap_or("(new)")), true, 4 * PPQ, None, color
)))
@ -216,23 +216,23 @@ impl<E: Engine> PhrasePool<E> {
self.phrase = self.phrase.min(self.phrases.len().saturating_sub(1));
}
}
pub fn append_new (&mut self, name: Option<&str>, color: Option<Color>) {
pub fn append_new (&mut self, name: Option<&str>, color: Option<ItemColor>) {
self.phrases.push(Self::new_phrase(name, color));
self.phrase = self.phrases.len() - 1;
}
pub fn insert_new (&mut self, name: Option<&str>, color: Option<Color>) {
pub fn insert_new (&mut self, name: Option<&str>, color: Option<ItemColor>) {
self.phrases.insert(self.phrase + 1, Self::new_phrase(name, color));
self.phrase += 1;
}
pub fn insert_dup (&mut self) {
let mut phrase = self.phrases[self.phrase].read().unwrap().duplicate();
phrase.color = random_color_near(phrase.color, 0.25);
phrase.color = ItemColor::random_near(phrase.color, 0.25);
self.phrases.insert(self.phrase + 1, Arc::new(RwLock::new(phrase)));
self.phrase += 1;
}
pub fn randomize_color (&mut self) {
let mut phrase = self.phrases[self.phrase].write().unwrap();
phrase.color = random_color();
phrase.color = ItemColor::random();
}
pub fn begin_rename (&mut self) {
self.mode = Some(PhrasePoolMode::Rename(
@ -347,7 +347,7 @@ impl Phrase {
loop_on: bool,
length: usize,
notes: Option<PhraseData>,
color: Option<Color>,
color: Option<ItemColor>,
) -> Self {
Self {
uuid: uuid::Uuid::new_v4(),
@ -359,7 +359,7 @@ impl Phrase {
loop_start: 0,
loop_length: length,
percussive: true,
color: color.unwrap_or_else(random_color)
color: color.unwrap_or_else(ItemColor::random)
}
}
pub fn duplicate (&self) -> Self {
@ -384,7 +384,7 @@ impl Phrase {
}
}
impl Default for Phrase {
fn default () -> Self { Self::new("(empty)", false, 0, None, Some(Color::Rgb(0, 0, 0))) }
fn default () -> Self { Self::new("(empty)", false, 0, None, Some(Color::Rgb(0, 0, 0).into())) }
}
impl PartialEq for Phrase { fn eq (&self, other: &Self) -> bool { self.uuid == other.uuid } }
impl Eq for Phrase {}