pub struct Chord { /* private fields */ }Expand description
Describes a set of notes played simultaneously
Implementations§
Source§impl Chord
impl Chord
Sourcepub fn new(rhythm: f64, notes: Vec<Note>) -> Result<Self>
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 theChordwill 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 thisrhythmvalue.notes: list of notes in theChord(len must be 1 or more)
§Errors
ChordError::EmptyChordif notes vec is emptyChordError::RhythmTooLongifrhythmis 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}Sourcepub fn from_pitches(rhythm: f64, dynamic: u7, pitches: &[u7]) -> Result<Self>
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 theChordand all the notes it containspitches: list of the pitches of the notes of theChorddynamic: dynamic that each note in theChordwill take
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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