Пример #1
0
 def test_note_equality(self):
     note1 = Note(0, 1, 1, (3, 4))
     self.assertEquals(note1, note1)
     self.assertEquals(note1, Note(0, 1, 1, (3, 4)))
     note1b = Note(0, 1, 1, (3, 4))
     note2 = Note(0, -1, 0, (1, 2))
     self.assertNotEquals(note1, note2)
Пример #2
0
 def test_song_items(self):
     region = as_region(' [C] c e | [Am] ')
     song_items = list(SongItems.parse(region))
     expected_song_items = [
         Chord(ScaleNote(0), descriptor=''),
         Note(0),
         Note(2),
         BarLine(),
         Chord(ScaleNote(5), descriptor='m')
     ]
     self.assertEquals(song_items, expected_song_items)
     self.assertEquals(song_items[0].source.value, '[C]')
     self.assertEquals(song_items[3].source.value, '|')
Пример #3
0
    def test_note_parse(self):
        region = as_region("a+'3q")
        note = Note.parse(region)
        self.assertEquals(note.source, region)
        self.assertEquals(note, Note(5, 1, 1, (3, 4)))
        self.assertEquals(note.semitone_offset, 10)
        region = as_region("a")
        note = Note.parse(region)
        self.assertEquals(note.source, region)
        self.assertEquals(note, Note(5))

        region = as_region("a+,3q")
        note = Note.parse(region)
        self.assertEquals(note, Note(5, 1, -1, (3, 4)))
Пример #4
0
 def test_parse_tied_notes_song_item(self):
     region = as_region('~a+3q')
     parsed_item = SongItem.parse(region)
     self.assertEquals(parsed_item,
                       Note(5, 1, duration=(3, 4), continued=True))
     region = as_region('a+3q~')
     parsed_item = SongItem.parse(region)
     self.assertEquals(parsed_item,
                       Note(5, 1, duration=(3, 4), to_continue=True))
     region = as_region('~a+3q~')
     parsed_item = SongItem.parse(region)
     self.assertEquals(
         parsed_item,
         Note(5, 1, duration=(3, 4), to_continue=True, continued=True))
Пример #5
0
    def test_subticks(self):
        song_lines = """
            *song:         tempo_bpm=120, ticks_per_beat=4, subticks_per_tick = 5
                 | [C] c 
"""
        parse_string = StringToParse('test_string', song_lines)
        song = Song.parse(parse_string)
        self.assertEqualsDisplaying(
            song,
            Song([
                SongValuesCommand([
                    SetSongTempoBpm(120),
                    SetSongTicksPerBeat(4),
                    SetSongSubTicksPerTick(5)
                ]),
                BarLine(),
                Chord(ScaleNote(0), descriptor=''),
                Note(0, duration=(1, 1))
            ]))
Пример #6
0
    def test_note_parse(self):
        region = as_region('a+\'3q')
        note = Note.parse(region)
        self.assertEquals(note.source, region)
        self.assertEquals(note, Note(5, 1, 1, (3, 4)))
        self.assertEquals(note.semitone_offset, 10)
        region = as_region('a')
        note = Note.parse(region)
        self.assertEquals(note.source, region)
        self.assertEquals(note, Note(5))

        region = as_region('a+,3q')
        note = Note.parse(region)
        self.assertEquals(note, Note(5, 1, -1, (3, 4)))
Пример #7
0
    def test_parse_song_cut(self):
        song_lines = """
            *song:         tempo_bpm=120, ticks_per_beat=4
                 | [C] c e 
                 [:FAC] e 
                 ! c | [G] r2
"""
        parse_string = StringToParse('test_string', song_lines)
        song = Song.parse(parse_string)
        self.assertEqualsDisplaying(
            song,
            Song([
                SongValuesCommand(
                    [SetSongTempoBpm(120),
                     SetSongTicksPerBeat(4)]),
                Note(0, duration=(1, 1)),
                BarLine(),
                Chord(ScaleNote(4), descriptor=''),
                Rest((2, 1))
            ]))
Пример #8
0
    def test_parse_song(self):
        parse_string = StringToParse('test_string', self.song_lines)
        song = Song.parse(parse_string)
        self.assertEqualsDisplaying(
            song,
            Song([
                SongValuesCommand(
                    [SetSongTempoBpm(120),
                     SetSongTicksPerBeat(4)]),
                TrackValuesCommand('chord',
                                   [SetTrackOctave(2),
                                    SetTrackInstrument(40)]),
                TrackValuesCommand(
                    'bass',
                    [SetTrackOctave(1), SetTrackVolume(90)]),
                Chord(ScaleNote(0), descriptor=''),
                Note(0, duration=(1, 1)),
                Note(2, duration=(1, 1)),
                Chord(ScaleNote(3), other_notes=[ScaleNote(5),
                                                 ScaleNote(0)]),
                Note(2, duration=(1, 1)),
                Note(0, duration=(1, 2)),
                Note(0, duration=(1, 2)),
                BarLine(),
                Chord(ScaleNote(4), descriptor=''),
                Note(4, duration=(1, 1)),
                Rest((2, 1))
            ]))
        chord_track = song.tracks['chord']
        self.assertEquals(chord_track.instrument, 40)
        self.assertEquals(song.tracks['bass'].volume, 90)
        self.assertEquals(len(chord_track.items), 3)
        self.assertEquals(len(song.tracks['melody'].items), 6)

        self.assertEquals(chord_track.items[0].midi_notes, [36, 40, 43])
        self.assertEquals(chord_track.items[1].bass_midi_note, 29)
        self.assertEquals(song.bar_ticks, [0, 16, 32])
Пример #9
0
 def test_parse_note_song_item(self):
     region = as_region("a+'3q")
     parsed_item = SongItem.parse(region)
     region = as_region("a+'3q")
     parsed_note = Note.parse(region)
     self.assertEquals(parsed_item, parsed_note)
Пример #10
0
 def test_note_parse_exception(self):
     with self.parse_exception('Invalid note: "a+\'3qmexico" (extra data "mexico")', "mexico"):
         region = as_region("a+'3qmexico")
         Note.parse(region)
Пример #11
0
 def test_note_unparse(self):
     note1 = Note(0, 1, 1, (3, 4))
     self.assertEquals(note1.unparse(), "c+'3q")
     note1 = Note(0, 1, -1, (3, 4))
     self.assertEquals(note1.unparse(), "c+,3q")
Пример #12
0
 def test_parse_note_song_item(self):
     region = as_region('a+\'3q')
     parsed_item = SongItem.parse(region)
     region = as_region('a+\'3q')
     parsed_note = Note.parse(region)
     self.assertEquals(parsed_item, parsed_note)
Пример #13
0
 def test_note_parse_exception(self):
     with self.parse_exception(
             'Invalid note: "a+\'3qmexico" (extra data "mexico")',
             "mexico"):
         region = as_region('a+\'3qmexico')
         Note.parse(region)
Пример #14
0
 def test_note_unparse(self):
     note1 = Note(0, 1, 1, (3, 4))
     self.assertEquals(note1.unparse(), 'c+\'3q')
     note1 = Note(0, 1, -1, (3, 4))
     self.assertEquals(note1.unparse(), 'c+,3q')