Ejemplo n.º 1
0
class TestPattern(unittest.TestCase):
    # TODO test setting and changing pattern length out of bounds 0<x<99
    # TODO test note collision when new note starts or ends in existing note
    # TODO test note collision when existing note starts or ends in new note
    # TODO test delete all notes and all occurrences of a note

    def set_up(self):
        self.pattern = Pattern(1)

    def test_pattern_add_note(self):
        self.set_up()
        self.pattern.add_note(create_dumb_note())
        self.assertEqual(self.pattern.tracks[0].notes[0], create_dumb_note())

    def test_cant_add_note_start_past_pattern_length(self):
        self.set_up()
        self.assertRaises(ValueError, self.pattern.add_note,
                          create_dumb_note(start_tick=384))

    @unittest.skip(
        "not sure how SP404-SX handles this need to do more research")
    def test_cant_add_note_length_past_pattern_length(self):
        self.set_up()
        self.assertRaises(ValueError, self.pattern.add_note,
                          create_dumb_note(start_tick=380, length=10))

    def test_cant_add_note_causing_13_tracks(self):
        self.set_up()
        for i in range(13):
            if i == 12:
                self.assertRaises(ValueError, self.pattern.add_note,
                                  create_dumb_note())
            else:
                self.pattern.add_note(create_dumb_note())
Ejemplo n.º 2
0
def read_pattern(bank_letter, pad_number):
    hex_data = get_hex_character_row_representation(bank_letter, pad_number)
    note_list = hex_data[:-2]
    pattern_length = int(str(hex_data[-1][2] + hex_data[-1][3]), base=16)
    pattern = Pattern(pattern_length)

    current_time = 0
    for chunk_index, note in enumerate(note_list):
        #if str(note[2] + note[3]) != '80' or len(pattern.notes) == 0:
        if str(note[2] + note[3]) != '80':
            ticks_till_next_note = int(str(note[0] + note[1]), 16)
            velocity = int(str(note[8] + note[9]), 16)
            length_ticks = int(str(note[12] + note[13] + note[14] + note[15]), 16)
            pad, bank = gen_pad_bank(pad_code=str(note[2] + note[3]), bank_switch=note[5])
            pattern.add_note(Note(bank=bank, pad=pad, velocity=velocity, length=length_ticks, start_tick=current_time))
            current_time += ticks_till_next_note
    return pattern