-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from FL03/v0.0.2
V0.0.2
- Loading branch information
Showing
74 changed files
with
2,863 additions
and
1,078 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Appellation: chord <module> | ||
Contrib: FL03 <jo3mccain@icloud.com> | ||
*/ | ||
use super::ChordData; | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] | ||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] | ||
pub struct Chord<S> | ||
where | ||
S: ChordData, | ||
{ | ||
pub(crate) len: usize, | ||
pub(crate) notes: S, | ||
} | ||
|
||
impl<S> Chord<S> | ||
where | ||
S: ChordData, | ||
{ | ||
pub fn new() -> Self | ||
where | ||
S: Default, | ||
{ | ||
Self { | ||
len: 0, | ||
notes: Default::default(), | ||
} | ||
} | ||
|
||
pub fn from_notes(notes: S) -> Self { | ||
Self { | ||
len: notes.len(), | ||
notes, | ||
} | ||
} | ||
|
||
pub fn from_iter<I>(iter: I) -> Self | ||
where | ||
I: IntoIterator<Item = S::Elem>, | ||
S: Default, | ||
{ | ||
let mut notes = S::default(); | ||
for note in iter { | ||
notes.push(note); | ||
} | ||
Self::from_notes(notes) | ||
} | ||
|
||
pub fn get(&self, idx: usize) -> &S::Elem { | ||
self.notes.get(idx) | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
debug_assert_eq!( | ||
self.len, | ||
self.notes.len(), | ||
"Chord length is inconsistent with notes length" | ||
); | ||
self.len | ||
} | ||
|
||
pub fn push(&mut self, note: S::Elem) { | ||
self.len += 1; | ||
self.notes.push(note); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Appellation: dyad <module> | ||
Contrib: FL03 <jo3mccain@icloud.com> | ||
*/ | ||
use crate::notes::Note; | ||
use crate::{Intervals, Pair}; | ||
|
||
fn _interval<A, B>(lhs: A, rhs: B) -> Intervals | ||
where | ||
A: core::ops::Sub<B, Output = Intervals>, | ||
{ | ||
lhs - rhs | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] | ||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] | ||
pub struct Dyad { | ||
chord: Pair<Note>, | ||
interval: Intervals, | ||
} | ||
|
||
impl Dyad { | ||
pub fn new(src: Note, tgt: Note) -> Self { | ||
let chord = Pair::new(src, tgt); | ||
let interval = Intervals::dist(src, tgt); | ||
Self { chord, interval } | ||
} | ||
|
||
pub fn from_tuple((lhs, rhs): (Note, Note)) -> Self { | ||
let chord = Pair::new(lhs, rhs); | ||
let interval = Intervals::dist(lhs, rhs); | ||
Self { chord, interval } | ||
} | ||
|
||
pub const fn chord(&self) -> &Pair<Note> { | ||
&self.chord | ||
} | ||
|
||
pub fn chord_mut(&mut self) -> &mut Pair<Note> { | ||
&mut self.chord | ||
} | ||
|
||
pub const fn interval(&self) -> &Intervals { | ||
&self.interval | ||
} | ||
|
||
pub fn interval_mut(&mut self) -> &mut Intervals { | ||
&mut self.interval | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Appellation: chord <module> | ||
Contrib: FL03 <jo3mccain@icloud.com> | ||
*/ | ||
#[doc(inline)] | ||
pub use self::{chord::Chord, dyad::Dyad}; | ||
|
||
pub(crate) mod chord; | ||
pub(crate) mod dyad; | ||
|
||
pub(crate) mod prelude { | ||
pub use super::chord::*; | ||
pub use super::dyad::*; | ||
} | ||
|
||
pub trait Container { | ||
type Elem; | ||
} | ||
|
||
impl<T> Container for Vec<T> { | ||
type Elem = T; | ||
} | ||
|
||
/// [ChordData] provides common methods for viable representations of chords. | ||
/// Typically, implementations of [ChordData] describe linear data-structures | ||
/// such as arrays, vectors, or slices. | ||
pub trait ChordData { | ||
type Elem; | ||
|
||
fn get(&self, idx: usize) -> &Self::Elem; | ||
|
||
fn len(&self) -> usize; | ||
|
||
fn push(&mut self, elem: Self::Elem); | ||
} |
Oops, something went wrong.