-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: SequencerRulerをContainer/Presentationに分離 (#2312)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Hiroshiba <[email protected]> Co-authored-by: Hiroshiba Kazuyuki <[email protected]>
- Loading branch information
1 parent
428413c
commit d7087ef
Showing
5 changed files
with
170 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<Presentation | ||
:offset | ||
:tpqn | ||
:timeSignatures | ||
:sequencerZoomX | ||
:numMeasures | ||
:playheadTicks | ||
@update:playheadTicks="updatePlayheadTicks" | ||
@deselectAllNotes="deselectAllNotes" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, onMounted, onUnmounted, ref } from "vue"; | ||
import Presentation from "./Presentation.vue"; | ||
import { useStore } from "@/store"; | ||
defineOptions({ | ||
name: "SequencerRuler", | ||
}); | ||
withDefaults( | ||
defineProps<{ | ||
offset: number; | ||
numMeasures: number; | ||
}>(), | ||
{ | ||
offset: 0, | ||
numMeasures: 32, | ||
}, | ||
); | ||
const store = useStore(); | ||
const tpqn = computed(() => store.state.tpqn); | ||
const timeSignatures = computed(() => store.state.timeSignatures); | ||
const sequencerZoomX = computed(() => store.state.sequencerZoomX); | ||
const playheadTicks = ref(0); | ||
const updatePlayheadTicks = (ticks: number) => { | ||
void store.dispatch("SET_PLAYHEAD_POSITION", { position: ticks }); | ||
}; | ||
const playheadPositionChangeListener = (position: number) => { | ||
playheadTicks.value = position; | ||
}; | ||
onMounted(() => { | ||
void store.dispatch("ADD_PLAYHEAD_POSITION_CHANGE_LISTENER", { | ||
listener: playheadPositionChangeListener, | ||
}); | ||
}); | ||
onUnmounted(() => { | ||
void store.dispatch("REMOVE_PLAYHEAD_POSITION_CHANGE_LISTENER", { | ||
listener: playheadPositionChangeListener, | ||
}); | ||
}); | ||
const deselectAllNotes = () => { | ||
void store.dispatch("DESELECT_ALL_NOTES"); | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
import { fn, expect, Mock } from "@storybook/test"; | ||
import { ref } from "vue"; | ||
|
||
import Presentation from "./Presentation.vue"; | ||
import { UnreachableError } from "@/type/utility"; | ||
|
||
const meta: Meta<typeof Presentation> = { | ||
component: Presentation, | ||
args: { | ||
timeSignatures: [ | ||
{ | ||
beats: 4, | ||
beatType: 4, | ||
measureNumber: 1, | ||
}, | ||
], | ||
sequencerZoomX: 0.25, | ||
tpqn: 480, | ||
offset: 0, | ||
numMeasures: 32, | ||
"onUpdate:playheadTicks": fn<(value: number) => void>(), | ||
onDeselectAllNotes: fn(), | ||
}, | ||
render: (args) => ({ | ||
components: { Presentation }, | ||
setup() { | ||
const playheadTicks = ref(0); | ||
return { args, playheadTicks }; | ||
}, | ||
template: `<Presentation v-bind="args" v-model:playheadTicks="playheadTicks" />`, | ||
}), | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Presentation>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const MovePlayhead: Story = { | ||
name: "再生位置を移動", | ||
|
||
play: async ({ canvasElement, args }) => { | ||
const ruler = | ||
canvasElement.querySelector<HTMLDivElement>(".sequencer-ruler"); | ||
|
||
if (!ruler) { | ||
throw new UnreachableError("ruler is not found"); | ||
} | ||
|
||
// userEvent.pointerは座標指定が上手くいかないので、MouseEventを使って手動でクリックをエミュレートする | ||
const rect = ruler.getBoundingClientRect(); | ||
const width = rect.width; | ||
const event = new MouseEvent("click", { | ||
bubbles: true, | ||
cancelable: true, | ||
clientX: rect.left + width / 2, | ||
clientY: rect.top + rect.height, | ||
}); | ||
|
||
ruler.dispatchEvent(event); | ||
|
||
await expect(args["onUpdate:playheadTicks"]).toHaveBeenCalled(); | ||
|
||
const onUpdateCallback = args["onUpdate:playheadTicks"] as Mock< | ||
(value: number) => void | ||
>; | ||
const newTick = onUpdateCallback.mock.calls[0][0]; | ||
|
||
await expect(newTick).toBeGreaterThan(0); | ||
await expect(args["onDeselectAllNotes"]).toHaveBeenCalled(); | ||
}, | ||
}; |
Binary file added
BIN
+6.45 KB
....spec.mts-snapshots/components-sing-sequencerruler--default-storybook-win32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.