Skip to content

Commit 48882e1

Browse files
feat: [project-sequencer-statemachine] ダブルクリック時はaddNoteStateに遷移せずに直接ノート追加の処理を行うようにする (#2540)
Co-authored-by: Hiroshiba Kazuyuki <[email protected]>
1 parent 2855e58 commit 48882e1

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/sing/sequencerStateMachine/states/addNoteState.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
PREVIEW_SOUND_DURATION,
1616
} from "@/sing/viewHelper";
1717
import { clamp } from "@/sing/utility";
18+
import { uuid4 } from "@/helpers/random";
1819

1920
export class AddNoteState
2021
implements State<SequencerStateDefinitions, Input, Context>
@@ -78,7 +79,7 @@ export class AddNoteState
7879
onEnter(context: Context) {
7980
const guideLineTicks = getGuideLineTicks(this.cursorPosAtStart, context);
8081
const noteToAdd = {
81-
id: NoteId(crypto.randomUUID()),
82+
id: NoteId(uuid4()),
8283
position: Math.max(0, guideLineTicks),
8384
duration: context.snapTicks.value,
8485
noteNumber: clamp(this.cursorPosAtStart.noteNumber, 0, 127),

src/sing/sequencerStateMachine/states/selectNotesToolIdleState.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ import {
88
SequencerStateDefinitions,
99
toggleNoteSelection,
1010
} from "@/sing/sequencerStateMachine/common";
11-
import { getButton, isSelfEventTarget } from "@/sing/viewHelper";
11+
import {
12+
getButton,
13+
getDoremiFromNoteNumber,
14+
isSelfEventTarget,
15+
PREVIEW_SOUND_DURATION,
16+
} from "@/sing/viewHelper";
1217
import { isOnCommandOrCtrlKeyDown } from "@/store/utility";
1318
import { Note } from "@/store/type";
19+
import { NoteId } from "@/type/preload";
20+
import { clamp } from "@/sing/utility";
21+
import { uuid4 } from "@/helpers/random";
1422

1523
export class SelectNotesToolIdleState
1624
implements State<SequencerStateDefinitions, Input, Context>
@@ -98,10 +106,25 @@ export class SelectNotesToolIdleState
98106
}
99107
} else if (input.mouseEvent.type === "dblclick") {
100108
void context.store.actions.DESELECT_ALL_NOTES();
101-
setNextState("addNote", {
102-
cursorPosAtStart: input.cursorPos,
103-
targetTrackId: selectedTrackId,
104-
returnStateId: this.id,
109+
110+
const guideLineTicks = getGuideLineTicks(input.cursorPos, context);
111+
const noteToAdd = {
112+
id: NoteId(uuid4()),
113+
position: Math.max(0, guideLineTicks),
114+
duration: context.snapTicks.value,
115+
noteNumber: clamp(input.cursorPos.noteNumber, 0, 127),
116+
lyric: getDoremiFromNoteNumber(input.cursorPos.noteNumber),
117+
};
118+
119+
void context.store.actions.COMMAND_ADD_NOTES({
120+
notes: [noteToAdd],
121+
trackId: selectedTrackId,
122+
});
123+
void context.store.actions.SELECT_NOTES({ noteIds: [noteToAdd.id] });
124+
125+
void context.store.actions.PLAY_PREVIEW_SOUND({
126+
noteNumber: noteToAdd.noteNumber,
127+
duration: PREVIEW_SOUND_DURATION,
105128
});
106129
}
107130
}

0 commit comments

Comments
 (0)