aboutsummaryrefslogtreecommitdiffstats
path: root/solo_tool_cli.py
blob: 8d53a3379e68824c0115b6a22fcfc3cdd7ea6ba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys

from solo_tool import SoloTool
from midi_controller_launchpad_mini import MidiController

class SoloToolCLI:
    def __init__(self, sessionJson, soloToolOverride=None, midiOverride=None):
        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
        }

    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 main(args):
    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(sys.argv[1:])