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

Add:ルーラークリックでスナップ位置に再生ヘッドをあわせる #2372

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 2 additions & 0 deletions src/components/Sing/SequencerRuler/Container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:sequencerZoomX
:numMeasures
:playheadTicks
:sequencerSnapType
@update:playheadTicks="updatePlayheadTicks"
@deselectAllNotes="deselectAllNotes"
/>
Expand Down Expand Up @@ -35,6 +36,7 @@ const store = useStore();
const tpqn = computed(() => store.state.tpqn);
const timeSignatures = computed(() => store.state.timeSignatures);
const sequencerZoomX = computed(() => store.state.sequencerZoomX);
const sequencerSnapType = computed(() => store.state.sequencerSnapType);

const playheadTicks = computed(() => store.getters.PLAYHEAD_POSITION);

Expand Down
19 changes: 16 additions & 3 deletions src/components/Sing/SequencerRuler/Presentation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@

<script setup lang="ts">
import { computed, ref, onMounted, onUnmounted } from "vue";
import { getMeasureDuration, getTimeSignaturePositions } from "@/sing/domain";
import {
getMeasureDuration,
getTimeSignaturePositions,
getNoteDuration,
snapTicksToGrid,
} from "@/sing/domain";
import { baseXToTick, tickToBaseX } from "@/sing/viewHelper";
import { TimeSignature } from "@/store/type";

Expand All @@ -73,6 +78,7 @@ const props = defineProps<{
tpqn: number;
timeSignatures: TimeSignature[];
sequencerZoomX: number;
sequencerSnapType: number;
}>();
const playheadTicks = defineModel<number>("playheadTicks", { required: true });
const emit = defineEmits<{
Expand Down Expand Up @@ -134,6 +140,10 @@ const playheadX = computed(() => {
return Math.floor(baseX * props.sequencerZoomX);
});

const snapTicks = computed(() => {
return getNoteDuration(props.sequencerSnapType, props.tpqn);
});

const onClick = (event: MouseEvent) => {
emit("deselectAllNotes");

Expand All @@ -142,7 +152,10 @@ const onClick = (event: MouseEvent) => {
throw new Error("sequencerRulerElement is null.");
}
const baseX = (props.offset + event.offsetX) / props.sequencerZoomX;
const ticks = baseXToTick(baseX, props.tpqn);
const ticks = snapTicksToGrid(
baseXToTick(baseX, props.tpqn),
snapTicks.value,
);
playheadTicks.value = ticks;
};

Expand Down Expand Up @@ -193,7 +206,7 @@ onUnmounted(() => {
background: var(--scheme-color-inverse-surface);
pointer-events: none;
will-change: transform;
z-index: vars.$z-index-sing-playhead;
z-index: 10000;
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
}

.sequencer-ruler-measure-number {
Expand Down
1 change: 1 addition & 0 deletions src/components/Sing/SequencerRuler/index.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const meta: Meta<typeof Presentation> = {
tpqn: 480,
offset: 0,
numMeasures: 32,
sequencerSnapType: 4,
"onUpdate:playheadTicks": fn<(value: number) => void>(),
onDeselectAllNotes: fn(),
},
Expand Down
7 changes: 7 additions & 0 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,10 @@ export const shouldPlayTracks = (tracks: Map<TrackId, Track>): Set<TrackId> => {
.map(([trackId]) => trackId),
);
};

/**
* 指定されたティックを直近のグリッドに合わせる
*/
export function snapTicksToGrid(ticks: number, snapTicks: number): number {
return Math.round(ticks / snapTicks) * snapTicks;
}
Loading