mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
add phrase uuids; implement comparisons
This commit is contained in:
parent
5b2b04dcf9
commit
690a8e8f24
6 changed files with 40 additions and 19 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -2555,6 +2555,7 @@ name = "tek_sequencer"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tek_core",
|
"tek_core",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2715,6 +2716,15 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uuid"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version-compare"
|
name = "version-compare"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tek_core = { path = "../tek_core" }
|
tek_core = { path = "../tek_core" }
|
||||||
|
uuid = { version = "1.10.0", features = [ "v4" ] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
|
||||||
|
|
@ -470,11 +470,14 @@ impl Scene {
|
||||||
}
|
}
|
||||||
/// Returns true if all phrases in the scene are currently playing
|
/// Returns true if all phrases in the scene are currently playing
|
||||||
pub fn is_playing <E: Engine> (&self, tracks: &[ArrangementTrack<E>]) -> bool {
|
pub fn is_playing <E: Engine> (&self, tracks: &[ArrangementTrack<E>]) -> bool {
|
||||||
self.clips.iter().enumerate()
|
self.clips.iter().enumerate().all(|(track_index, clip)|match clip {
|
||||||
.all(|(track_index, clip)|match clip {
|
Some(clip) => tracks
|
||||||
Some(i) => tracks
|
|
||||||
.get(track_index)
|
.get(track_index)
|
||||||
.map(|track|track.player.phrase == Some(*i))
|
.map(|track|if let Some(phrase) = &track.player.phrase {
|
||||||
|
*phrase.read().unwrap() == *clip.read().unwrap()
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
})
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
None => true
|
None => true
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -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 scene_clip = |scene, track: usize, w: u16, h: u16|Layers::new(move |add|{
|
||||||
let mut color = Color::Rgb(40, 50, 30);
|
let mut color = Color::Rgb(40, 50, 30);
|
||||||
match (tracks.get(track), (scene as &Scene).clips.get(track)) {
|
match (tracks.get(track), (scene as &Scene).clips.get(track)) {
|
||||||
(Some(track), Some(Some(clip))) => match track.phrases.get(*clip) {
|
(Some(track), Some(Some(phrase))) => {
|
||||||
Some(phrase) => {
|
|
||||||
let name = &(phrase as &Arc<RwLock<Phrase>>).read().unwrap().name;
|
let name = &(phrase as &Arc<RwLock<Phrase>>).read().unwrap().name;
|
||||||
let name = format!("{}", name.read().unwrap());
|
let name = format!("{}", name.read().unwrap());
|
||||||
add(&name.as_str().push_x(1).fixed_x(w))?;
|
add(&name.as_str().push_x(1).fixed_x(w))?;
|
||||||
if (track as &PhrasePlayer<_>).phrase == Some(*clip) {
|
color = COLOR_BG1;
|
||||||
|
if let Some(playing_phrase) = &track.player.phrase {
|
||||||
|
if *playing_phrase.read().unwrap() == *phrase.read().unwrap() {
|
||||||
color = COLOR_PLAYING
|
color = COLOR_PLAYING
|
||||||
} else {
|
}
|
||||||
color = COLOR_BG1
|
}
|
||||||
};
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ pub struct PhrasePool<E: Engine> {
|
||||||
/// A MIDI sequence.
|
/// A MIDI sequence.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Phrase {
|
pub struct Phrase {
|
||||||
|
pub uuid: uuid::Uuid,
|
||||||
/// Name of phrase
|
/// Name of phrase
|
||||||
pub name: Arc<RwLock<String>>,
|
pub name: Arc<RwLock<String>>,
|
||||||
/// Temporal resolution in pulses per quarter note
|
/// Temporal resolution in pulses per quarter note
|
||||||
|
|
@ -121,6 +122,7 @@ impl Phrase {
|
||||||
name: &str, loop_on: bool, length: usize, notes: Option<PhraseData>
|
name: &str, loop_on: bool, length: usize, notes: Option<PhraseData>
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
uuid: uuid::Uuid::new_v4(),
|
||||||
name: Arc::new(RwLock::new(name.into())),
|
name: Arc::new(RwLock::new(name.into())),
|
||||||
ppq: PPQ,
|
ppq: PPQ,
|
||||||
length,
|
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> {
|
impl<E: Engine> PhrasePlayer<E> {
|
||||||
pub fn new (name: &str) -> Self {
|
pub fn new (name: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
// TODO: Display phrases always in order of appearance
|
||||||
impl Content for PhrasePool<Tui> {
|
impl Content for PhrasePool<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue