def test_check_log(mappings_bank1): store.update('mappings', mappings_bank1) store.update('active_bank', 1) midi = Message(type='note_on', channel=2, note=33, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 1 log(translate_and_send(ret[0]))
def test_check_memory(mappings_bank_set): store.update('mappings', mappings_bank_set) store.update('active_bank', 0) bank1_element = 2 bank2_element = 3 assert store.get('mappings')[bank1_element]['memory'] == 0 assert store.get('mappings')[bank2_element]['memory'] == 0 # no bank selected the next messages should be ignored midi = Message(type='control_change', channel=6, control=77, value=64) send_midi_through_the_stream(midi) midi = Message(type='control_change', channel=7, control=88, value=89) send_midi_through_the_stream(midi) assert store.get('active_bank') == 0 assert store.get('mappings')[bank1_element]['memory'] == 0 assert store.get('mappings')[bank2_element]['memory'] == 0 # change to bank 1 midi = Message(type='note_on', channel=4, note=55, velocity=0) send_midi_through_the_stream(midi) assert store.get('active_bank') == 1 # bank1_element should change, bank2_element unchanged midi = Message(type='control_change', channel=6, control=77, value=78) send_midi_through_the_stream(midi) midi = Message(type='control_change', channel=7, control=88, value=89) send_midi_through_the_stream(midi) assert store.get('mappings')[bank1_element]['memory'] == 78 assert store.get('mappings')[bank2_element]['memory'] == 0 # change to bank 2 midi = Message(type='note_on', channel=5, note=66, velocity=0) send_midi_through_the_stream(midi) assert store.get('active_bank') == 2 # bank2_element should change, bank1_element unchanged midi = Message(type='control_change', channel=6, control=77, value=127) send_midi_through_the_stream(midi) midi = Message(type='control_change', channel=7, control=88, value=89) send_midi_through_the_stream(midi) assert store.get('mappings')[bank1_element]['memory'] == 78 assert store.get('mappings')[bank2_element]['memory'] == 89 # change to bank 1 midi = Message(type='note_on', channel=4, note=55, velocity=0) send_midi_through_the_stream(midi) assert store.get('active_bank') == 1 # bank1_element should change, bank2_element unchanged midi = Message(type='control_change', channel=6, control=77, value=127) send_midi_through_the_stream(midi) midi = Message(type='control_change', channel=7, control=88, value=89) send_midi_through_the_stream(midi) assert store.get('mappings')[bank1_element]['memory'] == 127 assert store.get('mappings')[bank2_element]['memory'] == 89
def test_real_time1(send_message_mock, mappings_real_time): store.update('mappings', mappings_real_time) midi = Message(type='note_on', channel=0, note=1, velocity=127) send_midi_through_the_stream(midi) assert send_message_mock.called is True assert send_message_mock.call_count == 1 cmd = mappings_real_time[0]['o-type'] expected = call({ 'type': cmd, 'channel': None, 'status': None, 'level': None }) assert send_message_mock.call_args == expected
def test_get_translations_bank_set(mappings_bank_set): store.update('mappings', mappings_bank_set) store.update('active_bank', 0) midi = Message(type='note_on', channel=15, note=1, velocity=0) send_midi_through_the_stream(midi) assert store.get('active_bank') == 0 midi = Message(type='note_on', channel=4, note=55, velocity=0) send_midi_through_the_stream(midi) assert store.get('active_bank') == 1 midi = Message(type='note_on', channel=5, note=66, velocity=0) send_midi_through_the_stream(midi) assert store.get('active_bank') == 2
def test_set_bank(mappings_bank_set): store.update('mappings', mappings_bank_set) store.update('active_bank', 0) assert store.get('active_bank') == 0 set_bank(6) assert store.get('active_bank') == 0 set_bank(12) assert store.get('active_bank') == 0 set_bank(121) assert store.get('active_bank') == 0 set_bank(1) assert store.get('active_bank') == 1 set_bank(2) assert store.get('active_bank') == 2 set_bank(1, initial=True) assert store.get('active_bank') == 1
def test_set_program1(set_program_mock, mappings_set_program): store.update('mappings', mappings_set_program) store.update('active_bank', 0) assert set_program_mock.called is False assert set_program_mock.call_count == 0 # Program change 1 midi = Message(type='note_on', channel=8, note=99, velocity=127) send_midi_through_the_stream(midi) assert set_program_mock.called is True assert set_program_mock.call_count == 1 expected = int(mappings_set_program[0]['o-control']) set_program_mock.assert_called_with(expected) # Program change 2 midi = Message(type='note_on', channel=9, note=111, velocity=127) send_midi_through_the_stream(midi) expected = int(mappings_set_program[1]['o-control']) set_program_mock.assert_called_with(expected) assert set_program_mock.call_count == 2
def test_set_program2(send_message_mock, mappings_set_program): store.update('mappings', mappings_set_program) store.update('active_bank', 0) assert send_message_mock.called is False assert send_message_mock.call_count == 0 # Program change 1 midi = Message(type='note_on', channel=8, note=99, velocity=127) send_midi_through_the_stream(midi) assert send_message_mock.called is True assert send_message_mock.call_count == 3 calls = send_message_mock.call_args_list assert calls[0][0][0]['type'] == 'note_on' assert calls[1][0][0]['type'] == 'program_change' assert calls[2][0][0]['type'] == 'note_off' # Program change 2 midi = Message(type='note_on', channel=9, note=111, velocity=127) send_midi_through_the_stream(midi) assert send_message_mock.call_count == 6 calls = send_message_mock.call_args_list assert calls[3][0][0]['type'] == 'note_off' assert calls[4][0][0]['type'] == 'note_on' assert calls[5][0][0]['type'] == 'program_change'
def test_translate_and_send1(mappings_bank1): store.update('mappings', mappings_bank1) store.update('active_bank', 0) midi = Message(type='note_on', channel=0, note=11, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 0 store.update('active_bank', 1) midi = Message(type='note_on', channel=2, note=33, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 1 ret = translate_and_send(ret[0]) assert ret['type'] == midi.type assert int(ret['channel']) == midi.channel + 1 assert int(ret['control']) == midi.note
def test_calculate_range(mappings_bank_set): store.update('mappings', mappings_bank_set) store.update('active_bank', 1) midi = Message(type='control_change', channel=6, control=77, value=17) ret = send_midi_through_the_stream(midi) expected = calculate_range(ret['o-range'], 17) assert ret['o-level'] == expected midi = Message(type='control_change', channel=6, control=77, value=101) ret = send_midi_through_the_stream(midi) expected = calculate_range(ret['o-range'], 101) assert ret['o-level'] == expected store.update('active_bank', 2) midi = Message(type='control_change', channel=7, control=88, value=89) ret = send_midi_through_the_stream(midi) expected = calculate_range(ret['o-range'], 89) assert ret['o-level'] == expected
def test_get_translations_bank1(mappings_bank1): # Ensure mappings are set for these tests store.update('mappings', mappings_bank1) store.update('active_bank', 0) midi = Message(type='note_off', channel=0, note=1, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 0 midi = Message(type='note_on', channel=0, note=1, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 0 # change bank store.update('active_bank', 1) midi = Message(type='note_on', channel=2, note=33, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 1
def test_get_translations_bank0(mappings_bank0): # Ensure mappings are set for these tests store.update('mappings', mappings_bank0) store.update('active_bank', 0) midi = Message(type='note_off', channel=0, note=1, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 0 midi = Message(type='note_on', channel=15, note=1, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 0 midi = Message(type='note_on', channel=0, note=127, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 0 midi = Message(type='note_on', channel=0, note=11, velocity=0) ret = get_translations(process_midi(midi)) assert len(ret) == 1 midi = Message(type='control_change', channel=15, control=2, value=64) ret = get_translations(process_midi(midi)) assert len(ret) == 0 midi = Message(type='control_change', channel=0, control=127, value=64) ret = get_translations(process_midi(midi)) assert len(ret) == 0 midi = Message(type='control_change', channel=1, control=22, value=64) ret = get_translations(process_midi(midi)) assert len(ret) == 1 # bank0 mappings are not affected by setting the bank store.update('active_bank', 1) ret = get_translations(process_midi(midi)) assert len(ret) == 1
def test_real_time2(mappings_real_time): store.update('mappings', mappings_real_time) midi = Message(type='note_on', channel=0, note=1, velocity=127) send_midi_through_the_stream(midi)