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

Auto Trait Implementations§

§

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> 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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,

§

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>,

§

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>,

§

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.