Skip to main content

is_consonant

Function is_consonant 

Source
pub fn is_consonant(
    pitches: &[Pitch],
    allowable: &[Vec<u8>],
    forbidden: &[Vec<u8>],
) -> bool
Expand description

Whether notes sound consonant: music21’s isConsonant. Notes whose interval_class_set is one of the forbidden sets are dissonant, and those whose set is one of the allowable consonant; any others are as consonant as their chord is. Each set is read as a set, in any order.

use music21::Pitch;
use music21::analysis::reduce_chords::is_consonant;

let pitches = |names: &[&str]| -> Vec<Pitch> {
    names.iter().map(|name| Pitch::from_name(*name).unwrap()).collect()
};
assert!(is_consonant(&pitches(&["C4", "E4", "G4"]), &[], &[]));
assert!(!is_consonant(&pitches(&["C4", "D4"]), &[], &[]));
// A major second allowed.
assert!(is_consonant(&pitches(&["C4", "D4"]), &[vec![2]], &[]));