aboutsummaryrefslogtreecommitdiffstats
path: root/midi_launchpad_mini_unittest.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2022-01-01 10:18:37 +0100
committerEddy Pedroni <eddy@0xf7.com>2022-01-01 10:18:37 +0100
commit71f6a49110b6696ca6ac7956baa4edaa1aaa9527 (patch)
treee16178d2db8c6a8b7459801aab34d46255d4e8f6 /midi_launchpad_mini_unittest.py
parent9090422b2ba5eab9e4131f9b9281ed83128d977c (diff)
Added partial Launchpad support, refactored existing files
Diffstat (limited to 'midi_launchpad_mini_unittest.py')
-rw-r--r--midi_launchpad_mini_unittest.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/midi_launchpad_mini_unittest.py b/midi_launchpad_mini_unittest.py
new file mode 100644
index 0000000..09f12df
--- /dev/null
+++ b/midi_launchpad_mini_unittest.py
@@ -0,0 +1,107 @@
+from midi_controller_launchpad_mini import MidiController
+
+class MidiWrapperMock:
+ def __init__(self):
+ self.callback = None
+ self.connectedDevice = None
+ self.lastMessageSent = None
+
+ def setCallback(self, callback):
+ self.callback = callback
+
+ def connect(self, deviceName):
+ self.connectedDevice = deviceName
+
+ def sendMessage(self, note, velocity=127, channel=0):
+ pass
+
+ def simulateInput(self, note, velocity=127, channel=0):
+ if self.callback is not None:
+ from mido import Message
+ msg = Message("note_on", note=note, velocity=velocity, channel=channel)
+ self.callback(msg)
+
+class SoloToolMock:
+ STOPPED = 0
+ PLAYING = 1
+ PAUSED = 2
+
+ def __init__(self):
+ self.state = SoloToolMock.STOPPED
+ self.position = 0.0
+ self.currentAbLimit = (0.0, 0.0)
+
+ def play(self):
+ self.state = SoloToolMock.PLAYING
+
+ def pause(self):
+ self.state = SoloToolMock.PAUSED
+
+ def stop(self):
+ self.state = SoloToolMock.STOPPED
+
+ def isPlaying(self):
+ return self.state == SoloToolMock.PLAYING
+
+ def jumpToA(self):
+ self.position = self.currentAbLimit[0]
+
+def test_connect():
+ expectedDevice = "Launchpad Mini MIDI 1"
+
+ soloToolMock = SoloToolMock()
+ midiWrapperMock = MidiWrapperMock()
+ uut = MidiController(soloToolMock, midiWrapperMock)
+ uut.connect()
+
+ assert midiWrapperMock.connectedDevice == expectedDevice
+
+def test_startStopAndPauseButtons():
+ playPauseButton = 112
+ stopButton = 96
+
+ soloToolMock = SoloToolMock()
+ midiWrapperMock = MidiWrapperMock()
+ uut = MidiController(soloToolMock, midiWrapperMock)
+ uut.connect()
+
+ assert soloToolMock.state == SoloToolMock.STOPPED
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ assert soloToolMock.state == SoloToolMock.PLAYING
+
+ midiWrapperMock.simulateInput(stopButton)
+ assert soloToolMock.state == SoloToolMock.STOPPED
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ midiWrapperMock.simulateInput(playPauseButton)
+ assert soloToolMock.state == SoloToolMock.PAUSED
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ assert soloToolMock.state == SoloToolMock.PLAYING
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ midiWrapperMock.simulateInput(stopButton)
+ assert soloToolMock.state == SoloToolMock.STOPPED
+
+def test_jumpToAButton():
+ ab = (0.5, 0.6)
+ soloToolMock = SoloToolMock()
+ midiWrapperMock = MidiWrapperMock()
+ uut = MidiController(soloToolMock, midiWrapperMock)
+ uut.connect()
+
+ soloToolMock.currentAbLimit = (ab[0], ab[1])
+ assert soloToolMock.position == 0.0
+
+ midiWrapperMock.simulateInput(101)
+ assert soloToolMock.position == ab[0]
+
+def test_unprogrammedButton():
+ unusedButton = 48
+ midiWrapperMock = MidiWrapperMock()
+ uut = MidiController(None, midiWrapperMock)
+ uut.connect()
+
+ # expect no crash
+ midiWrapperMock.simulateInput(48)