aboutsummaryrefslogtreecommitdiffstats
path: root/cli-project/src/solo_tool_cli.py
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2024-11-09 23:22:55 +0100
committerEddy Pedroni <epedroni@pm.me>2024-11-09 23:22:55 +0100
commitf676c50ba91ca6d4d0da9f77aeadc8b3fb16dc26 (patch)
treedd7cf29dff80610ec3e6179b444954a5bca3e125 /cli-project/src/solo_tool_cli.py
parentcda8197669409689be291660f93cb288ab2d31b3 (diff)
CLI improvements
Diffstat (limited to 'cli-project/src/solo_tool_cli.py')
-rw-r--r--cli-project/src/solo_tool_cli.py62
1 files changed, 19 insertions, 43 deletions
diff --git a/cli-project/src/solo_tool_cli.py b/cli-project/src/solo_tool_cli.py
index 1c8a7d6..5cc1537 100644
--- a/cli-project/src/solo_tool_cli.py
+++ b/cli-project/src/solo_tool_cli.py
@@ -1,57 +1,33 @@
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)
-
+ soloTool = SoloTool()
+ soloTool.loadSession(args[0])
+
+ def tick():
+ soloTool.tick()
+ threading.Timer(0.1, tick).start()
+
+ midiController = MidiController(soloTool)
+ midiController.connect()
+
+ try:
+ while(True):
+ time.sleep(0.1)
+ soloTool.tick()
+ except KeyboardInterrupt:
+ pass
+ finally:
+ midiController.disconnect()
+
if __name__ == '__main__':
main()