Skip to content

Commit

Permalink
ループ範囲が0の場合はループ無効にする
Browse files Browse the repository at this point in the history
  • Loading branch information
romot-co committed Oct 2, 2024
1 parent c954ae0 commit f03c07f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/components/Sing/SequencerGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const loopEndX = computed(() => {
.sequencer-grid-loop-mask {
position: relative;
fill: var(--scheme-color-scrim);
opacity: 0.16;
opacity: 0.38;
pointer-events: none;
}
Expand Down
40 changes: 21 additions & 19 deletions src/components/Sing/SequencerLoopControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns="http://www.w3.org/2000/svg"
:width
:height="32"
shape-rendering="crispEdges"
shape-rendering="geometricPrecision"
>
<!-- ループ範囲 -->
<rect
Expand All @@ -18,22 +18,24 @@
<!-- ループ開始ハンドル -->
<path
v-if="isLoopEnabled"
:d="`M${loopStartX - offset},0 L${loopStartX - offset},16 L${loopStartX - offset + 12},0 Z`"
:d="`M${loopStartX - offset},0 L${loopStartX - offset},15 L${loopStartX - offset + 12},0 Z`"
class="loop-handle loop-start-handle"
:class="{ 'loop-handle-disabled': loopStartTick === loopEndTick }"
/>
<!-- ループ終了ハンドル -->
<path
v-if="isLoopEnabled"
:d="`M${loopEndX - offset},0 L${loopEndX - offset},16 L${loopEndX - offset - 12},0 Z`"
:d="`M${loopEndX - offset},0 L${loopEndX - offset},15 L${loopEndX - offset - 12},0 Z`"
class="loop-handle loop-end-handle"
:class="{ 'loop-handle-disabled': loopStartTick === loopEndTick }"
/>
<!-- ループ開始ドラッグ領域 -->
<rect
v-if="isLoopEnabled"
:x="loopStartX - offset - 4"
y="0"
width="8"
height="32"
width="16"
height="28"
class="loop-drag-area"
@mousedown.stop="startDragging('start', $event)"
/>
Expand All @@ -42,8 +44,8 @@
v-if="isLoopEnabled"
:x="loopEndX - offset - 4"
y="0"
width="8"
height="32"
width="16"
height="28"
class="loop-drag-area"
@mousedown.stop="startDragging('end', $event)"
/>
Expand Down Expand Up @@ -105,13 +107,10 @@ const onDrag = (event: MouseEvent) => {
const dx = event.clientX - dragStartX.value;
const newX = dragStartHandleX.value + dx;
let newTick = Math.max(
0,
baseXToTick(newX / sequencerZoomX.value, tpqn.value),
);
const baseTick = baseXToTick(newX / sequencerZoomX.value, tpqn.value);
// スナップ処理
newTick = snapToGrid(newTick);
const newTick = Math.max(0, snapToGrid(baseTick));
try {
if (dragTarget.value === "start") {
Expand All @@ -120,13 +119,10 @@ const onDrag = (event: MouseEvent) => {
} else {
// 開始ハンドルが終了ハンドルを超えた場合、開始と終了を入れ替える
setLoopRange(loopEndTick.value, newTick);
// ドラッグ対象を終了ハンドルに切り替え
dragTarget.value = "end";
// ドラッグ開始点を現在のカーソル位置に再設定
dragStartX.value = event.clientX;
// 新しいドラッグ開始ハンドル位置を再計算
dragStartHandleX.value =
tickToBaseX(loopEndTick.value, tpqn.value) * sequencerZoomX.value;
Expand All @@ -137,20 +133,17 @@ const onDrag = (event: MouseEvent) => {
} else {
// 終了ハンドルが開始ハンドルを下回った場合、開始と終了を入れ替える
setLoopRange(newTick, loopStartTick.value);
// ドラッグ対象を開始ハンドルに切り替え
dragTarget.value = "start";
// ドラッグ開始点を現在のカーソル位置に再設定
dragStartX.value = event.clientX;
// 新しいドラッグ開始ハンドル位置を再計算
dragStartHandleX.value =
tickToBaseX(loopStartTick.value, tpqn.value) * sequencerZoomX.value;
}
}
} catch (error) {
throw new Error("Error setting loop range");
throw new Error("Could not set loop range");
}
};
Expand Down Expand Up @@ -189,9 +182,18 @@ onUnmounted(() => {
.loop-handle {
fill: var(--scheme-color-primary);
pointer-events: none;
stroke: var(--scheme-color-primary);
stroke-width: 2;
stroke-linejoin: round;
&.loop-handle-disabled {
fill: var(--scheme-color-secondary);
stroke: var(--scheme-color-secondary);
}
}
.loop-drag-area {
height: 28px;
fill: transparent;
cursor: ew-resize;
pointer-events: all;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sing/SequencerRuler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,6 @@ onUnmounted(() => {
.sequencer-ruler-loop-mask {
fill: var(--scheme-color-scrim);
opacity: 0.16;
opacity: 0.38;
}
</style>
3 changes: 0 additions & 3 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2466,9 +2466,6 @@ export const singingStore = createPartialStore<SingingStoreTypes>({

SET_LOOP_RANGE: {
mutation(state, { loopStartTick, loopEndTick }) {
if (loopStartTick >= loopEndTick) {
throw new Error("Loop start must be before loop end");
}
state.loopStartTick = loopStartTick;
state.loopEndTick = loopEndTick;
},
Expand Down

0 comments on commit f03c07f

Please sign in to comment.