@@ -52,6 +52,16 @@ class MidiControllerTemplate(object):
5252 def __init__ (self , midi_input_name , midi_output_name , callback_log ):
5353 self .callback_log = callback_log
5454
55+ # LCD has 2 rows with 56 characters each, fill with spaces
56+ self ._lcd_characters = [' ' ] * 2
57+ self ._lcd_overlay_characters = [' ' ] * 2
58+
59+ for line in range (2 ):
60+ self ._lcd_characters [line ] = [' ' ] * 56
61+ self ._lcd_overlay_characters [line ] = [' ' ] * 56
62+
63+ self ._show_overlay = [False , False ]
64+
5565 self ._log ('Initialising MIDI ports...' , True )
5666 self ._midi_input_name = midi_input_name
5767 self ._midi_output_name = midi_output_name
@@ -192,14 +202,22 @@ def withdraw_all_controls(self):
192202
193203 # --- handling of Mackie Control commands ---
194204
195- def set_lcd (self , position , new_string ):
196- """
197- send string of maximum 72 bytes to controller LCD
205+ def set_lcd (self , position , hex_codes , update = True ):
206+ for hex_code in hex_codes :
207+ # wrap display and determine position
208+ position %= 112
209+ (line , pos ) = divmod (position , 56 )
198210
199- position 1: top row
200- position 2: bottom row
201- """
202- pass
211+ # convert illegal characters to asterisk
212+ if (hex_code < 0x20 ) or (hex_code > 0x7F ):
213+ self ._lcd_characters [line ][pos ] = '*'
214+ else :
215+ self ._lcd_characters [line ][pos ] = chr (hex_code )
216+
217+ position += 1
218+
219+ if update :
220+ self .update_lcd ()
203221
204222
205223 def set_led (self , internal_id , led_status ):
@@ -273,3 +291,49 @@ def faders_to_minimum(self):
273291
274292 def all_leds_off (self ):
275293 self ._log ('Hardware LEDs NOT set to "off".' )
294+
295+
296+ # --- LCD and menu handling
297+
298+ def update_lcd (self ):
299+ pass
300+
301+
302+ def get_lcd_characters (self , line ):
303+ line %= 2
304+
305+ if self ._show_overlay [line ]:
306+ return self ._lcd_overlay_characters [line ]
307+ else :
308+ return self ._lcd_characters [line ]
309+
310+
311+ def show_menu (self , line , menu_strings ):
312+ assert (len (menu_strings ) == 8 )
313+
314+ menu_string_temp = ''
315+ for menu_string in menu_strings :
316+ menu_string_temp += menu_string .center (7 )[:7 ]
317+
318+ menu_characters = list (menu_string_temp )
319+ self .show_overlay (line , menu_characters )
320+
321+
322+ def hide_menu (self , line ):
323+ self .hide_overlay (line )
324+
325+
326+ def show_overlay (self , line , overlay_characters ):
327+ line %= 2
328+ assert (len (overlay_characters ) == 56 )
329+
330+ self ._show_overlay [line ] = True
331+ self ._lcd_overlay_characters [line ] = overlay_characters
332+ self .update_lcd ()
333+
334+
335+ def hide_overlay (self , line ):
336+ line %= 2
337+
338+ self ._show_overlay [line ] = False
339+ self .update_lcd ()
0 commit comments