Skip to content

Commit f44f5f9

Browse files
authored
Merge pull request #1584 from jedgarpark/modal-midi
code cleanup, some lists to tuples
2 parents 2bfaf56 + 9cd7243 commit f44f5f9

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

MIDI_Modal_Keyboard/code.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# 7x3 mech keyboard
66
# Each key sends MIDI NoteOn / NoteOff message over USB
77
# Can be any scale/mode
8+
# Key combo sends MIDI panic (see bottom section of code)
89

910
import time
1011
import board
@@ -33,7 +34,7 @@ def send_midi_panic():
3334
num_keys = 21
3435

3536
# list of pins to use (skipping GP15 on Pico because it's funky)
36-
pins = [
37+
pins = (
3738
board.GP0,
3839
board.GP1,
3940
board.GP2,
@@ -55,7 +56,7 @@ def send_midi_panic():
5556
board.GP19,
5657
board.GP20,
5758
board.GP21,
58-
]
59+
)
5960

6061

6162
keys = []
@@ -64,13 +65,13 @@ def send_midi_panic():
6465
tmp_pin.pull = Pull.UP
6566
keys.append(Debouncer(tmp_pin))
6667

67-
root_notes = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59] # used during config
68-
note_numbers = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
68+
root_notes = (48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59) # used during config
69+
note_numbers = (48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
6970
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
70-
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83]
71-
note_names = ["C2", "C#2", "D2", "D#2", "E2", "F2", "F#2", "G2", "G#2", "A2", "A#2", "B2",
71+
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83)
72+
note_names = ("C2", "C#2", "D2", "D#2", "E2", "F2", "F#2", "G2", "G#2", "A2", "A#2", "B2",
7273
"C3", "C#3", "D3", "D#3", "E3", "F3", "F#3", "G3", "G#3", "A3", "A#3", "B3",
73-
"C4", "C#4", "D4", "D#4", "E4", "F4", "F#4", "G4", "G#4", "A4", "A#4", "B4"]
74+
"C4", "C#4", "D4", "D#4", "E4", "F4", "F#4", "G4", "G#4", "A4", "A#4", "B4",)
7475
scale_root = root_notes[0] # default if nothing is picked
7576
root_picked = False # state of root selection
7677
mode_picked = False # state of mode selection
@@ -92,21 +93,20 @@ def send_midi_panic():
9293
print("Root is", note_names[i])
9394
if keys[i].rose:
9495
midi.send(NoteOff(root_notes[i], 0))
95-
# root_picked = True
9696
keys[20].update()
9797

9898
if keys[20].rose:
9999
root_picked = True
100100
print("Root picked.\n")
101101

102102
# lists of mode intervals relative to root
103-
major = [ 0, 2, 4, 5, 7, 9, 11 ]
104-
minor = [ 0, 2, 3, 5, 7, 8, 10 ]
105-
dorian = [ 0, 2, 3, 5, 7, 9, 10 ]
106-
phrygian = [ 0, 1, 3, 5, 7, 8, 10 ]
107-
lydian = [0 , 2, 4, 6, 7, 9, 11 ]
108-
mixolydian = [ 0, 2, 4, 5, 7, 9, 10]
109-
locrian = [ 0, 1, 3, 5, 6, 8, 10]
103+
major = ( 0, 2, 4, 5, 7, 9, 11 )
104+
minor = ( 0, 2, 3, 5, 7, 8, 10 )
105+
dorian = ( 0, 2, 3, 5, 7, 9, 10 )
106+
phrygian = ( 0, 1, 3, 5, 7, 8, 10 )
107+
lydian = (0 , 2, 4, 6, 7, 9, 11 )
108+
mixolydian = ( 0, 2, 4, 5, 7, 9, 10)
109+
locrian = ( 0, 1, 3, 5, 6, 8, 10)
110110

111111
modes = []
112112
modes.append(major)
@@ -117,15 +117,15 @@ def send_midi_panic():
117117
modes.append(mixolydian)
118118
modes.append(locrian)
119119

120-
mode_names = ["Major/Ionian",
120+
mode_names = ("Major/Ionian",
121121
"Minor/Aeolian",
122122
"Dorian",
123123
"Phrygian",
124124
"Lydian",
125125
"Mixolydian",
126-
"Locrian"]
126+
"Locrian")
127127

128-
intervals = mixolydian.copy() # intervals for Mixolydian by default
128+
intervals = list(mixolydian) # intervals for Mixolydian by default
129129

130130
print("Pick the mode with top seven keys, then press bottom right key to enter:")
131131
print(". . . . . . .")
@@ -175,6 +175,7 @@ def send_midi_panic():
175175
led.value = False
176176
print("Ready, set, play!")
177177

178+
178179
while True:
179180

180181
for i in range(num_keys):
@@ -196,15 +197,14 @@ def send_midi_panic():
196197
pass
197198

198199
# Key combo for MIDI panic
199-
# * o o o o o *
200-
# o o o * o o o
201-
# * o o o o o *
200+
# . o o o o o .
201+
# o o o . o o o
202+
# . o o o o o .
202203

203204
if (not keys[0].value and
204-
not keys[6].value and
205-
not keys[10].value and
206-
not keys[14].value and
207-
not keys[20].value):
208-
205+
not keys[6].value
206+
and not keys[10].value
207+
and not keys[14].value
208+
and not keys[20].value):
209209
send_midi_panic()
210210
time.sleep(1)

0 commit comments

Comments
 (0)