jwdj / EasyABC

EasyABC
GNU General Public License v2.0
87 stars 36 forks source link

Control-drag on the score to *add* to a previous selections of notes #91

Open revad opened 5 months ago

revad commented 5 months ago

77 fixes the selection of notes to play by dragging the mouse across the score. But you cannot select a passage that starts on one line and continues into the next. I mentioned this problem here:

https://github.com/jwdj/EasyABC/issues/90#issuecomment-2009499101

This patch allows you do do that by holding down the control/command key while dragging, which will add or merge the new selection and the previous one.

The changes are all to music_score_panel.py Note that changes are also required to music_score_panel.py for python 3.10: https://github.com/jwdj/EasyABC/issues/77#issuecomment-1999925784

At ~line 50, after the initialisations:

#DR2
        self.previous_selection = set()

Amend function OnLeftButtonDown to start:

    def OnLeftButtonDown(self, event):
        if event.LeftDown():
            self.SetFocus()
            page = self.current_page
            old_selection = page.selected_indices.copy()
#DR2
            self.previous_selection = old_selection

            page.clear_note_selection()

Amend function OnMouseMotion to start:

    def OnMouseMotion(self, event):
        page = self.current_page
        if self.HasCapture():
            if self.drag_start_x is not None and self.drag_start_y is not None:
#DR2
                add_selection = event.ControlDown() or event.CmdDown()

                x, y = self.get_xy_of_mouse_event(event)
                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))
                rect = wx.Rect(*map(int, self.drag_rect))
                old_selection = page.selected_indices.copy()
                page.select_notes(rect)
                if old_selection != page.selected_indices and self.OnNoteSelectionChangedDesc:
#DR2
                    if add_selection:
                         page.selected_indices = self.previous_selection.union(page.selected_indices)                        

                    self.OnNoteSelectionChangedDesc(page.selected_indices)
                self.redraw()
revad commented 5 months ago

Video showing how to add to a selection out.webm