|
2 | 2 | <Card> |
3 | 3 | <template v-slot:title> |
4 | 4 | <div class="flex justify-between items-center w-full"> |
5 | | - <span>{{ editorStore.isEditingFromScoreEditor ? '编辑乐谱' : '编曲文本转换工具' }}</span> |
| 5 | + <span>{{ pianoRollStore.isEditingFromScoreEditor ? '编辑乐谱' : '编曲文本转换工具' }}</span> |
6 | 6 | <div class="flex items-center gap-4"> |
7 | 7 | <div class="flex items-center gap-2"> |
8 | 8 | <label for="beatsPerBarInput" class="text-sm font-medium text-gray-300">拍/节:</label> |
|
39 | 39 | /> |
40 | 40 | </div> |
41 | 41 | <Button @click="togglePlayback">{{ isPlaying ? '停止' : '播放' }}</Button> |
42 | | - <Button v-if="editorStore.isEditingFromScoreEditor" @click="completeEditing" |
| 42 | + <Button v-if="pianoRollStore.isEditingFromScoreEditor" @click="completeEditing" |
43 | 43 | >完成编辑</Button |
44 | 44 | > |
45 | | - <Button v-if="!editorStore.isEditingFromScoreEditor" @click="onGenerateClick" |
| 45 | + <Button v-if="!pianoRollStore.isEditingFromScoreEditor" @click="onGenerateClick" |
46 | 46 | >生成模板文本</Button |
47 | 47 | > |
48 | 48 | <Button |
49 | | - v-if="!editorStore.isEditingFromScoreEditor" |
| 49 | + v-if="!pianoRollStore.isEditingFromScoreEditor" |
50 | 50 | @click="createNewScoreFromArrangement" |
51 | 51 | >以此新建乐谱</Button |
52 | 52 | > |
@@ -113,10 +113,11 @@ import { useRouter } from 'vue-router'; |
113 | 113 | import { SNTransition, type SNTemplate } from 'simple-notation'; |
114 | 114 | import * as Tone from 'tone'; |
115 | 115 | import { useTone } from '@/use'; |
116 | | -import { useEditorStore, type PianoRollNote } from '@/stores'; |
| 116 | +import { useEditorStore, usePianoRollStore, type PianoRollNote } from '@/stores'; |
117 | 117 |
|
118 | 118 | const { playNote, midiToNoteName, setInstrument } = useTone(); |
119 | 119 | const editorStore = useEditorStore(); |
| 120 | +const pianoRollStore = usePianoRollStore(); |
120 | 121 | const router = useRouter(); |
121 | 122 | const pianoGridRef = ref<InstanceType<typeof PianoGrid> | null>(null); |
122 | 123 | const isModalOpen = ref(false); |
@@ -256,34 +257,38 @@ function loadAndRenderNotes(notesToRender: PianoRollNote[], beatsInfo: number) { |
256 | 257 | tempo.value = parseInt(editorStore.formData.info.tempo || '120', 10); |
257 | 258 |
|
258 | 259 | // 3. 将转换后的音符存入 store(如果它们还不在那里) |
259 | | - if (editorStore.pianoRollNotes !== notesToRender) { |
260 | | - editorStore.pianoRollNotes = notesToRender; |
| 260 | + if (pianoRollStore.pianoRollNotes !== notesToRender) { |
| 261 | + pianoRollStore.setPianoRollNotes(notesToRender); |
261 | 262 | } |
262 | 263 | } |
263 | 264 |
|
264 | 265 | onMounted(() => { |
265 | 266 | // Case 1: 从乐谱编辑器带数据过来,需要异步转换 |
266 | | - if (editorStore.scoreToConvert && editorStore.beatsPerBarToConvert && pianoGridRef.value) { |
267 | | - editorStore.isEditingFromScoreEditor = true; |
| 267 | + if ( |
| 268 | + pianoRollStore.isEditingFromScoreEditor && |
| 269 | + pianoRollStore.scoreToConvert && |
| 270 | + pianoRollStore.beatsPerBarToConvert && |
| 271 | + pianoGridRef.value |
| 272 | + ) { |
268 | 273 | (async () => { |
269 | 274 | isLoading.value = true; |
270 | 275 | loadingProgress.value = 0; |
271 | 276 | const notes = await convertTextToNotesWithProgress( |
272 | | - editorStore.scoreToConvert!, |
273 | | - editorStore.beatsPerBarToConvert!, |
| 277 | + pianoRollStore.scoreToConvert!, |
| 278 | + pianoRollStore.beatsPerBarToConvert!, |
274 | 279 | (progress) => { |
275 | 280 | loadingProgress.value = progress; |
276 | 281 | }, |
277 | 282 | ); |
278 | | - loadAndRenderNotes(notes, editorStore.beatsPerBarToConvert!); |
| 283 | + loadAndRenderNotes(notes, pianoRollStore.beatsPerBarToConvert!); |
279 | 284 | isLoading.value = false; |
280 | | - editorStore.clearConversionData(); // 清理临时数据 |
| 285 | + pianoRollStore.clearConversionData(); // 清理临时数据 |
281 | 286 | })(); |
282 | 287 | } |
283 | 288 | // Case 2: 刷新页面或从其他页面返回,直接加载store中已有的数据 |
284 | | - else if (editorStore.isEditingFromScoreEditor && pianoGridRef.value) { |
| 289 | + else if (pianoRollStore.isEditingFromScoreEditor && pianoGridRef.value) { |
285 | 290 | const beatsInfo = parseInt(editorStore.formData.info.beat || '4', 10); |
286 | | - loadAndRenderNotes(editorStore.pianoRollNotes, beatsInfo); |
| 291 | + loadAndRenderNotes(pianoRollStore.pianoRollNotes, beatsInfo); |
287 | 292 | } |
288 | 293 | }); |
289 | 294 |
|
@@ -498,7 +503,7 @@ function completeEditing() { |
498 | 503 | const notesList = pianoGridRef.value.generateNotesList(); |
499 | 504 | const scoreText = convertNotesToText(notesList, beatsPerBar.value); |
500 | 505 | editorStore.updateScore(scoreText); // 只更新乐谱文本 |
501 | | - editorStore.isEditingFromScoreEditor = false; // 重置标志位 |
| 506 | + pianoRollStore.setIsEditingFromScoreEditor(false); // 重置标志位 |
502 | 507 | router.push('/'); |
503 | 508 | } |
504 | 509 | } |
|
0 commit comments