-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.py
82 lines (73 loc) · 2 KB
/
interface.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import wave
import pyaudio
import threading
import sys
import collections
from audio import *
from player import *
def interface(project, player):
def trymap(x):
try:
if int(x) == float(x):
return int(x)
return float(x)
except("Oops"):
return x
commands = {
'add_wav': project.add_wav,
'add_mp3': project.add_mp3,
'trackpoint': project.set_point,
'trackpoints': project.trackpoints,
'change_speed': project.change_speed,
'change_volume': project.change_volume,
'reverse': project.reverse,
'play': player.play,
'select': project.select,
'line': project.fragments,
'in_line': project.add_to_line,
'out_line': project.remove_from_line,
'export_line': project.export
}
while True:
line = organize(input(), '"', '\'')
print(line)
command = line[0]
if command == 'quit':
project.close()
break
args = []
if len(line) > 1:
args = map(trymap, line[1:])
if command in commands:
try:
result = commands[command]
if isinstance(result, type(project.add_wav)):
result = result(*args)
if isinstance(result, (int, str, float, list)):
print(result)
except Exception as ex:
print('Wrong count of arguments', ex)
def organize(line, *args):
result = []
current = ''
sym = ''
for i in line:
if i in args and sym == '':
sym = i
continue
if i == sym or i == ' ' and not sym:
result.append(current)
sym = ''
current = ''
continue
current += i
if current:
result.append(current)
return result
def main():
project = Project()
player = Player()
interface(project, player)
if __name__ == "__main__":
main()