From 15746777dd0bda20e0186d4aa8aae26cd4df8a42 Mon Sep 17 00:00:00 2001 From: Sig <62321214+sigprogramming@users.noreply.github.com> Date: Tue, 17 Dec 2024 20:53:31 +0900 Subject: [PATCH] =?UTF-8?q?Note=E3=81=AE=E3=82=A4=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=B9=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8F?= =?UTF-8?q?NoteId=E3=82=92=E6=B8=A1=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stateMachine/sequencerStateMachine.ts | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/sing/stateMachine/sequencerStateMachine.ts b/src/sing/stateMachine/sequencerStateMachine.ts index 65c7c30142..9fe51406ff 100644 --- a/src/sing/stateMachine/sequencerStateMachine.ts +++ b/src/sing/stateMachine/sequencerStateMachine.ts @@ -138,12 +138,6 @@ const executeNotesSelectionProcess = ( } }; -const getSelectedNotes = (context: Context) => { - return context.notesInSelectedTrack.value.filter((value) => - context.selectedNoteIds.value.has(value.id), - ); -}; - class IdleState implements IState { readonly id = "idle"; @@ -194,11 +188,10 @@ class IdleState implements IState { } if (mouseButton === "LEFT_BUTTON") { executeNotesSelectionProcess(context, input.mouseEvent, input.note); - const selectedNotes = getSelectedNotes(context); const moveNoteState = new MoveNoteState( input.cursorPos, selectedTrackId, - selectedNotes, + context.selectedNoteIds.value, input.note.id, ); setNextState(moveNoteState); @@ -347,13 +340,14 @@ class MoveNoteState implements IState { private readonly cursorPosAtStart: PositionOnSequencer; private readonly targetTrackId: TrackId; - private readonly targetNotesAtStart: Map; + private readonly targetNoteIds: Set; private readonly mouseDownNoteId: NoteId; private currentCursorPos: PositionOnSequencer; private innerContext: | { + targetNotesAtStart: Map; previewRequestId: number; executePreviewProcess: boolean; edited: boolean; @@ -364,18 +358,15 @@ class MoveNoteState implements IState { constructor( cursorPosAtStart: PositionOnSequencer, targetTrackId: TrackId, - targetNotes: Note[], + targetNoteIds: Set, mouseDownNoteId: NoteId, ) { - if (!targetNotes.some((value) => value.id === mouseDownNoteId)) { - throw new Error("mouseDownNote is not included in targetNotes."); + if (!targetNoteIds.has(mouseDownNoteId)) { + throw new Error("mouseDownNoteId is not included in targetNoteIds."); } this.cursorPosAtStart = cursorPosAtStart; this.targetTrackId = targetTrackId; - this.targetNotesAtStart = new Map(); - for (const targetNote of targetNotes) { - this.targetNotesAtStart.set(targetNote.id, targetNote); - } + this.targetNoteIds = targetNoteIds; this.mouseDownNoteId = mouseDownNoteId; this.currentCursorPos = cursorPosAtStart; @@ -387,7 +378,7 @@ class MoveNoteState implements IState { } const snapTicks = context.snapTicks.value; const previewNotes = context.previewNotes.value; - const targetNotesAtStart = this.targetNotesAtStart; + const targetNotesAtStart = this.innerContext.targetNotesAtStart; const mouseDownNote = getOrThrow(targetNotesAtStart, this.mouseDownNoteId); const dragTicks = this.currentCursorPos.ticks - this.cursorPosAtStart.ticks; const notePos = mouseDownNote.position; @@ -434,8 +425,15 @@ class MoveNoteState implements IState { onEnter(context: Context) { const guideLineTicks = getGuideLineTicks(this.cursorPosAtStart, context); + const targetNotesArray = context.notesInSelectedTrack.value.filter( + (value) => this.targetNoteIds.has(value.id), + ); + const targetNotesMap = new Map(); + for (const targetNote of targetNotesArray) { + targetNotesMap.set(targetNote.id, targetNote); + } - context.previewNotes.value = [...this.targetNotesAtStart.values()]; + context.previewNotes.value = [...targetNotesArray]; context.nowPreviewing.value = true; const previewIfNeeded = () => { @@ -452,6 +450,7 @@ class MoveNoteState implements IState { const previewRequestId = requestAnimationFrame(previewIfNeeded); this.innerContext = { + targetNotesAtStart: targetNotesMap, executePreviewProcess: false, previewRequestId, edited: false,