pub struct Scale { /* private fields */ }Implementations§
Source§impl Scale
impl Scale
Sourcepub fn new(tonic_pitch: u7, scale_mode: ScaleMode) -> Self
pub fn new(tonic_pitch: u7, scale_mode: ScaleMode) -> Self
Creates a new Scale
Examples found in repository?
examples/scales_example.rs (lines 13-16)
11fn main() -> Result<(), Box<dyn Error>> {
12 // Create a simple C Minor Scale on octave 4 (this requires the `composition` feature)
13 let s = Scale::new(
14 compute_pitch(NoteName::Do, Accidental::Natural, 4)?,
15 ScaleMode::Aeolian,
16 );
17
18 // Create a phrase that just plays the scale as a sequence of quavers (half beat)
19 let phrase = Phrase::from_notes_sequence(Note::new_sequence(QUAVER, MF, s.n_pitches(15)))?;
20
21 // Create a piano part that plays the phrase from beat 0
22 let mut piano_part = Part::new(Instrument::AcousticGrandPiano);
23 piano_part.add_phrase(phrase, 0.);
24
25 // Create a score with a tempo of 60 (one beat per second) and add both parts
26 let mut score = Score::new("my score", Tempo::new(60)?, None);
27 score.add_part(piano_part);
28
29 // Write the score to a MIDI file for playback
30 score.write_midi_file(File::create("scale_example.mid")?)?;
31 Ok(())
32}Sourcepub fn pitches(&self) -> ScalePitchesIterator<'static> ⓘ
pub fn pitches(&self) -> ScalePitchesIterator<'static> ⓘ
Returns an iterator that iterates over all pitches in the scale once
Sourcepub fn n_pitches(&self, num_pitches: usize) -> ScalePitchesIterator<'static> ⓘ
pub fn n_pitches(&self, num_pitches: usize) -> ScalePitchesIterator<'static> ⓘ
Returns an iterator that iterates over all pitches in the scale and can continue
on the next octaves until length pitches have been issued or the pitch has reached
a value too high for MIDI.
Examples found in repository?
examples/scales_example.rs (line 19)
11fn main() -> Result<(), Box<dyn Error>> {
12 // Create a simple C Minor Scale on octave 4 (this requires the `composition` feature)
13 let s = Scale::new(
14 compute_pitch(NoteName::Do, Accidental::Natural, 4)?,
15 ScaleMode::Aeolian,
16 );
17
18 // Create a phrase that just plays the scale as a sequence of quavers (half beat)
19 let phrase = Phrase::from_notes_sequence(Note::new_sequence(QUAVER, MF, s.n_pitches(15)))?;
20
21 // Create a piano part that plays the phrase from beat 0
22 let mut piano_part = Part::new(Instrument::AcousticGrandPiano);
23 piano_part.add_phrase(phrase, 0.);
24
25 // Create a score with a tempo of 60 (one beat per second) and add both parts
26 let mut score = Score::new("my score", Tempo::new(60)?, None);
27 score.add_part(piano_part);
28
29 // Write the score to a MIDI file for playback
30 score.write_midi_file(File::create("scale_example.mid")?)?;
31 Ok(())
32}Trait Implementations§
impl Copy for Scale
impl Eq for Scale
impl StructuralPartialEq for Scale
Auto Trait Implementations§
impl Freeze for Scale
impl RefUnwindSafe for Scale
impl Send for Scale
impl Sync for Scale
impl Unpin for Scale
impl UnwindSafe for Scale
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