def test_progression_midi(): assert ChordProgression.from_string("""C Fm G7""").midi() == [ [ note_to_midi(("C", 4)), note_to_midi(("E", 4)), note_to_midi(("G", 4)) ], [ note_to_midi(("F", 4)), note_to_midi(("G#", 4)), note_to_midi(("C", 5)) ], [ note_to_midi(("G", 4)), note_to_midi(("B", 4)), note_to_midi(("D", 5)), note_to_midi(("F", 5)), ], ]
def midi(self) -> List[int]: """ Returns the list of MIDI note values in the chord. >>> Chord.from_name("Amajor7").midi() [69, 73, 76, 80] """ return [ note_to_midi(self.root.transpose(semitone)) for semitone in self.semitones ]
def pitch(self) -> float: """Returns the absolute pitch of the note in Hz. Examples (equalities are approximate): * `Note("A", 4).pitch() == 440.0` * `Note("A", 0).pitch() == 27.5` * `Note("C", 4).pitch() == 261.62556` """ from jchord import midi return midi.midi_to_pitch(midi.note_to_midi(self))
def pitch(self) -> float: """Returns the absolute pitch of the note in Hz. >>> Note("A", 4).pitch() 440.0 >>> Note("A", 0).pitch() 27.5 >>> Note("C", 4).pitch() 261.6255653005986 """ from jchord import midi return midi.midi_to_pitch(midi.note_to_midi(self))
def test_note_to_midi_invalid_note(): with pytest.raises(InvalidNote): note_to_midi(Note("bA", 0))
def test_note_to_midi(note, octave, midi): assert note_to_midi(Note(note, octave)) == midi assert midi_to_note(midi) == Note(note, octave)
def __sub__(self, other): """Returns the number of semitones between the two notes""" from jchord import midi return midi.note_to_midi(self) - midi.note_to_midi(other)
def midi(self) -> List[int]: """Returns the list of MIDI note values in the chord.""" return [ note_to_midi(self.root.transpose(semitone)) for semitone in self.semitones ]