mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
80 lines
2.8 KiB
Rust
80 lines
2.8 KiB
Rust
/// Phrase editor.
|
|
|
|
pub(crate) use tek_core::*;
|
|
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
|
|
sequencer sequencer_tui
|
|
transport transport_tui
|
|
}
|
|
|
|
pub const PPQ: usize = 96;
|
|
|
|
pub const CORNERS: CornersTall = CornersTall(NOT_DIM_GREEN);
|
|
|
|
tui_style!(GRAY_DIM =
|
|
Some(Color::Gray), None, None, Modifier::DIM, Modifier::empty());
|
|
tui_style!(GRAY_NOT_DIM_BOLD =
|
|
Some(Color::Gray), None, None, Modifier::BOLD, Modifier::DIM);
|
|
tui_style!(NOT_DIM_BOLD =
|
|
None, None, None, Modifier::BOLD, Modifier::DIM);
|
|
tui_style!(NOT_DIM_GREEN =
|
|
Some(Color::Rgb(96, 255, 32)), Some(COLOR_BG1), None, Modifier::empty(), Modifier::DIM);
|
|
tui_style!(NOT_DIM =
|
|
None, None, None, Modifier::empty(), Modifier::DIM);
|
|
tui_style!(WHITE_NOT_DIM_BOLD =
|
|
Some(Color::White), None, None, Modifier::BOLD, Modifier::DIM);
|
|
tui_style!(STYLE_LABEL =
|
|
Some(Color::Reset), None, None, Modifier::empty(), Modifier::BOLD);
|
|
tui_style!(STYLE_VALUE =
|
|
Some(Color::White), None, None, Modifier::BOLD, Modifier::DIM);
|
|
|
|
pub fn random_color () -> Color {
|
|
let mut rng = thread_rng();
|
|
let color: Okhsl<f32> = Okhsl::new(
|
|
rng.gen::<f32>() * 360f32 - 180f32,
|
|
rng.gen::<f32>(),
|
|
rng.gen::<f32>() * 0.5,
|
|
);
|
|
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,
|
|
)
|
|
}
|
|
|
|
pub fn random_color_near (color: Color, distance: f32) -> Color {
|
|
let (r, g, b) = if let Color::Rgb(r, g, b) = color {
|
|
(r, g, b)
|
|
} else {
|
|
panic!("random_color_near works only with Color::Rgb")
|
|
};
|
|
if distance > 1.0 {
|
|
panic!("random_color_near requires distance between 0.0 and 1.0");
|
|
}
|
|
let old: Okhsl<f32> = Okhsl::from([
|
|
r as f32 / 255.0,
|
|
g as f32 / 255.0,
|
|
b as f32 / 255.0,
|
|
]);
|
|
let mut rng = thread_rng();
|
|
let new: Okhsl<f32> = Okhsl::new(
|
|
rng.gen::<f32>() * 360f32 - 180f32,
|
|
rng.gen::<f32>(),
|
|
rng.gen::<f32>() * 0.66,
|
|
);
|
|
let mixed = new.mix(old, 0.5);
|
|
let color: Srgb<f32> = Srgb::from_color_unclamped(mixed);
|
|
Color::Rgb(
|
|
(color.red * 255.0) as u8,
|
|
(color.green * 255.0) as u8,
|
|
(color.blue * 255.0) as u8,
|
|
)
|
|
}
|