Scale

Struct Scale 

Source
pub struct Scale { /* private fields */ }

Implementations§

Source§

impl Scale

Source

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}
Source

pub fn pitches(&self) -> ScalePitchesIterator<'static>

Returns an iterator that iterates over all pitches in the scale once

Source

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§

Source§

impl Clone for Scale

Source§

fn clone(&self) -> Scale

Returns a duplicate 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 Scale

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Scale

Source§

fn default() -> Scale

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Scale

Source§

fn eq(&self, other: &Scale) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Scale

Source§

impl Eq for Scale

Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

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,

Source§

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

Source§

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

Source§

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.