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

ソング:再生位置の表示形式を変更できるようにする #2306

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9f648aa
MBSR形式で表示するように変更、秒とMBSRどちらで表示するかを切り替えられるようにした
sigprogramming Oct 19, 2024
63336c1
拍と16分が1始まりになるように修正、コメントを追加
sigprogramming Oct 19, 2024
c41505b
修正、MBSRからMBSに変更
sigprogramming Oct 19, 2024
4563324
tickからMBSに変換する処理をdomain.tsに移動
sigprogramming Oct 19, 2024
4e9c638
変数名とclass名を変更
sigprogramming Oct 19, 2024
6c35780
小節.拍.100分に変更、MBS型からMeasuresBeats型に変更
sigprogramming Oct 22, 2024
840eab3
右クリックメニューの表記を変更
sigprogramming Oct 22, 2024
613cf65
再生ヘッド位置の表示モードが設定として保存されるようにした
sigprogramming Oct 22, 2024
725d0d0
デフォルトの表示モードを秒に変更[update snapshots]
sigprogramming Oct 22, 2024
f370ccb
displayModeからdisplayFormatに変更、リファクタリング
sigprogramming Oct 23, 2024
802a8f0
関数を削除
sigprogramming Oct 24, 2024
13365c1
Update src/components/Sing/PlayheadPositionDisplay.vue
sigprogramming Oct 24, 2024
4055aca
再生ヘッド位置の取得・設定処理をコンポーザブル化
sigprogramming Oct 24, 2024
06a8af7
SCREAMING_SNAKE_CASEに変更
sigprogramming Oct 24, 2024
3f9f201
修正
sigprogramming Oct 24, 2024
aa96997
Merge branch 'main' into display_playhead_position_in_mbsr_format
sigprogramming Oct 24, 2024
a52bd76
playheadPositionをRefにして、FrequentlyUpdatedStateとusePlayheadPositionを削除
sigprogramming Oct 26, 2024
6c3e1c2
MeasuresBeatsを移動
sigprogramming Oct 28, 2024
c6eeed2
PLAYHEAD_POSITIONの同期処理を削除
sigprogramming Oct 28, 2024
ba88ed9
displayFormatのチェックを行っているところを削除、importのところが変更できていなかったので修正
sigprogramming Oct 28, 2024
dd7c1b4
tpqnのバリデーション処理が間違っていたので修正
sigprogramming Oct 28, 2024
4d63b33
// オートスクロールの位置変更
Hiroshiba Oct 28, 2024
83fc8ba
Merge remote-tracking branch 'upstream/main' into pr/sigprogramming/2…
Hiroshiba Oct 28, 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
217 changes: 217 additions & 0 deletions src/components/Sing/PlayheadPositionDisplay.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<template>
<div>
<div v-if="displayMode === 'Seconds'" class="playhead-position">
<div class="min-and-sec">{{ minAndSecStr }}</div>
<div class="millisec">.{{ milliSecStr }}</div>
</div>
<div v-if="displayMode === 'MBS'" class="playhead-position">
<div class="measures">{{ measuresStr }}.</div>
<div class="beats">{{ beatsStr }}.</div>
<div class="sixteenths-integer-part">{{ sixteenthsIntegerPartStr }}</div>
<div class="sixteenths-decimal-part">.{{ sixteenthsDecimalPartStr }}</div>
</div>
<ContextMenu ref="contextMenu" :menudata="contextMenuData" />
</div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, onUnmounted, Ref } from "vue";
import { useStore } from "@/store";
import ContextMenu, {
ContextMenuItemData,
} from "@/components/Menu/ContextMenu.vue";
import {
getBeatDuration,
getMeasureDuration,
getTimeSignaturePositions,
} from "@/sing/domain";
import { TimeSignature } from "@/store/type";

const store = useStore();

const playheadTicks = ref(0);
const displayMode: Ref<"Seconds" | "MBS"> = ref("MBS");

const timeSignatures = computed(() => {
const tpqn = store.state.tpqn;
const timeSignatures = store.state.timeSignatures;
const tsPositions = getTimeSignaturePositions(timeSignatures, tpqn);
return timeSignatures.map((value, index) => ({
...value,
position: tsPositions[index],
}));
});

const findTimeSignatureIndex = (
ticks: number,
timeSignatures: (TimeSignature & { position: number })[],
) => {
if (ticks < 0) {
return 0;
}
for (let i = 0; i < timeSignatures.length - 1; i++) {
if (
timeSignatures[i].position <= ticks &&
timeSignatures[i + 1].position > ticks
) {
return i;
}
}
return timeSignatures.length - 1;
};

// Measures, Beats, Sixteenths
const mbs = computed(() => {
if (displayMode.value !== "MBS") {
return { measures: 1, beats: 1, sixteenths: 1, remaining: 0 };
}
const tpqn = store.state.tpqn;

const ticks = playheadTicks.value;

const tsIndex = findTimeSignatureIndex(ticks, timeSignatures.value);
const ts = timeSignatures.value[tsIndex];

const measureDuration = getMeasureDuration(ts.beats, ts.beatType, tpqn);
const beatDuration = getBeatDuration(ts.beats, ts.beatType, tpqn);
const sixteenthDuration = tpqn / 4;

const posInTs = ticks - ts.position;
const measuresInTs = Math.floor(posInTs / measureDuration);
const measures = ts.measureNumber + measuresInTs;

const posInMeasure = posInTs - measureDuration * measuresInTs;
const beats = 1 + Math.floor(posInMeasure / beatDuration);

const posInBeat = posInMeasure - beatDuration * (beats - 1);
const sixteenths = 1 + posInBeat / sixteenthDuration;

return { measures, beats, sixteenths };
});

sevenc-nanashi marked this conversation as resolved.
Show resolved Hide resolved
const measuresStr = computed(() => {
return mbs.value.measures >= 0
? String(mbs.value.measures).padStart(3, "0")
: String(mbs.value.measures);
});

const beatsStr = computed(() => {
return String(mbs.value.beats).padStart(2, "0");
});

const sixteenthsIntegerPartStr = computed(() => {
const integerPart = Math.floor(mbs.value.sixteenths);
return String(integerPart).padStart(2, "0");
});

const sixteenthsDecimalPartStr = computed(() => {
const integerPart = Math.floor(mbs.value.sixteenths);
const decimalPart = Math.floor((mbs.value.sixteenths - integerPart) * 100);
return String(decimalPart).padStart(2, "0");
});

const minAndSecStr = computed(() => {
if (displayMode.value !== "Seconds") {
return "";
}
const ticks = playheadTicks.value;
const time = store.getters.TICK_TO_SECOND(ticks);
const intTime = Math.trunc(time);
const min = Math.trunc(intTime / 60);
const minStr = String(min).padStart(2, "0");
const secStr = String(intTime - min * 60).padStart(2, "0");
return `${minStr}:${secStr}`;
});

const milliSecStr = computed(() => {
if (displayMode.value !== "Seconds") {
return "";
}
const ticks = playheadTicks.value;
const time = store.getters.TICK_TO_SECOND(ticks);
const intTime = Math.trunc(time);
const milliSec = Math.trunc((time - intTime) * 1000);
const milliSecStr = String(milliSec).padStart(3, "0");
return milliSecStr;
});

const contextMenu = ref<InstanceType<typeof ContextMenu>>();
const contextMenuData = computed<ContextMenuItemData[]>(() => {
return [
{
type: "button",
label: "小節",
disabled: displayMode.value === "MBS",
onClick: async () => {
contextMenu.value?.hide();
displayMode.value = "MBS";
},
disableWhenUiLocked: false,
},
{
type: "button",
label: "秒",
disabled: displayMode.value === "Seconds",
onClick: async () => {
contextMenu.value?.hide();
displayMode.value = "Seconds";
},
disableWhenUiLocked: false,
},
];
});

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,
});
});
sigprogramming marked this conversation as resolved.
Show resolved Hide resolved
</script>

<style scoped lang="scss">
@use "@/styles/v2/variables" as vars;
@use "@/styles/colors" as colors;

.playhead-position {
align-items: center;
display: flex;
font-weight: 700;
color: var(--scheme-color-on-surface);
}

.min-and-sec {
font-size: 28px;
}

.millisec {
font-size: 16px;
margin: 10px 0 0 2px;
}

.measures {
font-size: 24px;
}

.beats {
font-size: 24px;
}

.sixteenths-integer-part {
font-size: 24px;
}

.sixteenths-decimal-part {
font-size: 16px;
margin: 6px 0 0 2px;
}
</style>
62 changes: 3 additions & 59 deletions src/components/Sing/ToolBar/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@
icon="stop"
@click="stop"
/>
<div class="sing-playhead-position">
<div>{{ playheadPositionMinSecStr }}</div>
<div class="sing-playhead-position-millisec">
.{{ playHeadPositionMilliSecStr }}
</div>
</div>
<PlayheadPositionDisplay class="sing-playhead-position" />
</div>
<!-- settings for edit controls -->
<div class="sing-controls">
Expand Down Expand Up @@ -164,7 +159,8 @@
</template>

<script setup lang="ts">
import { computed, watch, ref, onMounted, onUnmounted } from "vue";
import { computed, watch, ref } from "vue";
import PlayheadPositionDisplay from "../PlayheadPositionDisplay.vue";
import EditTargetSwicher from "./EditTargetSwicher.vue";
import { useStore } from "@/store";

Expand Down Expand Up @@ -383,30 +379,6 @@ const setVolumeRangeAdjustment = () => {
});
};

const playheadTicks = ref(0);

/// 再生時間の分と秒
const playheadPositionMinSecStr = computed(() => {
const ticks = playheadTicks.value;
const time = store.getters.TICK_TO_SECOND(ticks);

const intTime = Math.trunc(time);
const min = Math.trunc(intTime / 60);
const minStr = String(min).padStart(2, "0");
const secStr = String(intTime - min * 60).padStart(2, "0");

return `${minStr}:${secStr}`;
});

const playHeadPositionMilliSecStr = computed(() => {
const ticks = playheadTicks.value;
const time = store.getters.TICK_TO_SECOND(ticks);
const intTime = Math.trunc(time);
const milliSec = Math.trunc((time - intTime) * 1000);
const milliSecStr = String(milliSec).padStart(3, "0");
return milliSecStr;
});

const nowPlaying = computed(() => store.state.nowPlaying);

const play = () => {
Expand Down Expand Up @@ -463,22 +435,6 @@ const snapTypeSelectModel = computed({
});
},
});

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,
});
});
</script>

<style scoped lang="scss">
Expand Down Expand Up @@ -714,19 +670,7 @@ onUnmounted(() => {
}

.sing-playhead-position {
align-items: center;
display: flex;
font-size: 28px;
font-weight: 700;
margin-left: 16px;
color: var(--scheme-color-on-surface);
}

.sing-playhead-position-millisec {
font-size: 16px;
font-weight: 700;
margin: 10px 0 0 2px;
color: var(--scheme-color-on-surface);
}

.sing-controls {
Expand Down
8 changes: 6 additions & 2 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ export function getMeasureDuration(
beatType: number,
tpqn: number,
) {
const wholeNoteDuration = tpqn * 4;
return (wholeNoteDuration / beatType) * beats;
return ((tpqn * 4) / beatType) * beats;
}

// NOTE: 戻り値の単位はtick
export function getBeatDuration(beats: number, beatType: number, tpqn: number) {
return (tpqn * 4) / beatType;
}

export function getNumMeasures(
Expand Down
Loading