TriadBase

Struct TriadBase 

Source
pub struct TriadBase<S = TriChord, K = Major, T = <S as RawSpace>::Elem>
where K: TriadType, S: TriadRepr<Elem = T>,
{ /* private fields */ }
Expand description

The TriadBase is an implementation of a triad generic over the chord, or storage, its classification, and the element type used to represent a note within the triadic chord.

Implementations§

Source§

impl<S, T, K> TriadBase<S, K, T>
where K: TriadType, S: TriadRepr<Elem = T>,

Source

pub fn new(chord: S, class: K) -> Self
where T: Zero,

Returns a new instance of the TriadBase with the given chord and kind.

Source

pub fn from_root_with_class(root: T, class: K) -> Self
where T: Copy + FromPrimitive + Zero + PitchMod<Output = T> + Add<Output = T>,

Create a new triad from a root pitch and class

Source

pub fn dynamic(self) -> TriadBase<S, Triads, T>

consumes the instance to use a dynamic classification enum

Source

pub const fn chord(&self) -> &S

returns an immutable reference to the chord.

Source

pub const fn chord_mut(&mut self) -> &mut S

returns a mutable reference to the chord.

Source

pub const fn class(&self) -> &K

returns a reference of the class of the triad.

Source

pub const fn class_mut(&mut self) -> &mut K

returns a mutable reference to the class of the triad.

Source

pub const fn octave(&self) -> &Octave<T>

returns a reference to the octave of the triad.

Source

pub const fn octave_mut(&mut self) -> &mut Octave<T>

Source

pub fn root(&self) -> &T
where S: TriadRepr,

returns a reference to the root note of the triad.

Source

pub fn root_mut(&mut self) -> &mut T
where S: TriadReprMut,

returns a mutable reference to the root note of the triad.

Source

pub fn third(&self) -> &T
where S: TriadRepr,

returns a reference to the third note of the triad.

Source

pub fn third_mut(&mut self) -> &mut T
where S: TriadReprMut,

returns a mutable reference to the third note of the triad.

Source

pub fn fifth(&self) -> &T
where S: TriadRepr,

returns a reference to the fifth note of the triad.

Source

pub fn fifth_mut(&mut self) -> &mut T
where S: TriadReprMut,

returns a mutable reference to the fifth note of the triad.

Source

pub fn set_chord(&mut self, chord: S) -> &mut Self

update the chord and returns a mutable reference to the triad

Source

pub fn set_class(&mut self, class: K) -> &mut Self

update the class and returns a mutable reference to the triad

Source

pub fn with_chord<S2>(self, chord: S2) -> TriadBase<S2, K>
where S2: TriadRepr<Elem = T>, T: Sized,

consumes the current instance to create another with the given chord

Source

pub fn with_class<K2>(self, class: K2) -> TriadBase<S, K2>
where K2: TriadType,

consumes the current instance to create another with the given class

Source

pub fn with_octave(self, octave: Octave<T>) -> Self

Source

pub fn into_parts(self) -> (S, K)

consumes the triad and returns the chord and class

Source

pub fn is_augmented(&self) -> bool

returns true if the triad is classified as an augmented triad.

Source

pub fn is_diminished(&self) -> bool

returns true if the triad is classified as a diminished triad.

Source

pub fn is_major(&self) -> bool

returns true if the triad is classified as a major triad.

Source

pub fn is_minor(&self) -> bool

returns true if the triad is classified as a minor triad.

Source

pub fn centroid<U>(&self) -> Option<[U; 2]>
where T: Copy + ToPrimitive, U: Float + FromPrimitive + ToPrimitive + Sum<T>, S: Clone + IntoIterator<Item = T>,

computes the centroid of the triad

Source

pub fn contains<Q>(&self, note: &Q) -> bool
where for<'a> &'a S: IntoIterator<Item = &'a T>, T: PartialEq, Q: Borrow<T>,

returns true if the triad contains the given note

Source

pub fn common_tones(&self, other: &Self) -> Vec<T>
where T: Clone + PartialEq, for<'a> &'a S: IntoIterator<Item = &'a T>,

returns a collection containing any tones common to both triads

Source

pub fn transform<X, Y>(self, step: X) -> Y
where Self: Transform<X, Output = Y>,

apply the given LPR transformation onto the triad, returning a new triad classified under Q where Q and K are related via the Rel associated type. For example, if transforming a major triad, then the resulting triad will be minor (and vice versa).

Source

pub fn leading<Y>(self) -> Y
where Self: Transform<LPR, Output = Y>,

apply the Leading transformation to the triad

Source

pub fn parallel<Y>(self) -> Y
where Self: Transform<LPR, Output = Y>,

apply the Parallel transformation to the triad

Source

pub fn relative<Y>(self) -> Y
where Self: Transform<LPR, Output = Y>,

apply the Relative transformation to the triad

Source

pub fn path_finder(&self) -> PathFinder<'_, S, K, T>

returns a path finder for the current triad

Source§

impl<S, T> TriadBase<S, Augmented, T>
where S: TriadRepr<Elem = T>,

Source

pub fn augmented(root: T) -> Self
where T: Copy + FromPrimitive + Zero + PitchMod<Output = T> + Add<Output = T>,

returns a new instance of the TriadBase with the given chord and kind as an augmented triad.

Source§

impl<S, T> TriadBase<S, Diminished, T>
where S: TriadRepr<Elem = T>,

Source

pub fn diminished(root: T) -> Self
where T: Copy + FromPrimitive + Zero + PitchMod<Output = T> + Add<Output = T>,

returns a new instance of the TriadBase with the given chord and kind as a diminished triad.

Source§

impl<S, T> TriadBase<S, Major, T>
where S: TriadRepr<Elem = T>,

Source

pub fn major(root: T) -> Self
where T: Copy + FromPrimitive + Zero + PitchMod<Output = T> + Add<Output = T>,

returns a new instance of the TriadBase with the given chord and kind as a major triad.

Source§

impl<S, T> TriadBase<S, Minor, T>
where S: TriadRepr<Elem = T>,

Source

pub fn minor(root: T) -> Self
where T: Copy + FromPrimitive + Zero + PitchMod<Output = T> + Add<Output = T>,

returns a new instance of the TriadBase with the given chord and kind as a minor triad.

Source§

impl<T> TriadBase<[T; 3], Triads, T>
where T: Copy + ToPrimitive + FromPrimitive + PitchMod<Output = T> + Add<Output = T>,

Source

pub fn barycentric<N, U>(&self, p: N) -> [U; 3]

return the barycentric coordinates of the given note w.r.t the current triad

Source

pub fn is_valid(&self) -> bool
where T: Copy + PartialEq + FromPrimitive + ToPrimitive + PitchMod<Output = T> + Sub<Output = T>,

returns true if the pitches within the triad match its classification

Source

pub fn is_neighbor(&self, other: &Self) -> Option<LPR>
where Self: Transform<LPR, Output = Self>, T: PartialEq,

returns some LPR transformation, iff they are within a single step of one another otherwise, returns None.

Source§

impl<T> TriadBase<[T; 3], Triads, T>
where T: Copy + ToPrimitive + FromPrimitive + Num + PitchMod<Output = T>,

Source

pub fn walk<I>(&self, path: I) -> Self
where I: IntoIterator<Item = LPR>,

apply a series of transformations to a triad

Source

pub fn walk_inplace<I>(&mut self, path: I)
where I: IntoIterator<Item = LPR>,

apply a chain of transformations to a triad in-place

Source§

impl TriadBase<[usize; 3], Triads>

Source

pub fn transform_inplace(&mut self, transform: LPR)

apply a single transformation to a triad in-place, mutating the current instance

Trait Implementations§

Source§

impl<T, S, K> AsMut<S> for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType,

Source§

fn as_mut(&mut self) -> &mut S

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, S, K> AsRef<S> for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType,

Source§

fn as_ref(&self) -> &S

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, S, K> Borrow<S> for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType,

Source§

fn borrow(&self) -> &S

Immutably borrows from an owned value. Read more
Source§

impl<T, S, K> BorrowMut<S> for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType,

Source§

fn borrow_mut(&mut self) -> &mut S

Mutably borrows from an owned value. Read more
Source§

impl<S, K, T: Clone> Clone for TriadBase<S, K, T>
where K: TriadType + Clone, S: TriadRepr<Elem = T> + Clone,

Source§

fn clone(&self) -> TriadBase<S, K, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, S, K> Debug for TriadBase<S, K, T>
where S: TriadRepr<Elem = T> + Debug, K: TriadType, T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, K, T: Default> Default for TriadBase<S, K, T>
where K: TriadType + Default, S: TriadRepr<Elem = T> + Default,

Source§

fn default() -> TriadBase<S, K, T>

Returns the “default value” for a type. Read more
Source§

impl<T, S, K> Deref for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType,

Source§

type Target = S

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, S, K> DerefMut for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<S, T, K> Dirac<&TriadBase<S, K, T>> for &LPR
where K: TriadType, K::Rel: TriadType, S: TriadRepr<Elem = T>, T: Copy + FromPrimitive + One + PitchMod<Output = T> + Add<Output = T> + Sub<Output = T>,

Source§

type Output = TriadBase<S, <K as Relative>::Rel, T>

Source§

fn apply(self, rhs: &TriadBase<S, K, T>) -> Self::Output

Source§

impl<S, T, K> Dirac<&TriadBase<S, K, T>> for LPR
where K: TriadType, K::Rel: TriadType, S: TriadRepr<Elem = T>, T: Copy + FromPrimitive + One + PitchMod<Output = T> + Add<Output = T> + Sub<Output = T>,

Source§

type Output = TriadBase<S, <K as Relative>::Rel, T>

Source§

fn apply(self, rhs: &TriadBase<S, K, T>) -> Self::Output

Source§

impl<S, T, K> Dirac<&mut TriadBase<S, K, T>> for LPR
where K: TriadType, K::Rel: TriadType, S: TriadRepr<Elem = T>, T: Copy + FromPrimitive + One + PitchMod<Output = T> + Add<Output = T> + Sub<Output = T>,

Source§

type Output = TriadBase<S, <K as Relative>::Rel, T>

Source§

fn apply(self, rhs: &mut TriadBase<S, K, T>) -> Self::Output

Source§

impl<S, T, K> Dirac<TriadBase<S, K, T>> for &LPR
where K: TriadType, K::Rel: TriadType, S: TriadRepr<Elem = T>, T: Copy + FromPrimitive + One + PitchMod<Output = T> + Add<Output = T> + Sub<Output = T>,

Source§

type Output = TriadBase<S, <K as Relative>::Rel, T>

Source§

fn apply(self, rhs: TriadBase<S, K, T>) -> Self::Output

Source§

impl<S, T, K> Dirac<TriadBase<S, K, T>> for &mut LPR
where K: TriadType, K::Rel: TriadType, S: TriadRepr<Elem = T>, T: Copy + FromPrimitive + One + PitchMod<Output = T> + Add<Output = T> + Sub<Output = T>,

Source§

type Output = TriadBase<S, <K as Relative>::Rel, T>

Source§

fn apply(self, rhs: TriadBase<S, K, T>) -> Self::Output

Source§

impl<S, T, K> Dirac<TriadBase<S, K, T>> for LPR
where K: TriadType, K::Rel: TriadType, S: TriadRepr<Elem = T>, T: Copy + FromPrimitive + One + PitchMod<Output = T> + Add<Output = T> + Sub<Output = T>,

Source§

type Output = TriadBase<S, <K as Relative>::Rel, T>

Source§

fn apply(self, rhs: TriadBase<S, K, T>) -> Self::Output

Source§

impl<T, S, K> Display for TriadBase<S, K, T>
where S: TriadRepr<Elem = T> + Debug, K: TriadType + Display, T: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, S, K> From<(S, K)> for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, T: Zero, K: TriadType,

Source§

fn from((chord, class): (S, K)) -> Self

Converts to this type from the input type.
Source§

impl<S, K, T: Hash> Hash for TriadBase<S, K, T>
where K: TriadType + Hash, S: TriadRepr<Elem = T> + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, S, K> Index<Factors> for TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType,

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: Factors) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, S, K> IndexMut<Factors> for TriadBase<S, K, T>
where S: TriadReprMut<Elem = T>, K: TriadType,

Source§

fn index_mut(&mut self, index: Factors) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, S, T, K, I> IntoIterator for &'a TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType, I: Iterator<Item = &'a T>, &'a S: IntoIterator<Item = I::Item, IntoIter = I>,

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = I

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, S, T, K, I> IntoIterator for &'a mut TriadBase<S, K, T>
where S: TriadRepr<Elem = T>, K: TriadType, I: Iterator<Item = &'a T>, &'a mut S: IntoIterator<Item = I::Item, IntoIter = I>,

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = I

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<S, T, K, I> IntoIterator for TriadBase<S, K, T>
where S: TriadRepr<Elem = T> + IntoIterator<Item = I::Item, IntoIter = I>, K: TriadType, I: Iterator<Item = T>,

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = I

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<S, T, K> PartialEq<S> for TriadBase<S, K, T>
where S: TriadRepr<Elem = T> + PartialEq, K: TriadType,

Source§

fn eq(&self, other: &S) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S1, T1, K1, S2, T2, K2> PartialEq<TriadBase<S2, K2, T2>> for TriadBase<S1, K1, T1>
where S1: TriadRepr<Elem = T1> + PartialEq<S2>, K1: TriadType, S2: TriadRepr<Elem = T2>, K2: TriadType,

Source§

fn eq(&self, other: &TriadBase<S2, K2, T2>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S, K, T: PartialOrd> PartialOrd for TriadBase<S, K, T>
where K: TriadType + PartialOrd, S: TriadRepr<Elem = T> + PartialOrd,

Source§

fn partial_cmp(&self, other: &TriadBase<S, K, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<S, T, K> Transform<LPR> for TriadBase<S, K, T>
where K: TriadType, K::Rel: TriadType, S: TriadRepr<Elem = T>, T: Copy + FromPrimitive + One + PitchMod<Output = T> + Add<Output = T> + Sub<Output = T>,

Source§

type Output = TriadBase<S, <K as Relative>::Rel, T>

Source§

fn transform(self, transformation: LPR) -> Self::Output

Source§

impl<S, K, T: Copy> Copy for TriadBase<S, K, T>
where K: TriadType + Copy, S: TriadRepr<Elem = T> + Copy,

Source§

impl<S, K, T: Eq> Eq for TriadBase<S, K, T>
where K: TriadType + Eq, S: TriadRepr<Elem = T> + Eq,

Auto Trait Implementations§

§

impl<S, K, T> Freeze for TriadBase<S, K, T>
where S: Freeze, K: Freeze, T: Freeze,

§

impl<S, K, T> RefUnwindSafe for TriadBase<S, K, T>

§

impl<S, K, T> Send for TriadBase<S, K, T>
where S: Send, T: Send,

§

impl<S, K, T> Sync for TriadBase<S, K, T>
where S: Sync, T: Sync,

§

impl<S, K, T> Unpin for TriadBase<S, K, T>
where S: Unpin, K: Unpin, T: Unpin,

§

impl<S, K, T> UnwindSafe for TriadBase<S, K, T>
where S: UnwindSafe, K: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsWeight<T> for T
where T: Clone + IntoWeight<T>,

Source§

fn as_weight(&self) -> Weight<T>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoWeight<T> for T

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Wrapper<T> for T

Source§

type Cont<U> = U

Source§

fn get(&self) -> &T

returns a reference to the inner value
Source§

fn view(&self) -> <T as Wrapper<T>>::Cont<&T>

returns a view of the container containing an immutable reference to the inner value