USB MIDI note highlighting
s-ol
4 months ago
2 | 2 |
import displayio
|
3 | 3 |
from adafruit_ticks import ticks_ms
|
4 | 4 |
from adafruit_midi.system_exclusive import SystemExclusive
|
|
5 |
from adafruit_midi.note_on import NoteOn
|
|
6 |
from adafruit_midi.note_off import NoteOff
|
5 | 7 |
|
6 | 8 |
try:
|
7 | 9 |
import storage
|
|
9 | 11 |
except:
|
10 | 12 |
dev_mode = False
|
11 | 13 |
|
12 | |
from .core import Mode
|
|
14 |
from .core import Mode, Note
|
13 | 15 |
from .matrix import Matrix
|
14 | 16 |
from .scale import Scale
|
15 | 17 |
from .layout import Layout, LAYOUTS, WickiHaydenLayout
|
|
270 | 272 |
|
271 | 273 |
if self.i2c:
|
272 | 274 |
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 |
|
273 | 286 |
|
274 | 287 |
self.mode.update_pixels(self.pixels)
|
275 | 288 |
|
27 | 27 |
self.rgb = ColorScale(self.keyboard)
|
28 | 28 |
|
29 | 29 |
self.notes = {}
|
|
30 |
self.extra_notes = {}
|
30 | 31 |
self.notes_expiring = {}
|
31 | 32 |
|
32 | 33 |
self.notes_dirty = False
|
28 | 28 |
def prepare_key(self, key: Key):
|
29 | 29 |
in_scale = self.keyboard.scale.is_in_scale(key.pitch)
|
30 | 30 |
|
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)
|
35 | 33 |
else:
|
36 | 34 |
return (0.3, 0.8, 0.0)
|
37 | 35 |
|
|
42 | 40 |
hue, sat, key_val = self.prepared[i]
|
43 | 41 |
|
44 | 42 |
base = self.keyboard.modes["base"]
|
|
43 |
extra = base.extra_notes.get(key.pitch)
|
45 | 44 |
note_for_pitch = base.notes.get(key.pitch)
|
46 | 45 |
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)
|
47 | 49 |
|
48 | 50 |
if key.note:
|
49 | 51 |
value = 1.0
|
50 | 52 |
elif note_for_pitch:
|
51 | |
value = note_for_pitch.expiry * 0.8
|
|
53 |
value = note_for_pitch.expiry * 0.3
|
52 | 54 |
else:
|
|
55 |
hue = 0.7
|
53 | 56 |
value = 0.0
|
54 | 57 |
|
55 | 58 |
rest = 1.0 - key_val
|