Enum musical_note::Scale
source · pub enum Scale {
Major,
Minor,
Dorian,
Phrygian,
Lydian,
Mixolidyan,
Locrian,
}Variants§
Implementations§
source§impl Scale
impl Scale
sourcepub fn structure(&self) -> [u8; 6]
pub fn structure(&self) -> [u8; 6]
Get interval structure of the scale.
Examples found in repository?
src/lib.rs (line 588)
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
fn resolve_for_key(&self, notes_map: &NotesMap, key: &Key) -> ResolvedScale {
let root = key.get_root();
let (root_midi, _root_idx) = (root[0], root[1]);
let mut degree_midi = [root_midi; 7];
let mut degree_notes = [key.tonic; 7];
let mut used_accidentals = Vec::with_capacity(10);
for (idx, interval) in self.structure().iter().enumerate() {
let mut next_midi = degree_midi[idx];
next_midi += interval;
if next_midi > 11 {
next_midi %= 12;
}
let index = degree_notes[idx].0.index() + 1;
let candidate_note = NoteName::by_index(index);
// println!(
// "candidate_note: {:?}, next_midi: {:?}",
// candidate_note, next_midi
// );
let next_note = notes_map
.resolve_note_for_midi((candidate_note, Accidental::White), next_midi)
.unwrap();
degree_notes[idx + 1] = next_note;
degree_midi[idx + 1] = next_midi;
if next_note.1 != Accidental::White {
used_accidentals.push(next_note.1);
}
// println!(
// "next_note: {:?}, degree_notes: {:?}, degree_midi: {:?}, used_accidentals: {:?}",
// next_note, degree_notes, degree_midi, used_accidentals
// )
}
ResolvedScale {
key: *key,
degree_midi,
degree_notes,
used_accidentals,
}
}Trait Implementations§
source§impl<'de> Deserialize<'de> for Scale
impl<'de> Deserialize<'de> for Scale
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq<Scale> for Scale
impl PartialEq<Scale> for Scale
source§impl PartialOrd<Scale> for Scale
impl PartialOrd<Scale> for Scale
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read more