add phrase uuids; implement comparisons

This commit is contained in:
🪞👃🪞 2024-10-08 18:15:41 +03:00
parent 5b2b04dcf9
commit 690a8e8f24
6 changed files with 40 additions and 19 deletions

10
Cargo.lock generated
View file

@ -2555,6 +2555,7 @@ name = "tek_sequencer"
version = "0.1.0"
dependencies = [
"tek_core",
"uuid",
]
[[package]]
@ -2715,6 +2716,15 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
dependencies = [
"getrandom",
]
[[package]]
name = "version-compare"
version = "0.2.0"

View file

@ -5,6 +5,7 @@ version = "0.1.0"
[dependencies]
tek_core = { path = "../tek_core" }
uuid = { version = "1.10.0", features = [ "v4" ] }
[lib]
path = "src/lib.rs"

View file

@ -470,14 +470,17 @@ impl Scene {
}
/// Returns true if all phrases in the scene are currently playing
pub fn is_playing <E: Engine> (&self, tracks: &[ArrangementTrack<E>]) -> bool {
self.clips.iter().enumerate()
.all(|(track_index, clip)|match clip {
Some(i) => tracks
.get(track_index)
.map(|track|track.player.phrase == Some(*i))
.unwrap_or(false),
None => true
})
self.clips.iter().enumerate().all(|(track_index, clip)|match clip {
Some(clip) => tracks
.get(track_index)
.map(|track|if let Some(phrase) = &track.player.phrase {
*phrase.read().unwrap() == *clip.read().unwrap()
} else {
false
})
.unwrap_or(false),
None => true
})
}
pub fn ppqs <E: Engine> (tracks: &[ArrangementTrack<E>], scenes: &[Self]) -> Vec<(usize, usize)> {
let mut total = 0;

View file

@ -248,18 +248,16 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
let scene_clip = |scene, track: usize, w: u16, h: u16|Layers::new(move |add|{
let mut color = Color::Rgb(40, 50, 30);
match (tracks.get(track), (scene as &Scene).clips.get(track)) {
(Some(track), Some(Some(clip))) => match track.phrases.get(*clip) {
Some(phrase) => {
let name = &(phrase as &Arc<RwLock<Phrase>>).read().unwrap().name;
let name = format!("{}", name.read().unwrap());
add(&name.as_str().push_x(1).fixed_x(w))?;
if (track as &PhrasePlayer<_>).phrase == Some(*clip) {
(Some(track), Some(Some(phrase))) => {
let name = &(phrase as &Arc<RwLock<Phrase>>).read().unwrap().name;
let name = format!("{}", name.read().unwrap());
add(&name.as_str().push_x(1).fixed_x(w))?;
color = COLOR_BG1;
if let Some(playing_phrase) = &track.player.phrase {
if *playing_phrase.read().unwrap() == *phrase.read().unwrap() {
color = COLOR_PLAYING
} else {
color = COLOR_BG1
};
},
_ => {}
}
}
},
_ => {}
};

View file

@ -23,6 +23,7 @@ pub struct PhrasePool<E: Engine> {
/// A MIDI sequence.
#[derive(Debug)]
pub struct Phrase {
pub uuid: uuid::Uuid,
/// Name of phrase
pub name: Arc<RwLock<String>>,
/// Temporal resolution in pulses per quarter note
@ -121,6 +122,7 @@ impl Phrase {
name: &str, loop_on: bool, length: usize, notes: Option<PhraseData>
) -> Self {
Self {
uuid: uuid::Uuid::new_v4(),
name: Arc::new(RwLock::new(name.into())),
ppq: PPQ,
length,
@ -185,6 +187,12 @@ impl Phrase {
}
}
}
impl std::cmp::PartialEq for Phrase {
fn eq (&self, other: &Self) -> bool {
self.uuid == other.uuid
}
}
impl Eq for Phrase {}
impl<E: Engine> PhrasePlayer<E> {
pub fn new (name: &str) -> Self {
Self {

View file

@ -1,4 +1,5 @@
use crate::*;
// TODO: Display phrases always in order of appearance
impl Content for PhrasePool<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {