Chord

Struct Chord 

Source
pub struct Chord { /* private fields */ }
Expand description

Describes a set of notes played simultaneously

Implementations§

Source§

impl Chord

Source

pub fn new(rhythm: f64, notes: Vec<Note>) -> Result<Self>

Returns a new Chord based on the given rhythm value and notes

§Arguments
  • rhythm: duration in beats that the Chord will take in a phrase. Some notes of the chord can last longer, but the next entry added to the phrase will start after the end of this rhythm value.
  • notes: list of notes in the Chord (len must be 1 or more)
§Errors
  • ChordError::EmptyChord if notes vec is empty
  • ChordError::RhythmTooLong if rhythm is longer than the longest note
Examples found in repository?
examples/praeludium_no1_single_phrase.rs (line 42)
35fn phrase() -> Result<Phrase> {
36    let mut phrase = Phrase::new();
37    let mut add_bar = |pitch1: u7, pitch2: u7, pitch3: u7, pitch4: u7, pitch5: u7| -> Result<()> {
38        for _ in 0..=1 {
39            // Using a single note Chord to define a note that lasts while the next notes play.
40            // The next note/chord starts at the end of the Chord's rhythm value, but the notes in the
41            // chord can have a longer duration.
42            phrase.add_chord(Chord::new(SEMIQUAVER, vec![Note::new(pitch1, MINIM, MF)?])?);
43            phrase.add_chord(Chord::new(
44                SEMIQUAVER,
45                vec![Note::new(pitch2, DOTTED_QUAVER + CROTCHET, MF)?],
46            )?);
47            for _ in 0..=1 {
48                phrase.add_sequential_notes(Note::new_sequence(
49                    SEMIQUAVER,
50                    MF,
51                    [pitch3, pitch4, pitch5],
52                ))?;
53            }
54        }
55        Ok(())
56    };
57    add_bar(
58        compute_pitch(NN::C, Acc::Natural, 4)?,
59        compute_pitch(NN::E, Acc::Natural, 4)?,
60        compute_pitch(NN::G, Acc::Natural, 4)?,
61        compute_pitch(NN::C, Acc::Natural, 5)?,
62        compute_pitch(NN::E, Acc::Natural, 5)?,
63    )?;
64    add_bar(
65        compute_pitch(NN::C, Acc::Natural, 4)?,
66        compute_pitch(NN::D, Acc::Natural, 4)?,
67        compute_pitch(NN::A, Acc::Natural, 4)?,
68        compute_pitch(NN::D, Acc::Natural, 5)?,
69        compute_pitch(NN::F, Acc::Natural, 5)?,
70    )?;
71    add_bar(
72        compute_pitch(NN::B, Acc::Natural, 3)?,
73        compute_pitch(NN::D, Acc::Natural, 4)?,
74        compute_pitch(NN::G, Acc::Natural, 4)?,
75        compute_pitch(NN::D, Acc::Natural, 5)?,
76        compute_pitch(NN::F, Acc::Natural, 5)?,
77    )?;
78    add_bar(
79        compute_pitch(NN::C, Acc::Natural, 4)?,
80        compute_pitch(NN::E, Acc::Natural, 4)?,
81        compute_pitch(NN::G, Acc::Natural, 4)?,
82        compute_pitch(NN::C, Acc::Natural, 5)?,
83        compute_pitch(NN::E, Acc::Natural, 5)?,
84    )?;
85    add_bar(
86        compute_pitch(NN::C, Acc::Natural, 4)?,
87        compute_pitch(NN::E, Acc::Natural, 4)?,
88        compute_pitch(NN::A, Acc::Natural, 4)?,
89        compute_pitch(NN::E, Acc::Natural, 5)?,
90        compute_pitch(NN::A, Acc::Natural, 5)?,
91    )?;
92    add_bar(
93        compute_pitch(NN::C, Acc::Natural, 4)?,
94        compute_pitch(NN::D, Acc::Natural, 4)?,
95        compute_pitch(NN::F, Acc::Sharp, 4)?,
96        compute_pitch(NN::A, Acc::Natural, 4)?,
97        compute_pitch(NN::D, Acc::Natural, 5)?,
98    )?;
99    add_bar(
100        compute_pitch(NN::B, Acc::Natural, 3)?,
101        compute_pitch(NN::D, Acc::Natural, 4)?,
102        compute_pitch(NN::G, Acc::Natural, 4)?,
103        compute_pitch(NN::D, Acc::Natural, 5)?,
104        compute_pitch(NN::G, Acc::Natural, 5)?,
105    )?;
106    add_bar(
107        compute_pitch(NN::B, Acc::Natural, 3)?,
108        compute_pitch(NN::C, Acc::Natural, 4)?,
109        compute_pitch(NN::E, Acc::Natural, 4)?,
110        compute_pitch(NN::G, Acc::Natural, 4)?,
111        compute_pitch(NN::C, Acc::Natural, 5)?,
112    )?;
113    add_bar(
114        compute_pitch(NN::A, Acc::Natural, 3)?,
115        compute_pitch(NN::C, Acc::Natural, 4)?,
116        compute_pitch(NN::E, Acc::Natural, 4)?,
117        compute_pitch(NN::G, Acc::Natural, 4)?,
118        compute_pitch(NN::C, Acc::Natural, 5)?,
119    )?;
120    Ok(phrase)
121}
Source

pub fn from_pitches(rhythm: f64, dynamic: u7, pitches: &[u7]) -> Result<Self>

Returns a new Chord based on the given rhythm value, note pitches, and dynamic.

§Arguments
  • rhythm: duration in beats of the Chord and all the notes it contains
  • pitches: list of the pitches of the notes of the Chord
  • dynamic: dynamic that each note in the Chord will take
Source

pub fn rhythm(&self) -> f64

Returns the rhythm value of the Chord

Source

pub fn notes(&self) -> &[Note]

Returns the notes of the Chord

Trait Implementations§

Source§

impl Clone for Chord

Source§

fn clone(&self) -> Chord

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 Debug for Chord

Source§

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

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

impl Default for Chord

Source§

fn default() -> Chord

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

impl PartialEq for Chord

Source§

fn eq(&self, other: &Chord) -> 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 StructuralPartialEq for Chord

Auto Trait Implementations§

§

impl Freeze for Chord

§

impl RefUnwindSafe for Chord

§

impl Send for Chord

§

impl Sync for Chord

§

impl Unpin for Chord

§

impl UnwindSafe for Chord

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> 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<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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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.