mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
scene and track colors; random_color_near
This commit is contained in:
parent
f500c717a2
commit
6bee5b0bcd
5 changed files with 80 additions and 38 deletions
|
|
@ -47,11 +47,17 @@ pub struct ArrangementTrack<E: Engine> {
|
|||
pub outputs: Vec<()>,
|
||||
/// Preferred width of track column
|
||||
pub width: usize,
|
||||
/// Identifying color of track
|
||||
pub color: Color,
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub struct Scene {
|
||||
/// Name of scene
|
||||
pub name: Arc<RwLock<String>>,
|
||||
/// Clips in scene, one per track
|
||||
pub clips: Vec<Option<Arc<RwLock<Phrase>>>>,
|
||||
/// Identifying color of scene
|
||||
pub color: Color,
|
||||
}
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
/// Represents the current user selection in the arranger
|
||||
|
|
@ -199,8 +205,8 @@ impl<E: Engine> Arrangement<E> {
|
|||
}
|
||||
pub fn track_add (&mut self, name: Option<&str>) -> Usually<&mut ArrangementTrack<E>> {
|
||||
self.tracks.push(name.map_or_else(
|
||||
|| ArrangementTrack::new(&self.track_default_name()),
|
||||
|name| ArrangementTrack::new(name),
|
||||
|| ArrangementTrack::new(&self.track_default_name(), None),
|
||||
|name| ArrangementTrack::new(name, None),
|
||||
));
|
||||
let index = self.tracks.len() - 1;
|
||||
Ok(&mut self.tracks[index])
|
||||
|
|
@ -240,8 +246,8 @@ impl<E: Engine> Arrangement<E> {
|
|||
pub fn scene_add (&mut self, name: Option<&str>) -> Usually<&mut Scene> {
|
||||
let clips = vec![None;self.tracks.len()];
|
||||
self.scenes.push(match name {
|
||||
Some(name) => Scene::new(name, clips),
|
||||
None => Scene::new(&self.scene_default_name(), clips),
|
||||
Some(name) => Scene::new(name, clips, None),
|
||||
None => Scene::new(&self.scene_default_name(), clips, None),
|
||||
});
|
||||
let index = self.scenes.len() - 1;
|
||||
Ok(&mut self.scenes[index])
|
||||
|
|
@ -344,13 +350,14 @@ impl<E: Engine> Arrangement<E> {
|
|||
}
|
||||
}
|
||||
impl<E: Engine> ArrangementTrack<E> {
|
||||
pub fn new (name: &str) -> Self {
|
||||
pub fn new (name: &str, color: Option<Color>) -> Self {
|
||||
Self {
|
||||
name: Arc::new(RwLock::new(name.into())),
|
||||
inputs: vec![],
|
||||
player: PhrasePlayer::new(name),
|
||||
player: PhrasePlayer::new(),
|
||||
outputs: vec![],
|
||||
width: name.len() + 2,
|
||||
color: color.unwrap_or_else(random_color)
|
||||
}
|
||||
}
|
||||
pub fn longest_name (tracks: &[Self]) -> usize {
|
||||
|
|
@ -491,11 +498,13 @@ impl ArrangementViewMode {
|
|||
impl Scene {
|
||||
pub fn new (
|
||||
name: impl AsRef<str>,
|
||||
clips: impl AsRef<[Option<Arc<RwLock<Phrase>>>]>
|
||||
clips: impl AsRef<[Option<Arc<RwLock<Phrase>>>]>,
|
||||
color: Option<Color>,
|
||||
) -> Self {
|
||||
Self {
|
||||
name: Arc::new(RwLock::new(name.as_ref().into())),
|
||||
clips: clips.as_ref().iter().map(|x|x.clone()).collect(),
|
||||
color: color.unwrap_or_else(random_color),
|
||||
}
|
||||
}
|
||||
/// Returns the pulse length of the longest phrase in the scene
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue