Skip to content

Commit c108210

Browse files
committed
implemented sharps/flats toggle
1 parent b8ba054 commit c108210

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
TITLE = "midimech"
44
# FOCUS = False
5-
NOTES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
5+
#U+1D12C flat
6+
#1D130 sharp
7+
NOTES_SHARPS = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
8+
NOTES_FLATS = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
69
WHOLETONE = True
710
FONT_SZ = 32
811
BRIGHTNESS = 0.4

src/core.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ def next_mode(self, ofs=1):
9393
self.set_mode((self.mode_index + ofs) % self.scale_notes.count('x'))
9494
self.dirty = self.dirty_lights = True
9595

96+
def toggle_sharps_flats(self, ofs=1):
97+
if (self.use_sharps):
98+
self.use_sharps = False
99+
self.NOTES = NOTES_FLATS
100+
else:
101+
self.use_sharps = True
102+
self.NOTES = NOTES_SHARPS
103+
self.dirty = self.dirty_lights = True
104+
96105
def prev_scale(self, ofs=1):
97106
self.next_scale(-ofs)
98107

@@ -324,7 +333,7 @@ def get_note_index(self, x, y, transpose=True):
324333
y = self.board_h - y - 1
325334
x += self.options.base_offset
326335
tr = self.tonic if transpose else 0
327-
return (row_offset * y + column_offset * x + tr) % len(NOTES)
336+
return (row_offset * y + column_offset * x + tr) % len(self.NOTES)
328337
# ofs = (self.board_h - y) // 2 + BASE_OFFSET
329338
# step = 2 if WHOLETONE else 1
330339
# tr = self.tonic if transpose else 0
@@ -335,7 +344,7 @@ def get_note_index(self, x, y, transpose=True):
335344

336345
def get_note(self, x, y, transpose=True):
337346
"""Get note name for x, y"""
338-
return NOTES[self.get_note_index(x, y, transpose=transpose)]
347+
return self.NOTES[self.get_note_index(x, y, transpose=transpose)]
339348

340349
def get_color(self, x, y):
341350
"""Get color for x, y"""
@@ -1629,6 +1638,11 @@ def __init__(self):
16291638
text='MOD>',
16301639
manager=self.gui
16311640
)
1641+
self.btn_sharps_flats = pygame_gui.elements.UIButton(
1642+
relative_rect=pygame.Rect((bs.x * 16 + 2, y), (bs.x, bs.y)),
1643+
text='#/b',
1644+
manager=self.gui
1645+
)
16321646
# self.next_scale = pygame_gui.elements.UIButton(
16331647
# relative_rect=pygame.Rect((bs.x * 11 + 2, y), (bs.x, bs.y)),
16341648
# text='SCL>',
@@ -1695,6 +1709,9 @@ def __init__(self):
16951709
self.linn_out = None
16961710
self.midi_out = None
16971711
self.split_out = None
1712+
self.use_sharps = True
1713+
self.NOTES = NOTES_SHARPS
1714+
16981715

16991716
outnames = rtmidi2.get_out_ports()
17001717
for i in range(len(outnames)):
@@ -2223,6 +2240,8 @@ def logic(self, dt):
22232240
self.next_mode()
22242241
elif ev.ui_element == self.btn_prev_mode:
22252242
self.prev_mode()
2243+
elif ev.ui_element == self.btn_sharps_flats:
2244+
self.toggle_sharps_flats()
22262245
# elif ev.type == pygame_gui.UI_HORIZONTAL_SLIDER_MOVED:
22272246
# if ev.ui_element == self.slider_velocity:
22282247
# global self.options.velocity_curve

0 commit comments

Comments
 (0)