git.s-ol.nu hw/0x33.board/firmware / 89e6f84
perf: less OLED redraws in base s-ol 2 months ago
4 changed file(s) with 31 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
100100 self.mode = self.modes["base"]
101101
102102 self.settings.load()
103 self.mode.update_display()
103 self.mode.update_scale()
104104
105105 def on_midi_ch_usb(self, ch): self.midi_usb.out_channel = ch
106106 def on_midi_ch_trs(self, ch): self.midi_trs.out_channel = ch
1616 scale_label: label.Label
1717 notes_label: label.Label
1818
19 _notes_dirty: bool
20
1921 def __init__(self, *args):
2022 super().__init__(*args)
2123
2224 self.keys = [Key(self.keyboard, i) for i in range(48)]
2325 self.notes = {}
2426 self.notes_expiring = {}
27
28 self._notes_dirty = False
2529
2630 self.scale_label = label.Label(FONT_10, text="", color=0xffffff, anchor_point=(0, 0), anchored_position=(0, 0))
2731 self.notes_label = label.Label(FONT_10, text="", color=0xffffff, anchor_point=(0, 0), anchored_position=(10, 12))
4751 def update_scale(self):
4852 for key in self.keys:
4953 key.update_scale()
50 self.update_display()
54
55 self.scale_label.text = self.keyboard.scale.format()
5156
5257 def tick(self, ticks_ms: int):
5358 for note in self.notes_expiring.values():
5459 note.update_expiry(ticks_ms)
55
56 def update_display(self):
57 self.scale_label.text = self.keyboard.scale.format()
58
59 active = [pitch for pitch in self.notes]
60 active.sort()
61 self.notes_label.text = ' '.join(self.keyboard.scale.label(p) for p in active)
6260
6361 def update_pixels(self, pixels: NeoPixel):
6462 pixels.fill(0)
6664
6765 for key in self.keys:
6866 pixels[led_map[key.i]] = key.update_color()
67
68 if self._notes_dirty:
69 active = [pitch for pitch in self.notes]
70 active.sort()
71 self.notes_label.text = ' '.join(self.keyboard.scale.label(p) for p in active)
72 self._notes_dirty = False
6973
7074 def key_event(self, i: int, pressed: bool) -> bool:
7175 if pressed:
9599 else:
96100 key.on_release()
97101
98 self.update_display()
102 self._notes_dirty = True
103
99104 return pressed
100105
101106
132137 ))
133138
134139 def enter(self):
135 super().enter()
136140 self.entered = supervisor.ticks_ms()
137141 self.pressed_something = False
142 self.update_display()
143 super().enter()
144
145 def update_display(self):
146 base = self.keyboard.modes["base"]
147 self.scale_label.text = base.scale_label.text
148
149 def update_pixels(self, pixels: NeoPixel):
150 base = self.keyboard.modes["base"]
151 base.update_pixels(pixels)
152 super().update_pixels(pixels)
138153
139154 def key_event(self, i: int, pressed: bool) -> bool:
140155 base = self.keyboard.modes["base"]
146161 self.keyboard.mode = self.keyboard.modes["menu"]
147162 return False
148163
149 self.keyboard.mode = self.keyboard.modes["base"]
164 self.keyboard.mode = base
150165 return False
151166
152167 if not pressed:
156171 key = base.keys[i]
157172 self.keyboard.settings.get("scale_root").value = key._pitch
158173 self.keyboard.settings.dispatch("scale_root")
159 base.update_display()
160174 self.pressed_something = True
161175 return False
162176
163177 if i == Key.PREV_I:
164178 self.keyboard.settings.get("scale_name").press_prev()
165179 self.keyboard.settings.dispatch("scale_name")
166 base.update_display()
167180 self.pressed_something = True
168181 return False
169182
170183 if i == Key.NEXT_I:
171184 self.keyboard.settings.get("scale_name").press_next()
172185 self.keyboard.settings.dispatch("scale_name")
173 base.update_display()
174186 self.pressed_something = True
175187 return False
176
177 def update_display(self):
178 base = self.keyboard.modes["base"]
179 self.scale_label.text = base.scale_label.text
142142 Called when this mode becomes active.
143143 '''
144144 self.keyboard.display.show(self.group)
145 self.update_display()
146145
147146 def exit(self):
148147 '''
170169 Callback to update RGB LEDs.
171170 '''
172171 pixels[0] = hsv_to_rgb(*self.color)
173
174 def update_display(self):
175 '''
176 Callback to update self.group contents
177 '''
178 pass
216216 fill=0xffffff,
217217 ))
218218
219 def enter(self):
220 self.update_display()
221 super().enter()
222
219223 def exit(self):
220224 super().exit()
221225 self.settings.store()