|
@@ -27,12 +27,12 @@ export default defineComponent({
|
|
|
"1/32.": "6",
|
|
|
rest: "7"
|
|
|
}
|
|
|
- const rhythmData = ref<rhythmData[]>([])
|
|
|
+ const rhythmData = ref<rhythmData[][]>([])
|
|
|
const actRhythmData = computed<rhythmData[]>(() => {
|
|
|
- return rhythmData.value.slice(state.activeNoteIndex, state.activeNoteIndex + 7)
|
|
|
+ return rhythmData.value[Math.floor(state.activeNoteIndex / 6)]
|
|
|
})
|
|
|
function initRhythmData() {
|
|
|
- rhythmData.value = state.times.map(item => {
|
|
|
+ const rhythmArr = state.times.map(item => {
|
|
|
const noteElement = item.noteElement
|
|
|
const isDot = !!noteElement?.DotsXml
|
|
|
const denominator = noteElement?.typeLength?.denominator || 4
|
|
@@ -44,6 +44,17 @@ export default defineComponent({
|
|
|
rhythmImg: isRestFlag ? "rest" : `1/${denominator}${isDot ? "." : ""}`
|
|
|
}
|
|
|
})
|
|
|
+ rhythmData.value = splitArrayWithReduce(rhythmArr, 6)
|
|
|
+ }
|
|
|
+ function splitArrayWithReduce(arr: any[], chunkSize: number) {
|
|
|
+ return arr.reduce((result, item, index) => {
|
|
|
+ const chunkIndex = Math.floor(index / chunkSize)
|
|
|
+ if (!result[chunkIndex]) {
|
|
|
+ result[chunkIndex] = [] // 初始化一个新组
|
|
|
+ }
|
|
|
+ result[chunkIndex].push(item)
|
|
|
+ return result
|
|
|
+ }, [])
|
|
|
}
|
|
|
initRhythmData()
|
|
|
return () => {
|
|
@@ -52,8 +63,17 @@ export default defineComponent({
|
|
|
<div class={[styles.rhythm, headTopData.rhythmModeDirection === "vertical" && styles.vertical]}>
|
|
|
<div class={styles.titImg}></div>
|
|
|
<div class={styles.rhythmBox}>
|
|
|
- {actRhythmData.value.map(item => {
|
|
|
- return <div class={[styles.rhythmImg, styles[`rhythm${rhythmImgObj[item.rhythmImg]}`]]}></div>
|
|
|
+ <div class={[styles.rhythmImg, styles[`rhythm${rhythmImgObj[actRhythmData.value[state.activeNoteIndex % 6].rhythmImg]}`]]}></div>
|
|
|
+ {actRhythmData.value.map((item, index) => {
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ class={[
|
|
|
+ styles.rhythmImg,
|
|
|
+ styles[`rhythm${rhythmImgObj[item.rhythmImg]}`],
|
|
|
+ state.activeNoteIndex % 6 === index && styles.active
|
|
|
+ ]}
|
|
|
+ ></div>
|
|
|
+ )
|
|
|
})}
|
|
|
</div>
|
|
|
</div>
|