-
Notifications
You must be signed in to change notification settings - Fork 304
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
ソング:再生位置の表示形式を変更できるようにする #2306
Changes from 10 commits
9f648aa
63336c1
c41505b
4563324
4e9c638
6c35780
840eab3
613cf65
725d0d0
f370ccb
802a8f0
13365c1
4055aca
06a8af7
3f9f201
aa96997
a52bd76
6c3e1c2
c6eeed2
ba88ed9
dd7c1b4
4d63b33
83fc8ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<template> | ||
<div> | ||
<div v-if="displayFormat === 'MinutesSeconds'" class="playhead-position"> | ||
<div>{{ minAndSecStr }}</div> | ||
<div class="millisec">.{{ milliSecStr }}</div> | ||
</div> | ||
<div v-if="displayFormat === 'MeasuresBeats'" class="playhead-position"> | ||
<div>{{ measuresStr }}.</div> | ||
<div>{{ beatsIntegerPartStr }}</div> | ||
<div class="beats-fractional-part">.{{ beatsFractionalPartStr }}</div> | ||
</div> | ||
<ContextMenu ref="contextMenu" :menudata="contextMenuData" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, computed, onMounted, onUnmounted } from "vue"; | ||
import { useStore } from "@/store"; | ||
import ContextMenu, { | ||
ContextMenuItemData, | ||
} from "@/components/Menu/ContextMenu.vue"; | ||
import { getTimeSignaturePositions, ticksToMeasuresBeats } from "@/sing/domain"; | ||
import { MeasuresBeats } from "@/store/type"; | ||
import { useRootMiscSetting } from "@/composables/useRootMiscSetting"; | ||
|
||
const store = useStore(); | ||
|
||
const playheadTicks = ref(0); | ||
const [displayFormat, setDisplayFormat] = useRootMiscSetting( | ||
store, | ||
"playheadPositionDisplayFormat", | ||
); | ||
|
||
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 measuresBeats = computed((): MeasuresBeats => { | ||
if (displayFormat.value !== "MeasuresBeats") { | ||
return { measures: 1, beats: 1 }; | ||
} | ||
const tpqn = store.state.tpqn; | ||
return ticksToMeasuresBeats(playheadTicks.value, timeSignatures.value, tpqn); | ||
}); | ||
|
||
const measuresStr = computed(() => { | ||
return measuresBeats.value.measures >= 0 | ||
? String(measuresBeats.value.measures).padStart(3, "0") | ||
: String(measuresBeats.value.measures); | ||
}); | ||
|
||
const beatsIntegerPartStr = computed(() => { | ||
const integerPart = Math.floor(measuresBeats.value.beats); | ||
return String(integerPart).padStart(2, "0"); | ||
}); | ||
|
||
const beatsFractionalPartStr = computed(() => { | ||
const integerPart = Math.floor(measuresBeats.value.beats); | ||
const fractionalPart = Math.floor( | ||
(measuresBeats.value.beats - integerPart) * 100, | ||
); | ||
return String(fractionalPart).padStart(2, "0"); | ||
}); | ||
|
||
const minAndSecStr = computed(() => { | ||
if (displayFormat.value !== "MinutesSeconds") { | ||
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 (displayFormat.value !== "MinutesSeconds") { | ||
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: displayFormat.value === "MeasuresBeats", | ||
onClick: async () => { | ||
contextMenu.value?.hide(); | ||
setDisplayFormat("MeasuresBeats"); | ||
}, | ||
disableWhenUiLocked: false, | ||
}, | ||
{ | ||
type: "button", | ||
label: "分:秒", | ||
disabled: displayFormat.value === "MinutesSeconds", | ||
onClick: async () => { | ||
contextMenu.value?.hide(); | ||
setDisplayFormat("MinutesSeconds"); | ||
}, | ||
disableWhenUiLocked: false, | ||
}, | ||
sigprogramming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]; | ||
}); | ||
|
||
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; | ||
font-size: 28px; | ||
color: var(--scheme-color-on-surface); | ||
} | ||
|
||
.millisec { | ||
font-size: 16px; | ||
margin: 10px 0 0 2px; | ||
} | ||
|
||
.beats-fractional-part { | ||
font-size: 16px; | ||
margin: 10px 0 0 2px; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { | |
PhraseKey, | ||
Track, | ||
EditorFrameAudioQuery, | ||
MeasuresBeats, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (ただのコメントです) domainからstoreの型をimportしてるの、逆な気がしますね!! 今回のこの型に関してはstore側で全く使ってないので、多分こっちに定義する方が良さそう感あります。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 個人的にはそちらの方があってるように感じます! 解釈としては、
みたいな感じかなと! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. なるほどです! |
||
} from "@/store/type"; | ||
import { FramePhoneme } from "@/openapi"; | ||
import { TrackId } from "@/type/preload"; | ||
|
@@ -210,10 +211,53 @@ 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(beatType: number, tpqn: number) { | ||
return (tpqn * 4) / beatType; | ||
} | ||
|
||
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; | ||
}; | ||
|
||
export const ticksToMeasuresBeats = ( | ||
ticks: number, | ||
timeSignatures: (TimeSignature & { position: number })[], | ||
tpqn: number, | ||
): MeasuresBeats => { | ||
const tsIndex = findTimeSignatureIndex(ticks, timeSignatures); | ||
const ts = timeSignatures[tsIndex]; | ||
|
||
const measureDuration = getMeasureDuration(ts.beats, ts.beatType, tpqn); | ||
const beatDuration = getBeatDuration(ts.beatType, tpqn); | ||
|
||
const posInTs = ticks - ts.position; | ||
const measuresInTs = Math.floor(posInTs / measureDuration); | ||
const measures = ts.measureNumber + measuresInTs; | ||
|
||
const posInMeasure = posInTs - measureDuration * measuresInTs; | ||
const beats = 1 + posInMeasure / beatDuration; | ||
|
||
return { measures, beats }; | ||
}; | ||
|
||
export function getNumMeasures( | ||
notes: Note[], | ||
tempos: Tempo[], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(割とただのコメントです)
ここの更新速度が早すぎて、若干目が使えるなと感じました!
ただまあ、別にこれでいい感じなのかなーとも思ってます。どうしようもない!