Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor mouse gesture to hooks #426

Merged
merged 28 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1498f4e
refactor: convert NoteMouseHandler to hooks
ryohey Dec 10, 2024
16bef54
refactor: convert getPencilActionForMouseDown to hooks
ryohey Dec 10, 2024
5c751d0
refactor: convert getSelectionActionForMouseDown to hooks
ryohey Dec 10, 2024
f5291f5
refactor: merge cursor function to hooks
ryohey Dec 10, 2024
cac7d9f
refactor: convert actions to hooks
ryohey Dec 10, 2024
4d0b64b
Update settings.json
ryohey Dec 14, 2024
e54cba4
refactor: remove selection actions
ryohey Dec 14, 2024
00d7d0d
refactor: remove removeEvent
ryohey Dec 14, 2024
8d99353
refactor: remove createNote
ryohey Dec 14, 2024
ead9d6a
refactor: convert selection actions to hooks
ryohey Dec 14, 2024
6d7bc52
Add useSelectNote
ryohey Dec 14, 2024
d6e3be6
refactor: convert keyboard shortcut actions to hooks
ryohey Dec 14, 2024
ec7a7e5
refactor: convert mouse actions to hooks
ryohey Dec 14, 2024
18bf0a0
refactor: convert selection actions to hooks
ryohey Dec 15, 2024
0ab906b
refactor: remove rootStore dependency from mouse handler
ryohey Dec 15, 2024
c1ee345
Fix
ryohey Dec 15, 2024
0bdef93
refactor merge selection reset reactions
ryohey Dec 15, 2024
a1129eb
refactor: convert actions to hooks
ryohey Dec 15, 2024
9563004
Fix hooks
ryohey Dec 15, 2024
f07752f
refactor: move transposeNotes to Song
ryohey Dec 15, 2024
6c55836
refactor: move resetSelection to PianoRollStore
ryohey Dec 15, 2024
c24323c
refactor: move resetSelection to ArrangeViewStore
ryohey Dec 15, 2024
ad062ea
Fix MouseGesture type
ryohey Dec 18, 2024
dd5866e
refactor: organize gestures
ryohey Dec 18, 2024
02f1652
refactor: Add MouseGesture.ts
ryohey Dec 18, 2024
1daa89a
refactor: add types
ryohey Dec 18, 2024
eb1e976
refactor: add types
ryohey Dec 18, 2024
a77f368
refactor: rename files
ryohey Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"testing.openTesting": "neverOpen"
"testing.openTesting": "neverOpen",
"testing.automaticallyOpenTestResults": "neverOpen"
}
26 changes: 4 additions & 22 deletions app/src/actions/arrangeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,8 @@ import { isEventInRange } from "../helpers/filterEvents"
import clipboard from "../services/Clipboard"
import RootStore from "../stores/RootStore"
import Track from "../track"
import { pushHistory } from "./history"
import { transposeNotes } from "./song"
import { batchUpdateNotesVelocity, BatchUpdateOperation } from "./track"

export const arrangeResetSelection =
({ arrangeViewStore }: RootStore) =>
() => {
arrangeViewStore.selection = null
arrangeViewStore.selectedEventIds = {}
}

export const arrangeStartSelection =
({ arrangeViewStore }: RootStore) =>
() => {
arrangeViewStore.selection = null
arrangeViewStore.selectedEventIds = {}
}

export const arrangeResizeSelection =
({
song: { tracks },
Expand Down Expand Up @@ -249,12 +233,10 @@ function getEventsInSelection(tracks: Track[], selection: ArrangeSelection) {
}

export const arrangeTransposeSelection =
(rootStore: RootStore) => (deltaPitch: number) => {
pushHistory(rootStore)()
transposeNotes(rootStore)(
deltaPitch,
rootStore.arrangeViewStore.selectedEventIds,
)
({ song, pushHistory, arrangeViewStore: { selectedEventIds } }: RootStore) =>
(deltaPitch: number) => {
pushHistory()
song.transposeNotes(deltaPitch, selectedEventIds)
}

export const arrangeDuplicateSelection =
Expand Down
146 changes: 81 additions & 65 deletions app/src/actions/hotkey.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,102 @@
// global keyboard shortcuts or menu actions

import {
isControlEventsClipboardData,
isPianoNotesClipboardData,
} from "../clipboard/clipboardTypes"
import Clipboard from "../services/Clipboard"
import RootStore from "../stores/RootStore"
import {
arrangeCopySelection,
arrangeDeleteSelection,
arrangePasteSelection,
} from "./arrangeView"
} from "../actions/arrangeView"
import {
copyControlSelection,
deleteControlSelection,
pasteControlSelection,
} from "./control"
import { copySelection, deleteSelection, pasteSelection } from "./selection"
} from "../actions/control"
import {
useCopySelection,
useDeleteSelection,
usePasteSelection,
} from "../actions/selection"
import {
copyTempoSelection,
deleteTempoSelection,
pasteTempoSelection,
} from "./tempo"
} from "../actions/tempo"
import {
isControlEventsClipboardData,
isPianoNotesClipboardData,
} from "../clipboard/clipboardTypes"
import { useStores } from "../hooks/useStores"
import Clipboard from "../services/Clipboard"

export const copySelectionGlobal = (rootStore: RootStore) => () => {
switch (rootStore.router.path) {
case "/track":
if (rootStore.pianoRollStore.selectedNoteIds.length > 0) {
copySelection(rootStore)()
} else if (rootStore.controlStore.selectedEventIds.length > 0) {
copyControlSelection(rootStore)()
}
break
case "/arrange":
arrangeCopySelection(rootStore)()
break
case "/tempo":
copyTempoSelection(rootStore)()
break
export const useCopySelectionGlobal = () => {
const rootStore = useStores()
const copySelection = useCopySelection()
return () => {
switch (rootStore.router.path) {
case "/track":
if (rootStore.pianoRollStore.selectedNoteIds.length > 0) {
copySelection()
} else if (rootStore.controlStore.selectedEventIds.length > 0) {
copyControlSelection(rootStore)()
}
break
case "/arrange":
arrangeCopySelection(rootStore)()
break
case "/tempo":
copyTempoSelection(rootStore)()
break
}
}
}

export const cutSelectionGlobal = (rootStore: RootStore) => () => {
switch (rootStore.router.path) {
case "/track":
if (rootStore.pianoRollStore.selectedNoteIds.length > 0) {
copySelection(rootStore)()
deleteSelection(rootStore)()
} else if (rootStore.controlStore.selectedEventIds.length > 0) {
copyControlSelection(rootStore)()
deleteControlSelection(rootStore)()
}
break
case "/arrange":
arrangeCopySelection(rootStore)()
arrangeDeleteSelection(rootStore)()
break
case "/tempo":
copyTempoSelection(rootStore)()
deleteTempoSelection(rootStore)()
break
export const useCutSelectionGlobal = () => {
const rootStore = useStores()
const copySelection = useCopySelection()
const deleteSelection = useDeleteSelection()

return () => {
switch (rootStore.router.path) {
case "/track":
if (rootStore.pianoRollStore.selectedNoteIds.length > 0) {
copySelection()
deleteSelection()
} else if (rootStore.controlStore.selectedEventIds.length > 0) {
copyControlSelection(rootStore)()
deleteControlSelection(rootStore)()
}
break
case "/arrange":
arrangeCopySelection(rootStore)()
arrangeDeleteSelection(rootStore)()
break
case "/tempo":
copyTempoSelection(rootStore)()
deleteTempoSelection(rootStore)()
break
}
}
}

export const pasteSelectionGlobal = (rootStore: RootStore) => () => {
switch (rootStore.router.path) {
case "/track":
const text = Clipboard.readText()
if (!text || text.length === 0) {
return
}
const obj = JSON.parse(text)
if (isPianoNotesClipboardData(obj)) {
pasteSelection(rootStore)()
} else if (isControlEventsClipboardData(obj)) {
pasteControlSelection(rootStore)()
}
break
case "/arrange":
arrangePasteSelection(rootStore)()
break
case "/tempo":
pasteTempoSelection(rootStore)()
export const usePasteSelectionGlobal = () => {
const rootStore = useStores()
const pasteSelection = usePasteSelection()
return () => {
switch (rootStore.router.path) {
case "/track":
const text = Clipboard.readText()
if (!text || text.length === 0) {
return
}
const obj = JSON.parse(text)
if (isPianoNotesClipboardData(obj)) {
pasteSelection()
} else if (isControlEventsClipboardData(obj)) {
pasteControlSelection(rootStore)()
}
break
case "/arrange":
arrangePasteSelection(rootStore)()
break
case "/tempo":
pasteTempoSelection(rootStore)()
}
}
}
15 changes: 9 additions & 6 deletions app/src/actions/player.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Measure } from "../entities/measure/Measure"
import { useStores } from "../hooks/useStores"
import { noteOffMidiEvent, noteOnMidiEvent } from "../midi/MidiEvent"
import RootStore from "../stores/RootStore"

Expand Down Expand Up @@ -132,9 +133,9 @@ export const toggleEnableLoop =
player.loop = { ...player.loop, enabled: !player.loop.enabled }
}

export const startNote =
({ player, synthGroup }: Pick<RootStore, "player" | "synthGroup">) =>
(
export const useStartNote = () => {
const { player, synthGroup } = useStores()
return (
{
channel,
noteNumber,
Expand All @@ -152,10 +153,11 @@ export const startNote =
delayTime,
)
}
}

export const stopNote =
({ player }: Pick<RootStore, "player">) =>
(
export const useStopNote = () => {
const { player } = useStores()
return (
{
channel,
noteNumber,
Expand All @@ -167,3 +169,4 @@ export const stopNote =
) => {
player.sendEvent(noteOffMidiEvent(0, channel, noteNumber, 0), delayTime)
}
}
Loading
Loading