def test_parse_note(self): note1 = notation.parse_note("C#'") note2 = notation.parse_note("C2") note3 = notation.parse_note("Cb8,") note4 = notation.parse_note("B#16''") self.assertEqual(note1, (1, 5, 0.25, 120)) self.assertEqual(note2, (0, 5, 0.5, 120)) self.assertEqual(note3, (11, 4, 0.125, 120)) self.assertEqual(note4, (0, 6, 0.0625, 120))
def __init__(self, value=0, octave=5, dur=0.25, volume=100): if isinstance(value, str): self.value, self.octave, self.dur, self.volume = notation.parse_note(value) else: offset, val = divmod(value, 12) self.value = val self.octave = octave + offset self.dur = dur self.volume = volume
def __init__(self, value=0, octave=5, dur=0.25, volume=100): if isinstance(value, str): self.value, self.octave, self.dur, self.volume = notation.parse_note( value) else: offset, val = divmod(value, 12) self.value = val self.octave = octave + offset self.dur = dur self.volume = volume
def __init__(self, value=0, octave=5, dur=0.25, volume=100): # if `value` is a string if isinstance(value, str): # attempt to parse the musical notation self.value, self.octave, self.dur, self.volume = notation.parse_note( value) else: # otherwise build the Note object manually # we accept any number for the value # but break it up into the octave offset and the note value # the note value is the given value mod 12 # the octave offset is floor( value / 12 ) + the given octave # this means we can pass in value=18, octave=0 to get note #6 in octave #1 # and we can also pass in value=30, octave=4 to get note #6 in octave #6 offset, val = divmod(value, 12) # divmod(x,y) returns (x//y, x%y) self.value = val self.octave = octave + offset self.dur = dur self.volume = volume