Struct rust_music::score::Score
source · pub struct Score { /* private fields */ }Expand description
Describes a full Score
Implementations§
source§impl Score
impl Score
sourcepub fn new<S: ToString>(
name: S,
tempo: Tempo,
metadata: Option<Metadata>
) -> Score
pub fn new<S: ToString>( name: S, tempo: Tempo, metadata: Option<Metadata> ) -> Score
Returns a new empty Score from the given arguments
Arguments
name- Title of theScoretempo- Tempo of theScoreMetadata- Optional information
Examples found in repository?
examples/praeludium_no1_single_phrase.rs (lines 21-30)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn praeludium() -> Result<Score> {
let mut part = Part::new(Instrument::AcousticGrandPiano);
part.add_phrase(phrase()?, 0.);
let mut score = Score::new(
"Praeludium No 1 in C Major",
Tempo::new(96)?,
Some(Metadata {
key_signature: NN::C as i8,
mode: Mode::Major,
time_numerator: 4,
time_denominator: 4,
}),
);
score.add_part(part);
Ok(score)
}More examples
examples/praeludium_no1_multi_phrase.rs (lines 33-42)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
fn praeludium() -> Result<Score> {
let mut part: Part = Part::new(Instrument::AcousticGrandPiano);
part.add_phrase(right_hand()?, 0.);
part.add_phrase(left_hand_high_note()?, 0.);
part.add_phrase(left_hand_low_note()?, 0.);
let mut score = Score::new(
"Praeludium No 1 in C Major",
Tempo::new(96)?,
Some(Metadata {
key_signature: NN::C as i8,
mode: Mode::Major,
time_numerator: 4,
time_denominator: 4,
}),
);
score.add_part(part);
Ok(score)
}examples/praeludium_no1_organ_piano.rs (lines 30-39)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn praeludium() -> Result<Score> {
let mut piano_part = Part::new(Instrument::AcousticGrandPiano);
let mut organ_part = Part::new(Instrument::ChurchOrgan);
piano_part.add_phrase(right_hand()?, 0.);
organ_part.add_phrase(left_hand_high_note()?, 0.);
organ_part.add_phrase(left_hand_low_note()?, 0.);
let mut score = Score::new(
"Praeludium No 1 in C Major",
Tempo::new(96)?,
Some(Metadata {
key_signature: NN::C as i8,
mode: Mode::Major,
time_numerator: 4,
time_denominator: 4,
}),
);
score.add_part(piano_part);
score.add_part(organ_part);
Ok(score)
}examples/readme_example.rs (line 40)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn main() -> Result<(), Box<dyn Error>> {
// Create a musical phrase that plays C-E-G (arpeggiated C Major chord)
// with crotchets, at MezzoForte volume
let mut phrase_to_repeat = Phrase::new();
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::C, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::E, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::G, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
// Create a piano part that plays the phrase from beat 0
let mut piano_part = Part::new(Instrument::AcousticGrandPiano);
piano_part.add_phrase(phrase_to_repeat.clone(), 0.);
// Create a Strings part that plays the phrase from beat 0.5
// (at the same time as the piano but shifted half a beat)
let mut violins_part = Part::new(Instrument::StringEnsemble1);
violins_part.add_phrase(phrase_to_repeat, 0.5);
// Create a score with a tempo of 60 (one beat per second) and add both parts
let mut score = Score::new("my score", Tempo::new(60)?, None);
score.add_part(piano_part);
score.add_part(violins_part);
// Write the score to a MIDI file for playback
score.write_midi_file(File::create("readme_example.mid")?)?;
Ok(())
}sourcepub fn add_part(&mut self, part: Part)
pub fn add_part(&mut self, part: Part)
Adds a Part to the Score.
Warning: q Score can contain unlimited Parts but if exporting to
Standard MIDI File, any Score with more than 16 Parts will fail
because MIDI only supports 16 channels.
Examples found in repository?
examples/praeludium_no1_single_phrase.rs (line 31)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn praeludium() -> Result<Score> {
let mut part = Part::new(Instrument::AcousticGrandPiano);
part.add_phrase(phrase()?, 0.);
let mut score = Score::new(
"Praeludium No 1 in C Major",
Tempo::new(96)?,
Some(Metadata {
key_signature: NN::C as i8,
mode: Mode::Major,
time_numerator: 4,
time_denominator: 4,
}),
);
score.add_part(part);
Ok(score)
}More examples
examples/praeludium_no1_multi_phrase.rs (line 43)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
fn praeludium() -> Result<Score> {
let mut part: Part = Part::new(Instrument::AcousticGrandPiano);
part.add_phrase(right_hand()?, 0.);
part.add_phrase(left_hand_high_note()?, 0.);
part.add_phrase(left_hand_low_note()?, 0.);
let mut score = Score::new(
"Praeludium No 1 in C Major",
Tempo::new(96)?,
Some(Metadata {
key_signature: NN::C as i8,
mode: Mode::Major,
time_numerator: 4,
time_denominator: 4,
}),
);
score.add_part(part);
Ok(score)
}examples/praeludium_no1_organ_piano.rs (line 40)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn praeludium() -> Result<Score> {
let mut piano_part = Part::new(Instrument::AcousticGrandPiano);
let mut organ_part = Part::new(Instrument::ChurchOrgan);
piano_part.add_phrase(right_hand()?, 0.);
organ_part.add_phrase(left_hand_high_note()?, 0.);
organ_part.add_phrase(left_hand_low_note()?, 0.);
let mut score = Score::new(
"Praeludium No 1 in C Major",
Tempo::new(96)?,
Some(Metadata {
key_signature: NN::C as i8,
mode: Mode::Major,
time_numerator: 4,
time_denominator: 4,
}),
);
score.add_part(piano_part);
score.add_part(organ_part);
Ok(score)
}examples/readme_example.rs (line 41)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn main() -> Result<(), Box<dyn Error>> {
// Create a musical phrase that plays C-E-G (arpeggiated C Major chord)
// with crotchets, at MezzoForte volume
let mut phrase_to_repeat = Phrase::new();
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::C, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::E, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::G, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
// Create a piano part that plays the phrase from beat 0
let mut piano_part = Part::new(Instrument::AcousticGrandPiano);
piano_part.add_phrase(phrase_to_repeat.clone(), 0.);
// Create a Strings part that plays the phrase from beat 0.5
// (at the same time as the piano but shifted half a beat)
let mut violins_part = Part::new(Instrument::StringEnsemble1);
violins_part.add_phrase(phrase_to_repeat, 0.5);
// Create a score with a tempo of 60 (one beat per second) and add both parts
let mut score = Score::new("my score", Tempo::new(60)?, None);
score.add_part(piano_part);
score.add_part(violins_part);
// Write the score to a MIDI file for playback
score.write_midi_file(File::create("readme_example.mid")?)?;
Ok(())
}sourcepub fn write_midi_file<W: Write>(&self, w: W) -> Result<()>
pub fn write_midi_file<W: Write>(&self, w: W) -> Result<()>
Examples found in repository?
More examples
examples/readme_example.rs (line 45)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn main() -> Result<(), Box<dyn Error>> {
// Create a musical phrase that plays C-E-G (arpeggiated C Major chord)
// with crotchets, at MezzoForte volume
let mut phrase_to_repeat = Phrase::new();
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::C, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::E, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
phrase_to_repeat.add_note(Note::new(
compute_pitch(NoteName::G, Accidental::Natural, 4)?,
CROTCHET,
MF,
)?);
// Create a piano part that plays the phrase from beat 0
let mut piano_part = Part::new(Instrument::AcousticGrandPiano);
piano_part.add_phrase(phrase_to_repeat.clone(), 0.);
// Create a Strings part that plays the phrase from beat 0.5
// (at the same time as the piano but shifted half a beat)
let mut violins_part = Part::new(Instrument::StringEnsemble1);
violins_part.add_phrase(phrase_to_repeat, 0.5);
// Create a score with a tempo of 60 (one beat per second) and add both parts
let mut score = Score::new("my score", Tempo::new(60)?, None);
score.add_part(piano_part);
score.add_part(violins_part);
// Write the score to a MIDI file for playback
score.write_midi_file(File::create("readme_example.mid")?)?;
Ok(())
}pub fn duration(&self) -> f64
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Score
impl Send for Score
impl Sync for Score
impl Unpin for Score
impl UnwindSafe for Score
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