Skip to content

Commit ae39869

Browse files
authored
Merge pull request #108 from aupfred/fix_jwdj_EasyABC_103
#103 highlight note when cursor change in editor
2 parents 6623583 + bf0992a commit ae39869

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ different panes. Tie/untie option added for notes. Broken rhythm
637637
- New: file setting: ffmpeg
638638
- Several fixes to support newer Python versions. (thanks aupfred and all that contributed)
639639
- Updated xml2abc, abc2xml (aupfred)
640+
- Reenable note highlighting based on cursor position in editor (aupfred)
640641
- Adapt to new version of abcmidi output (aupfred)
641642
- Fix playback of a selection on second page (aupfred)
642643
- Enable Midi playback for Mac based on Apple DLS Synthetiser thanks to mplay library (aupfred)

easy_abc.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -6778,6 +6778,7 @@ def ScrollMusicPaneToMatchEditor(self, select_closest_note=False, select_closest
67786778

67796779
closest_xy = None
67806780
closest_col = -9999
6781+
note_delta = 9999
67816782
line = self.editor.GetCurrentLine()
67826783
col = self.editor.GetCurrentPos() - self.editor.PositionFromLine(line)
67836784
# 1.3.6.2 [JWdJ] 2015-02
@@ -6786,7 +6787,12 @@ def ScrollMusicPaneToMatchEditor(self, select_closest_note=False, select_closest
67866787
# 1.3.6.2 [JWdJ] 2015-02
67876788
for i, (x, y, abc_row, abc_col, desc) in enumerate(page.notes):
67886789
abc_row += row_offset
6789-
if abc_row == line and (abs(col - abc_col) < abs(closest_col - abc_col)):
6790+
#FAU 20250126: search for the closest while not switching to next one to early
6791+
# with if abc_row == line and and (abs(col - abc_col) < abs(closest_col - abc_col))
6792+
# as soon as cursor shifted after the letter of note next note was selected even if only duration of previous note
6793+
# %%TODO%%: improve to consider highlight only if cursor is in a note?
6794+
if abc_row == line and col>=abc_col and (abs(col - abc_col)<note_delta): # and (abs(col - abc_col) < abs(closest_col - abc_col))
6795+
note_delta=abs(col - abc_col)
67906796
closest_col = abc_col
67916797
closest_xy = (x, y)
67926798
if select_closest_note:
@@ -7368,7 +7374,11 @@ def OnPosChanged(self, evt):
73687374
# otherhand, the following function allows the highlighted note
73697375
# in the MusicPane follow the highlighted note in the editor when
73707376
# it is controlled by the keyboard arrow keys. p09
7371-
#self.ScrollMusicPaneToMatchEditor(select_closest_note=True, select_closest_page=True) #patch p08
7377+
#FAU 20250126: To avoid to have sort of a race, keep the call but
7378+
# only when no action on the music pane to select
7379+
# Add a property in music_pane to identify when a drag selection is ongoing
7380+
if not self.music_pane.mouse_select_ongoing:
7381+
self.ScrollMusicPaneToMatchEditor(select_closest_note=True, select_closest_page=True) #patch p08
73727382

73737383

73747384
def OnModified(self, evt):

music_score_panel.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def __init__(self, parent, renderer):
3636
self.drag_start_x = None
3737
self.drag_start_y = None
3838
self.drag_rect = None
39+
#FAU 20250120: mouse_select_ongoing positionned to avoid the race with event of selection change in TextCtrl
40+
self.mouse_select_ongoing = False
3941
self.SetVirtualSize((self.buffer_width, self.buffer_height))
4042
self.SetScrollbars(20, 20, 50, 50)
4143
# 1.3.6.2 [JWdJ] 2015-02-14 hook events after initializing to prevent unnecessary redraws
@@ -92,6 +94,8 @@ def get_xy_of_mouse_event(self, event):
9294

9395
def OnLeftButtonDown(self, event):
9496
if event.LeftDown():
97+
#FAU 20250126: mouse_select_ongoing positionned to avoid the race with event of selection change in TextCtrl
98+
self.mouse_select_ongoing = True
9599
self.SetFocus()
96100
page = self.current_page
97101
old_selection = page.selected_indices.copy()
@@ -143,6 +147,8 @@ def OnLeftButtonUp(self, event):
143147
self.drag_rect = None
144148
self.OnMouseMotion(event)
145149
self.redraw()
150+
#FAU 20250126: mouse_select_ongoing positionned to avoid the race with event of selection change in TextCtrl
151+
self.mouse_select_ongoing = False
146152

147153
def OnMouseMotion(self, event):
148154
page = self.current_page
@@ -162,6 +168,8 @@ def OnMouseMotion(self, event):
162168
self.SetCursor(self.pointer_cursor)
163169
else:
164170
self.SetCursor(self.cross_cursor)
171+
#FAU 20250126: mouse_select_ongoing positionned to avoid the race with event of selection change in TextCtrl
172+
self.mouse_select_ongoing = False
165173
## if self.HasCapture():
166174
## x, y = self.get_xy_of_mouse_event(event)
167175
## self.drag_rect = (min(self.drag_start_x, x), min(self.drag_start_y, y), abs(self.drag_start_x-x), abs(self.drag_start_y-y))
@@ -277,7 +285,8 @@ def draw_notes_highlighted(self, note_indices):
277285
self.Update()
278286
finally:
279287
self.redrawing = False
280-
self.highlighted_notes = None
288+
if not wx.Platform == "__WXMAC__":
289+
self.highlighted_notes = None
281290

282291
def Draw(self):
283292
dc = wx.BufferedDC(None, self.renderer.buffer)

0 commit comments

Comments
 (0)