Struct rust_music::Chord
source · 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)
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)
}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§
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> 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