aboutsummaryrefslogtreecommitdiffstats
path: root/cli-project
diff options
context:
space:
mode:
Diffstat (limited to 'cli-project')
-rw-r--r--cli-project/pyproject.toml24
-rw-r--r--cli-project/src/solo_tool_cli.py57
-rw-r--r--cli-project/test/solo_tool_cli_integrationtest.py41
-rw-r--r--cli-project/test/test.flacbin0 -> 31743252 bytes
-rw-r--r--cli-project/test/test.mp3bin0 -> 5389533 bytes
-rw-r--r--cli-project/test/test_session.json13
6 files changed, 135 insertions, 0 deletions
diff --git a/cli-project/pyproject.toml b/cli-project/pyproject.toml
new file mode 100644
index 0000000..7d31a09
--- /dev/null
+++ b/cli-project/pyproject.toml
@@ -0,0 +1,24 @@
+[build-system]
+requires = ["setuptools"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "solo_tool_cli"
+authors = [
+ { name = "Eddy Pedroni", email = "epedroni@pm.me" },
+]
+description = "A CLI frontend for the solo_tool library"
+requires-python = ">=3.12"
+dependencies = [
+ "solo_tool"
+]
+dynamic = ["version"]
+
+[project.optional-dependencies]
+dev = [
+ "pytest"
+]
+
+[project.scripts]
+solo-tool-cli = "solo_tool_cli:main"
+
diff --git a/cli-project/src/solo_tool_cli.py b/cli-project/src/solo_tool_cli.py
new file mode 100644
index 0000000..1c8a7d6
--- /dev/null
+++ b/cli-project/src/solo_tool_cli.py
@@ -0,0 +1,57 @@
+import sys
+import time
+import threading
+
+from solo_tool import SoloTool
+from solo_tool.midi_controller_launchpad_mini import MidiController
+
+class SoloToolCLI:
+ def __init__(self, sessionJson, soloToolOverride=None, midiOverride=None, tickEnable=True):
+ self._soloTool = SoloTool() if soloToolOverride is None else soloToolOverride
+ self._soloTool.loadSession(sessionJson)
+ self._midiController = MidiController(self._soloTool) if midiOverride is None else midiOverride
+ self._commands = {
+ "song" : self._song,
+ "midi" : self._midi
+ }
+ if tickEnable:
+ self._tick()
+
+ def input(self, commandString):
+ split = commandString.strip().split(" ")
+ if split[0] in self._commands:
+ self._commands[split[0]](split[1:])
+
+ def _song(self, args):
+ if len(args) > 0:
+ self._soloTool.setSong(int(args[0]))
+ else:
+ songs = self._soloTool.getSongs()
+ print("Songs:")
+ for i, s in enumerate(songs):
+ print(f" {i} {s}")
+
+ def _midi(self, args):
+ if len(args) > 0 and args[0] == "connect":
+ print("Connecting to MIDI device...")
+ self._midiController.connect()
+ else:
+ print("Supported device: Novation Launchpad Mini MkII")
+
+ def _tick(self):
+ self._soloTool.tick()
+ threading.Timer(0.1, self._tick).start()
+
+def main():
+ args = sys.argv[1:]
+ if len(args) == 0:
+ print("Please provide path to session file")
+ sys.exit(1)
+
+ soloToolCli = SoloToolCLI(args[0])
+ while(True):
+ commandString = input("> ")
+ soloToolCli.input(commandString)
+
+if __name__ == '__main__':
+ main()
diff --git a/cli-project/test/solo_tool_cli_integrationtest.py b/cli-project/test/solo_tool_cli_integrationtest.py
new file mode 100644
index 0000000..c29a223
--- /dev/null
+++ b/cli-project/test/solo_tool_cli_integrationtest.py
@@ -0,0 +1,41 @@
+import pytest
+import io
+from contextlib import redirect_stdout
+
+from solo_tool_cli import SoloToolCLI
+from solo_tool import SoloTool
+
+class MockMidiController:
+ def __init__(self, soloTool):
+ self.connected = False
+
+ def connect(self):
+ self.connected = True
+
+@pytest.fixture
+def soloTool():
+ return SoloTool()
+
+@pytest.fixture
+def mockMidi(soloTool):
+ return MockMidiController(soloTool)
+
+@pytest.fixture
+def uut(soloTool, mockMidi):
+ return SoloToolCLI("test_session.json", soloToolOverride=soloTool, midiOverride=mockMidi, tickEnable=False)
+
+def test_connectMidi(uut, mockMidi):
+ expectedOutput = """\
+Supported device: Novation Launchpad Mini MkII
+Connecting to MIDI device...
+"""
+
+ with io.StringIO() as buf, redirect_stdout(buf):
+ uut.input("midi")
+ assert not mockMidi.connected
+
+ uut.input("midi connect")
+ assert mockMidi.connected
+
+ assert buf.getvalue() == expectedOutput
+
diff --git a/cli-project/test/test.flac b/cli-project/test/test.flac
new file mode 100644
index 0000000..9164735
--- /dev/null
+++ b/cli-project/test/test.flac
Binary files differ
diff --git a/cli-project/test/test.mp3 b/cli-project/test/test.mp3
new file mode 100644
index 0000000..3c353b7
--- /dev/null
+++ b/cli-project/test/test.mp3
Binary files differ
diff --git a/cli-project/test/test_session.json b/cli-project/test/test_session.json
new file mode 100644
index 0000000..f48b792
--- /dev/null
+++ b/cli-project/test/test_session.json
@@ -0,0 +1,13 @@
+[
+ {
+ "path" : "test.flac",
+ "ab_limits" : null
+ },
+ {
+ "path" : "test.mp3",
+ "ab_limits" : [
+ [0.1, 0.2],
+ [0.3, 0.4]
+ ]
+ }
+]