-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.py
182 lines (152 loc) · 4.83 KB
/
display.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
""" This file contains the Display object which generates a command line display interface."""
import curses
INDENT = 3
WORD_LEN = 20
PHASE_LINE = 4
TEMPO_LINE = 6
SPEED_LINE = 7
SYNC_LINE = 8
MODE_LINE = 10
BRIGHT_LINE = 11
SATURATION_LINE = 12
ALT_LINE = 13
MUTE_MODE_LINE = 15
MUTE_LINE = 16
DEBUG_LINE = 17
FREQ_LINE = 18
WIN_HEIGHT = 20
WIN_WIDTH = 80
class Display:
def __init__(self):
curses.initscr()
self.s = curses.newwin(WIN_HEIGHT, WIN_WIDTH, 0, 0)
curses.noecho()
curses.cbreak()
self.s.keypad(1)
self.s.nodelay(1)
self.s.addstr(0, 0, "____ _ _ ____ ____ ___ _ _ ____ _ _ ____ _ _ ___ ____ ")
self.s.addstr(1, 0, "|__| | | | | |___ | |__| |___ | | | __ |__| | [__ ")
self.s.addstr(2, 0, "| | |___ |___ |__| | | | | |___ |___ | |__] | | | ___] ")
self.s.addstr(TEMPO_LINE,
INDENT,
"(space) Tempo: ")
self.s.addstr(MODE_LINE,
INDENT,
"(asdfg) Mode: ")
self.s.addstr(BRIGHT_LINE,
INDENT,
" (< >) Brightness: ")
self.s.addstr(SPEED_LINE,
INDENT,
" (^ v) Speed: ")
self.s.addstr(SATURATION_LINE,
INDENT,
" (- +) Saturation: ")
self.s.addstr(ALT_LINE,
INDENT,
" (b) Alt: ")
self.s.addstr(MUTE_MODE_LINE,
INDENT,
" (qwe) Mute Mode: ")
self.s.addstr(MUTE_LINE,
INDENT,
"(enter) Mute: ")
self.s.addstr(SYNC_LINE,
INDENT,
" (c) Sync")
self.s.refresh()
def getch(self):
return self.s.getch()
def update(self,
tempo,
mode,
brightness,
speed,
saturation,
phase,
direction,
mute_name,
mute,
alt):
self.set_field("tempo", tempo)
self.set_field("mode", mode)
self.set_field("brightness", brightness)
self.set_field("speed", speed)
self.set_field("saturation", saturation)
self.set_field("mute_mode", mute_name)
self.set_field("mute", mute)
self.set_field("alt", alt)
self.draw_phase(phase, direction, speed)
self.s.move(1,19)
self.s.refresh()
def set_field(self, cat, val, indent=3, word_len=0):
if cat == "tempo":
line = TEMPO_LINE
word_len = WORD_LEN
string = str(round(val, 1))
elif cat == "debug":
line = DEBUG_LINE
string = str(val)
elif cat == "freq":
line = FREQ_LINE
string = str(val)
elif cat == "mode":
line = MODE_LINE
word_len = WORD_LEN
string = str(val)
elif cat == "brightness":
line = BRIGHT_LINE
word_len = WORD_LEN
string = str(int(round(val, 2) * 100)) + "%"
elif cat == "speed":
line = SPEED_LINE
word_len = WORD_LEN
if val >= 1:
string = str(int(val)) + "x"
else:
n, d = (val).as_integer_ratio()
string = "{}/{}".format(n, d) + "x"
elif cat == "saturation":
line = SATURATION_LINE
word_len = WORD_LEN
string = str(int(val * 100)) + "%"
elif cat == "mute_mode":
line = MUTE_MODE_LINE
word_len = WORD_LEN
string = val
elif cat == "mute":
line = MUTE_LINE
word_len = WORD_LEN
if val:
string = "On"
else:
string = "Off"
elif cat == "alt":
line = ALT_LINE
word_len = WORD_LEN
if val:
string = "On"
else:
string = "Off"
self.s.move(line, indent + word_len)
self.s.clrtoeol()
self.s.addstr(line, indent + word_len, string)
def draw_phase(self, phase, direction, multiplier, size=30):
step = 1. / size
p = phase // step
if direction == 1:
p = size - p
self.s.move(PHASE_LINE, INDENT)
self.s.clrtoeol()
self.s.addstr("|")
for i in range(size):
if i == p:
self.s.addstr("X")
else:
self.s.addstr(" ")
self.s.addstr("|")
def close(self):
curses.nocbreak()
self.s.keypad(0)
curses.echo()
curses.endwin()