mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
switch sequencer to ItemColorTriplet
This commit is contained in:
parent
cb8dfb4bd7
commit
87379ff76b
5 changed files with 25 additions and 15 deletions
|
|
@ -36,8 +36,8 @@ impl ItemColor {
|
||||||
let hi = Okhsl::new( 180.0, 0.5, 0.2);
|
let hi = Okhsl::new( 180.0, 0.5, 0.2);
|
||||||
UniformOkhsl::new(lo, hi).sample(&mut rng).into()
|
UniformOkhsl::new(lo, hi).sample(&mut rng).into()
|
||||||
}
|
}
|
||||||
pub fn random_near (base: Self, distance: f32) -> Self {
|
pub fn random_near (color: Self, distance: f32) -> Self {
|
||||||
base.mix(Self::random(), distance)
|
color.mix(Self::random(), distance)
|
||||||
}
|
}
|
||||||
pub fn mix (&self, other: Self, distance: f32) -> Self {
|
pub fn mix (&self, other: Self, distance: f32) -> Self {
|
||||||
if distance > 1.0 { panic!("color mixing takes distance between 0.0 and 1.0"); }
|
if distance > 1.0 { panic!("color mixing takes distance between 0.0 and 1.0"); }
|
||||||
|
|
@ -55,6 +55,14 @@ impl From<ItemColor> for ItemColorTriplet {
|
||||||
Self { base, light: light.into(), dark: dark.into() }
|
Self { base, light: light.into(), dark: dark.into() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl ItemColorTriplet {
|
||||||
|
pub fn random () -> Self {
|
||||||
|
ItemColor::random().into()
|
||||||
|
}
|
||||||
|
pub fn random_near (color: Self, distance: f32) -> Self {
|
||||||
|
color.base.mix(ItemColor::random(), distance).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn okhsl_to_rgb (color: Okhsl<f32>) -> Color {
|
pub fn okhsl_to_rgb (color: Okhsl<f32>) -> Color {
|
||||||
let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(color);
|
let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(color);
|
||||||
Color::Rgb((red * 255.0) as u8, (green * 255.0) as u8, (blue * 255.0) as u8,)
|
Color::Rgb((red * 255.0) as u8, (green * 255.0) as u8, (blue * 255.0) as u8,)
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,7 @@ impl<E: Engine> Arrangement<E> {
|
||||||
ArrangementFocus::Track(t) => { self.tracks[t].color = ItemColor::random() },
|
ArrangementFocus::Track(t) => { self.tracks[t].color = ItemColor::random() },
|
||||||
ArrangementFocus::Scene(s) => { self.scenes[s].color = ItemColor::random() },
|
ArrangementFocus::Scene(s) => { self.scenes[s].color = ItemColor::random() },
|
||||||
ArrangementFocus::Clip(t, s) => if let Some(phrase) = &self.scenes[s].clips[t] {
|
ArrangementFocus::Clip(t, s) => if let Some(phrase) = &self.scenes[s].clips[t] {
|
||||||
phrase.write().unwrap().color = ItemColor::random();
|
phrase.write().unwrap().color = ItemColorTriplet::random();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
let name = format!("{}", name);
|
let name = format!("{}", name);
|
||||||
let max_w = name.len().min((w as usize).saturating_sub(2));
|
let max_w = name.len().min((w as usize).saturating_sub(2));
|
||||||
add(&name.as_str()[0..max_w].push_x(1).fixed_x(w))?;
|
add(&name.as_str()[0..max_w].push_x(1).fixed_x(w))?;
|
||||||
color = (phrase as &Arc<RwLock<Phrase>>).read().unwrap().color.rgb;
|
color = (phrase as &Arc<RwLock<Phrase>>).read().unwrap().color.base.rgb;
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ pub enum PhrasePoolMode {
|
||||||
/// All notes are displayed with minimum length
|
/// All notes are displayed with minimum length
|
||||||
pub percussive: bool,
|
pub percussive: bool,
|
||||||
/// Identifying color of phrase
|
/// Identifying color of phrase
|
||||||
pub color: ItemColor,
|
pub color: ItemColorTriplet,
|
||||||
}
|
}
|
||||||
/// Contains state for viewing and editing a phrase
|
/// Contains state for viewing and editing a phrase
|
||||||
pub struct PhraseEditor<E: Engine> {
|
pub struct PhraseEditor<E: Engine> {
|
||||||
|
|
@ -205,7 +205,7 @@ impl<E: Engine> PhrasePool<E> {
|
||||||
}
|
}
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
fn new_phrase (name: Option<&str>, color: Option<ItemColor>) -> Arc<RwLock<Phrase>> {
|
fn new_phrase (name: Option<&str>, color: Option<ItemColorTriplet>) -> Arc<RwLock<Phrase>> {
|
||||||
Arc::new(RwLock::new(Phrase::new(
|
Arc::new(RwLock::new(Phrase::new(
|
||||||
String::from(name.unwrap_or("(new)")), true, 4 * PPQ, None, color
|
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));
|
self.phrase = self.phrase.min(self.phrases.len().saturating_sub(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn append_new (&mut self, name: Option<&str>, color: Option<ItemColor>) {
|
pub fn append_new (&mut self, name: Option<&str>, color: Option<ItemColorTriplet>) {
|
||||||
self.phrases.push(Self::new_phrase(name, color));
|
self.phrases.push(Self::new_phrase(name, color));
|
||||||
self.phrase = self.phrases.len() - 1;
|
self.phrase = self.phrases.len() - 1;
|
||||||
}
|
}
|
||||||
pub fn insert_new (&mut self, name: Option<&str>, color: Option<ItemColor>) {
|
pub fn insert_new (&mut self, name: Option<&str>, color: Option<ItemColorTriplet>) {
|
||||||
self.phrases.insert(self.phrase + 1, Self::new_phrase(name, color));
|
self.phrases.insert(self.phrase + 1, Self::new_phrase(name, color));
|
||||||
self.phrase += 1;
|
self.phrase += 1;
|
||||||
}
|
}
|
||||||
pub fn insert_dup (&mut self) {
|
pub fn insert_dup (&mut self) {
|
||||||
let mut phrase = self.phrases[self.phrase].read().unwrap().duplicate();
|
let mut phrase = self.phrases[self.phrase].read().unwrap().duplicate();
|
||||||
phrase.color = ItemColor::random_near(phrase.color, 0.25);
|
phrase.color = ItemColorTriplet::random_near(phrase.color, 0.25);
|
||||||
self.phrases.insert(self.phrase + 1, Arc::new(RwLock::new(phrase)));
|
self.phrases.insert(self.phrase + 1, Arc::new(RwLock::new(phrase)));
|
||||||
self.phrase += 1;
|
self.phrase += 1;
|
||||||
}
|
}
|
||||||
pub fn randomize_color (&mut self) {
|
pub fn randomize_color (&mut self) {
|
||||||
let mut phrase = self.phrases[self.phrase].write().unwrap();
|
let mut phrase = self.phrases[self.phrase].write().unwrap();
|
||||||
phrase.color = ItemColor::random();
|
phrase.color = ItemColorTriplet::random();
|
||||||
}
|
}
|
||||||
pub fn begin_rename (&mut self) {
|
pub fn begin_rename (&mut self) {
|
||||||
self.mode = Some(PhrasePoolMode::Rename(
|
self.mode = Some(PhrasePoolMode::Rename(
|
||||||
|
|
@ -347,7 +347,7 @@ impl Phrase {
|
||||||
loop_on: bool,
|
loop_on: bool,
|
||||||
length: usize,
|
length: usize,
|
||||||
notes: Option<PhraseData>,
|
notes: Option<PhraseData>,
|
||||||
color: Option<ItemColor>,
|
color: Option<ItemColorTriplet>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
uuid: uuid::Uuid::new_v4(),
|
uuid: uuid::Uuid::new_v4(),
|
||||||
|
|
@ -359,7 +359,7 @@ impl Phrase {
|
||||||
loop_start: 0,
|
loop_start: 0,
|
||||||
loop_length: length,
|
loop_length: length,
|
||||||
percussive: true,
|
percussive: true,
|
||||||
color: color.unwrap_or_else(ItemColor::random)
|
color: color.unwrap_or_else(ItemColorTriplet::random)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn duplicate (&self) -> Self {
|
pub fn duplicate (&self) -> Self {
|
||||||
|
|
@ -384,7 +384,9 @@ impl Phrase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for Phrase {
|
impl Default for Phrase {
|
||||||
fn default () -> Self { Self::new("(empty)", false, 0, None, Some(Color::Rgb(0, 0, 0).into())) }
|
fn default () -> Self {
|
||||||
|
Self::new("(empty)", false, 0, None, Some(ItemColor::from(Color::Rgb(0, 0, 0)).into()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl PartialEq for Phrase { fn eq (&self, other: &Self) -> bool { self.uuid == other.uuid } }
|
impl PartialEq for Phrase { fn eq (&self, other: &Self) -> bool { self.uuid == other.uuid } }
|
||||||
impl Eq for Phrase {}
|
impl Eq for Phrase {}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ impl Content for PhrasePool<Tui> {
|
||||||
if *focused && i == *phrase { row2 = format!("{row2}▄"); }
|
if *focused && i == *phrase { row2 = format!("{row2}▄"); }
|
||||||
};
|
};
|
||||||
let row2 = TuiStyle::bold(row2, true);
|
let row2 = TuiStyle::bold(row2, true);
|
||||||
let bg = if i == self.phrase { color } else { color };
|
let bg = if i == self.phrase { color.base } else { color.light };
|
||||||
add(&col!(row1, row2).fill_x().bg(bg.rgb))?;
|
add(&col!(row1, row2).fill_x().bg(bg.rgb))?;
|
||||||
Ok(if *focused && i == self.phrase { add(&CORNERS)?; })
|
Ok(if *focused && i == self.phrase { add(&CORNERS)?; })
|
||||||
})
|
})
|
||||||
|
|
@ -57,7 +57,7 @@ impl Content for PhraseEditor<Tui> {
|
||||||
start: time_start, point: time_point, clamp: time_clamp, scale: time_scale
|
start: time_start, point: time_point, clamp: time_clamp, scale: time_scale
|
||||||
} = *self.time_axis.read().unwrap();
|
} = *self.time_axis.read().unwrap();
|
||||||
let color = Color::Rgb(0,255,0);
|
let color = Color::Rgb(0,255,0);
|
||||||
let color = phrase.as_ref().map(|p|p.read().unwrap().color.rgb).unwrap_or(color);
|
let color = phrase.as_ref().map(|p|p.read().unwrap().color.base.rgb).unwrap_or(color);
|
||||||
let keys = CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_w(5))), move|to: &mut TuiOutput|{
|
let keys = CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_w(5))), move|to: &mut TuiOutput|{
|
||||||
Ok(if to.area().h() >= 2 {
|
Ok(if to.area().h() >= 2 {
|
||||||
to.buffer_update(to.area().set_w(5), &|cell, x, y|{
|
to.buffer_update(to.area().set_w(5), &|cell, x, y|{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue