-
Notifications
You must be signed in to change notification settings - Fork 11
/
tuner-gui.py
executable file
·176 lines (141 loc) · 5.48 KB
/
tuner-gui.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.8.0 on Sun Jun 12 16:56:08 2022
#
import wx
import time
import _thread
import wx.lib.agw.pygauge as PG
import zoomzt2
from argparse import ArgumentParser
global options
# begin wxGlade: dependencies
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MyFrame(wx.Frame):
pedal = None
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((400, 300))
'''
self.gauge_1 = wx.Gauge(self, wx.ID_ANY, 10)
self.gauge_2 = wx.Gauge(self, wx.ID_ANY, 10)
'''
self.gauge_1 = PG.PyGauge(self, wx.ID_ANY, 10)
self.gauge_2 = PG.PyGauge(self, wx.ID_ANY, 10)
self.gauge_1.SetValue(0)
self.gauge_2.SetValue(10)
self.gauge_1.SetBarColor(wx.WHITE)
self.gauge_1.SetBackgroundColour(wx.BLUE)
self.gauge_2.SetBarColor(wx.RED)
self.gauge_2.SetBackgroundColour(wx.WHITE)
self.label_1 = wx.StaticText(self, wx.ID_ANY, "A", style=wx.ALIGN_CENTER)
self.label_1.SetFont(wx.Font(84, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_1 = wx.Button(self, wx.ID_ANY, "Connect")
self.button_2 = wx.Button(self, wx.ID_ANY, "Disconnect")
self.choice_1 = wx.Choice(self, wx.ID_ANY, choices=["435 Hz", "436 Hz", "437 Hz", "438 Hz", "439 Hz", "440 Hz", "441 Hz", "442 Hz", "443 Hz", "444 Hz", "445 Hz"])
self.__set_properties()
self.__do_layout()
# end wxGlade
self.pedal = zoomzt2.zoomzt2()
self.ConnectPedal()
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Tuner")
self.button_2.Hide()
self.choice_1.Hide()
self.choice_1.SetSelection(5)
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3.Add(self.gauge_1, 1, wx.EXPAND, 0)
sizer_3.Add(self.gauge_2, 1, wx.EXPAND, 0)
sizer_1.Add(sizer_3, 1, wx.ALIGN_CENTER | wx.EXPAND, 0)
sizer_1.Add(self.label_1, 0, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 0)
sizer_2.Add(self.button_1, 5, wx.ALIGN_BOTTOM | wx.ALL, 0)
sizer_2.Add(self.button_2, 5, wx.ALIGN_BOTTOM | wx.ALL, 0)
sizer_2.Add(self.choice_1, 1, wx.ALIGN_BOTTOM, 0)
sizer_1.Add(sizer_2, 1, wx.ALIGN_BOTTOM, 0)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
self.Bind(wx.EVT_BUTTON, self.butConnect, self.button_1)
self.Bind(wx.EVT_BUTTON, self.butDisconnect, self.button_2)
def butConnect(self, event):
self.ConnectPedal()
self.UpdateButtons()
event.Skip()
def butDisconnect(self, event):
self.DisconnectPedal()
self.UpdateButtons()
event.Skip()
def doTuner(self):
while self.pedal.is_connected():
(note, delta) = self.pedal.tuner_read()
if note:
wx.CallAfter(self.label_1.SetLabel, note)
wx.CallAfter(self.gauge_1.SetValue, 10)
wx.CallAfter(self.gauge_2.SetValue, 0)
if delta == 0:
# perfect tuning, show Green Bar
wx.CallAfter(self.gauge_1.SetValue, 0)
wx.CallAfter(self.gauge_2.SetValue, 10)
wx.CallAfter(self.gauge_1.SetBackgroundColour, wx.GREEN)
wx.CallAfter(self.gauge_2.SetBarColor, wx.GREEN)
else:
wx.CallAfter(self.gauge_1.SetBackgroundColour, wx.BLUE)
wx.CallAfter(self.gauge_2.SetBarColor, wx.RED)
if note != "-":
if delta < 0:
wx.CallAfter(self.gauge_1.SetValue, delta+10)
if delta > 0:
wx.CallAfter(self.gauge_2.SetValue, delta)
wx.CallAfter(self.Layout)
wx.CallAfter(self.Refresh)
time.sleep(0.1)
wx.CallAfter(self.DisconnectPedal)
def UpdateButtons(self):
if self.pedal.is_connected():
self.button_1.Hide()
self.button_2.Show()
self.choice_1.Show()
else:
self.button_1.Show()
self.button_2.Hide()
self.choice_1.Hide()
self.Layout()
def ConnectPedal(self):
if self.pedal.connect(options.midiskip):
self.pedal.editor_on()
self.pedal.tuner(True)
_thread.start_new_thread(self.doTuner, ())
self.UpdateButtons()
def DisconnectPedal(self):
if self.pedal.is_connected():
self.pedal.tuner(False)
self.pedal.editor_off()
self.pedal.disconnect()
self.UpdateButtons()
# end of class MyFrame
class tuner(wx.App):
def OnInit(self):
self.Tuner = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.Tuner)
self.Tuner.Show()
return True
# end of class tuner
if __name__ == "__main__":
parser = ArgumentParser(prog="tuner-gui")
parser.add_argument("-M", "--midiskip",
help="Skip devices when connecting, ie when you have multiple pedals",
type=int, default=0, dest="midiskip")
options = parser.parse_args()
tuner = tuner(0)
tuner.MainLoop()