def test_parse_notes(self): notes1 = notation.parse_notes(["C", "D", "E"]) notes2 = notation.parse_notes(["Cb4'", "D#8,", "E#16,"]) list_notes1 = [(0, 5, 0.25, 120), (2, 5, 0.25, 120), (4, 5, 0.25, 120)] list_notes2 = [(11, 5, 0.25, 120), (3, 4, 0.125, 120), (5, 4, 0.0625, 120)] self.assertEqual(notes1, list_notes1) self.assertEqual(notes2, list_notes2)
def __init__(self, args=None): if isinstance(args, str): if args.startswith("file://"): filename = args.replace("file://", "") note_lists = notation.parse_notes(self._parse_score(filename)) else: note_lists = notation.parse_notes(args.split()) self.items = [self._make_note_or_rest(x) for x in note_lists] elif isinstance(args, collections.Iterable): if self._is_note_or_rest(args): self.items = args else: raise MusiclibError("Every argument have to be a Note or a Rest.") elif args is None: self.items = [] else: raise MusiclibError("NoteSeq doesn't accept this type of data.")
def __init__(self, args=None): if isinstance(args, str): if args.startswith("file://"): filename = args.replace("file://", "") note_lists = notation.parse_notes(self._parse_score(filename)) else: note_lists = notation.parse_notes(args.split()) self.items = [self._make_note_or_rest(x) for x in note_lists] elif isinstance(args, collections.Iterable): if self._is_note_or_rest(args): self.items = args else: raise MusiclibError( "Every argument have to be a Note or a Rest.") elif args is None: self.items = [] else: raise MusiclibError("NoteSeq doesn't accept this type of data.")
def __init__(self, args=None): if isinstance(args, str): if args.startswith("file://"): # parse a file for list of notes filename = args.replace("file://", "") note_lists = notation.parse_notes(self._parse_score(filename)) else: # parse the string assuming it's a space-separated list of notes note_lists = notation.parse_notes(args.split()) # notation.parse_notes() returns a list of lists of attributes for a Note/Rest # build the Note or Rest objects from that list self.items = [self._make_note_or_rest(x) for x in note_lists] elif isinstance(args, collections.Iterable): # if we got a list, tuple, or other iterable object # make sure everything in the iterable is a note or rest if self._is_note_or_rest(args): self.items = args else: raise MusiclibError( "Every argument have to be a Note or a Rest.") elif args is None: self.items = [] else: raise MusiclibError("NoteSeq doesn't accept this type of data.")
def test_parse_notes_dur_dot(self): notes1 = notation.parse_notes(["C4.''", "D4..", "E8."]) list_notes1 = [(0, 6, 0.375, 120), (2, 6, 0.4375, 120), (4, 6, 0.1875, 120)] self.assertEqual(notes1, list_notes1)