@@ -68,7 +68,7 @@ def __init__(self, MainWindow):
68
68
]
69
69
for i ,cb in enumerate (self .midiDeviceComboBoxes ):
70
70
cb .currentIndexChanged .connect (self .choose_midi_device_for_channel (i ))
71
-
71
+ # reset midi channel buttons
72
72
self .resetButtons = [
73
73
self .resetChannel0Button ,
74
74
self .resetChannel1Button ,
@@ -92,7 +92,6 @@ def __init__(self, MainWindow):
92
92
93
93
# provide storage to remember the last 512 raw eeg data points
94
94
self .last_512_raw_waves = deque ([0 ]* RAW_VAL_WIN_SIZE , RAW_VAL_WIN_SIZE )
95
-
96
95
self .counter = 0
97
96
98
97
# reserve a notequeue to remember 3 notes on each channel
@@ -111,23 +110,29 @@ def __init__(self, MainWindow):
111
110
self .signal_quality = "unknown signal quality"
112
111
self .update_statusbar ()
113
112
113
+ # instantiate an object that can transform note names to midi numbers
114
114
self .notelookup = notelookup .NoteLookup ()
115
115
116
- # more signals
116
+ # more signals: what to do if a checkbox is clicked
117
117
self .attentionCheckBox .clicked .connect (self .attentionCheckBoxClicked )
118
118
self .meditationCheckBox .clicked .connect (self .meditationCheckBoxClicked )
119
119
self .eyeBlinkCheckBox .clicked .connect (self .eyeBlinkCheckBoxClicked )
120
120
121
+ # make sure the menu entries do something
121
122
self .actionQuit .triggered .connect (QtGui .qApp .quit )
122
123
self .actionSave_state .triggered .connect (self .save_state )
123
124
self .actionLoad_state .triggered .connect (self .load_state )
124
125
126
+ # determine which ui elements should be saved/loaded
125
127
self .setup_serialization ()
126
128
129
+ # discover the plugins and display in the ui as needed
127
130
self .setup_plugins ()
128
131
129
132
def setup_serialization (self ):
130
-
133
+ """
134
+ function that collects all information required for saving ui state to model file
135
+ """
131
136
def lineedit_getter (lineedit ):
132
137
return "{0}" .format (lineedit .text ())
133
138
@@ -168,6 +173,10 @@ def combobox_setter(combobox, value):
168
173
self .serializer .register ("eyeBlinkPluginComboBox" ,self .eyeBlinkPluginComboBox , combobox_getter , combobox_setter )
169
174
170
175
def setup_plugins (self ):
176
+ """
177
+ discover all plugins and populate the plugin combo boxes
178
+ setup signals so that selecting a plugin has some effect
179
+ """
171
180
self .prevAttentionPluginIndex = 0
172
181
self .prevMeditationPluginIndex = 0
173
182
self .prevEyeBlinkPluginIndex = 0
@@ -196,6 +205,9 @@ def setup_plugins(self):
196
205
self .eyeBlinkPluginSelected (0 )
197
206
198
207
def suspend_plugin (self , plugin_object , section ):
208
+ """
209
+ define how to suspend a running plugin without deleting it, e.g. when the checkbox is unchecked
210
+ """
199
211
plugin_object .suspend (section )
200
212
midichan = plugin_object .get_midi_channel_list (section )
201
213
for m in midichan :
@@ -204,6 +216,9 @@ def suspend_plugin(self, plugin_object, section):
204
216
self .midiOut [m ].send_message (msg )
205
217
206
218
def attentionCheckBoxClicked (self ):
219
+ """
220
+ what to do if the attention check box is clicked
221
+ """
207
222
from yapsy .PluginManager import PluginManagerSingleton
208
223
manager = PluginManagerSingleton .get ()
209
224
plugin = manager .getAllPlugins ()[self .prevAttentionPluginIndex ]
@@ -213,6 +228,9 @@ def attentionCheckBoxClicked(self):
213
228
plugin .plugin_object .resume ('attention' )
214
229
215
230
def attentionPluginSelected (self , index ):
231
+ """
232
+ what to do if an attention plugin is selected
233
+ """
216
234
from yapsy .PluginManager import PluginManagerSingleton
217
235
manager = PluginManagerSingleton .get ()
218
236
plugin = manager .getAllPlugins ()[self .prevAttentionPluginIndex ]
@@ -225,6 +243,9 @@ def attentionPluginSelected(self, index):
225
243
self .attentionCheckBoxClicked ()
226
244
227
245
def meditationCheckBoxClicked (self ):
246
+ """
247
+ what to do if meditation checkbox is clicked
248
+ """
228
249
from yapsy .PluginManager import PluginManagerSingleton
229
250
manager = PluginManagerSingleton .get ()
230
251
plugin = manager .getAllPlugins ()[self .prevMeditationPluginIndex ]
@@ -235,6 +256,9 @@ def meditationCheckBoxClicked(self):
235
256
236
257
237
258
def meditationPluginSelected (self , index ):
259
+ """
260
+ what to do if a meditation plugin is selected
261
+ """
238
262
from yapsy .PluginManager import PluginManagerSingleton
239
263
manager = PluginManagerSingleton .get ()
240
264
plugin = manager .getAllPlugins ()[self .prevMeditationPluginIndex ]
@@ -248,6 +272,9 @@ def meditationPluginSelected(self, index):
248
272
249
273
250
274
def eyeBlinkCheckBoxClicked (self ):
275
+ """
276
+ what to do if the eye blink check box is clicked
277
+ """
251
278
from yapsy .PluginManager import PluginManagerSingleton
252
279
manager = PluginManagerSingleton .get ()
253
280
plugin = manager .getAllPlugins ()[self .prevEyeBlinkPluginIndex ]
@@ -257,6 +284,9 @@ def eyeBlinkCheckBoxClicked(self):
257
284
plugin .plugin_object .resume ('eyeBlink' )
258
285
259
286
def eyeBlinkPluginSelected (self , index ):
287
+ """
288
+ what to do if an eye blink plugin is selected
289
+ """
260
290
from yapsy .PluginManager import PluginManagerSingleton
261
291
manager = PluginManagerSingleton .get ()
262
292
plugin = manager .getAllPlugins ()[self .prevEyeBlinkPluginIndex ]
@@ -269,6 +299,9 @@ def eyeBlinkPluginSelected(self, index):
269
299
self .eyeBlinkCheckBoxClicked ()
270
300
271
301
def save_state (self ):
302
+ """
303
+ get state of ui and all plugins, and save to file
304
+ """
272
305
model = self .serializer .ui_to_model ()
273
306
plugin_model = {}
274
307
from yapsy .PluginManager import PluginManagerSingleton
@@ -284,6 +317,9 @@ def save_state(self):
284
317
f .write (modelstring )
285
318
286
319
def load_state (self ):
320
+ """
321
+ get state of ui and all plugins from file, and set to the ui
322
+ """
287
323
with open ("midicontroller-state.json" , "r" ) as f :
288
324
modelstring = f .read ()
289
325
import json
@@ -304,6 +340,9 @@ def load_state(self):
304
340
305
341
306
342
def quit_gracefully (self ):
343
+ """
344
+ switch off all playing notes and delete all plugins
345
+ """
307
346
for i ,mo in enumerate (self .midiOut ):
308
347
bytemsg = self .notequeue .clear_notes (i )
309
348
for msg in bytemsg :
@@ -316,7 +355,7 @@ def quit_gracefully(self):
316
355
317
356
def monitor (self ):
318
357
"""
319
- start/stop button
358
+ start/stop button pressed
320
359
"""
321
360
print "monitor"
322
361
if self .running :
@@ -354,10 +393,16 @@ def monitor(self):
354
393
self .update_statusbar ()
355
394
356
395
def handle_poor_signal (self , headset , value ):
396
+ """
397
+ react to a poor signal event
398
+ """
357
399
self .signal_quality = "poor signal quality {0}%" .format (value )
358
400
self .MainWindow .update_statusbar_signal .emit ()
359
401
360
402
def handle_good_signal (self , headset , value ):
403
+ """
404
+ handle to a good signal event
405
+ """
361
406
self .signal_quality = "good signal quality"
362
407
self .MainWindow .update_statusbar_signal .emit ()
363
408
0 commit comments