git.s-ol.nu hw/0x33.board/firmware / 56c2129
USB MIDI note highlighting s-ol 4 months ago
3 changed file(s) with 23 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
22 import displayio
33 from adafruit_ticks import ticks_ms
44 from adafruit_midi.system_exclusive import SystemExclusive
5 from adafruit_midi.note_on import NoteOn
6 from adafruit_midi.note_off import NoteOff
57
68 try:
79 import storage
911 except:
1012 dev_mode = False
1113
12 from .core import Mode
14 from .core import Mode, Note
1315 from .matrix import Matrix
1416 from .scale import Scale
1517 from .layout import Layout, LAYOUTS, WickiHaydenLayout
270272
271273 if self.i2c:
272274 self.i2c.tick()
275
276 msg = self.midi_usb.receive()
277 while msg:
278 if isinstance(msg, NoteOn):
279 note = Note(self, msg.note)
280 self.modes['base'].extra_notes[note.pitch] = note
281 elif isinstance(msg, NoteOff) and self.modes['base'].extra_notes:
282 del self.modes['base'].extra_notes[msg.note]
283
284 msg = self.midi_usb.receive()
285
273286
274287 self.mode.update_pixels(self.pixels)
275288
2727 self.rgb = ColorScale(self.keyboard)
2828
2929 self.notes = {}
30 self.extra_notes = {}
3031 self.notes_expiring = {}
3132
3233 self.notes_dirty = False
2828 def prepare_key(self, key: Key):
2929 in_scale = self.keyboard.scale.is_in_scale(key.pitch)
3030
31 if in_scale == "core":
32 return (0.1, 1.0, 0.2)
33 elif in_scale:
34 return (0.7, 0.9, 0.15)
31 if in_scale:
32 return (0.1, 0.9, 0.65)
3533 else:
3634 return (0.3, 0.8, 0.0)
3735
4240 hue, sat, key_val = self.prepared[i]
4341
4442 base = self.keyboard.modes["base"]
43 extra = base.extra_notes.get(key.pitch)
4544 note_for_pitch = base.notes.get(key.pitch)
4645 note_for_pitch = note_for_pitch or base.notes_expiring.get(key.pitch)
46
47 if extra:
48 return hsv_to_rgb(hue, 1.0, 1.0)
4749
4850 if key.note:
4951 value = 1.0
5052 elif note_for_pitch:
51 value = note_for_pitch.expiry * 0.8
53 value = note_for_pitch.expiry * 0.3
5254 else:
55 hue = 0.7
5356 value = 0.0
5457
5558 rest = 1.0 - key_val