def test_process_midi_types_cc(self): s = sol.Sol() state = sol.State() msg = make_message(smolmidi.CC, 42, 64) s._process_midi(msg, state) assert math.isclose(state.cc(42), 0.5, rel_tol=0.01)
def test_process_midi_types_pressure(self): s = sol.Sol() state = sol.State() msg = make_message(smolmidi.CHANNEL_PRESSURE, 64) s._process_midi(msg, state) assert math.isclose(state.pressure, 0.5, rel_tol=0.01)
def test_run_loop_note_on_note_off(self): count = 0 def loop(previous, current, outputs): nonlocal count if count == 0: assert previous.note is None assert current.note == 42 elif count == 1: assert previous.note == 42 assert current.note is None else: raise sol._StopLoop count += 1 # Add data to the midi stub usb_midi.ports[0].data = iter( [smolmidi.NOTE_ON, 42, 64, smolmidi.NOTE_OFF, 42, 0] ) s = sol.Sol() s.run(loop) assert count == 2
def test_process_midi_types_pitch_bend(self): s = sol.Sol() state = sol.State() msg = make_message(smolmidi.PITCH_BEND, 0x00, 0x40) s._process_midi(msg, state) assert state.pitch_bend == 0 msg = make_message(smolmidi.PITCH_BEND, 0x00, 0x00) s._process_midi(msg, state) assert state.pitch_bend == -1 msg = make_message(smolmidi.PITCH_BEND, 0x00, 0x80) s._process_midi(msg, state) assert state.pitch_bend == 1
def test_run_loop_simple(self): def loop(previous, current, outputs): assert previous.note is None assert current.note == 42 assert math.isclose(current.velocity, 0.5, rel_tol=0.01) outputs.gate_1 = True raise sol._StopLoop # Add data to the midi stub usb_midi.ports[0].data = iter([smolmidi.NOTE_ON, 42, 64]) s = sol.Sol() s.run(loop) assert s.outputs.gate_1 is True
def test_process_midi_types_note_on_off(self): s = sol.Sol() state = sol.State() msg = make_message(smolmidi.NOTE_ON, 42, 64) s._process_midi(msg, state) assert state.note == 42 assert math.isclose(state.velocity, 0.5, rel_tol=0.01) msg = make_message(smolmidi.NOTE_OFF, 42, 0) s._process_midi(msg, state) assert state.note is None assert state.velocity == 0 # Note on with 0 velocity should be treated as Note Off msg = make_message(smolmidi.NOTE_ON, 42, 0) s._process_midi(msg, state) assert state.note is None assert state.velocity == 0
def test_default_state(self): sol.Sol()