Skip to content

Commit 8847bef

Browse files
RomotRomot
Romot
authored and
Romot
committed
#1818 調整
1 parent 64a2c2c commit 8847bef

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/components/Dialog/ImportMidiDialog.vue

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<QDialog ref="dialogRef" persistent>
2+
<QDialog ref="dialogRef" auto-scroll @before-show="initializeValues">
33
<QLayout container view="hHh lpr fFf" class="q-dialog-plugin bg-background">
44
<QHeader>
55
<QToolbar>
@@ -14,14 +14,15 @@
1414
<QToolbarTitle>MIDIファイルのインポート</QToolbarTitle>
1515
</QToolbar>
1616
</QHeader>
17-
<QPageContainer class="q-px-lg">
17+
<QPageContainer class="q-px-lg q-py-md">
1818
<QFile
1919
v-model="midiFile"
20-
label="MIDIファイルを指定"
20+
label="MIDIファイル"
2121
class="q-my-sm"
2222
accept=".mid,.midi"
23-
:error-message="fileError"
24-
:error="!!fileError"
23+
:error-message="midiFileError"
24+
:error="!!midiFileError"
25+
placeholder="MIDIファイルを選択してください"
2526
@input="handleMidiFileChange"
2627
/>
2728
<QSelect
@@ -30,7 +31,7 @@
3031
:options="tracks"
3132
emit-value
3233
map-options
33-
label="トラックを選択"
34+
label="インポートするトラック"
3435
/>
3536
</QPageContainer>
3637
<QFooter>
@@ -71,17 +72,20 @@ const { dialogRef, onDialogOK, onDialogCancel } = useDialogPluginComponent();
7172
7273
const store = useStore();
7374
75+
// MIDIファイル
7476
const midiFile = ref<File | null>(null);
75-
const midi = ref<Midi | null>(null);
76-
const fileError = computed(() => {
77+
// MIDIファイルエラー
78+
const midiFileError = computed(() => {
7779
if (midiFile.value && !midi.value) {
7880
return "MIDIファイルの読み込みに失敗しました";
7981
} else if (midiFile.value && midi.value && !midi.value.tracks.length) {
8082
return "トラックがありません";
8183
}
8284
return undefined;
8385
});
84-
const selectedTrack = ref<string | number | null>(null);
86+
// MIDIデータ(tone.jsでパースしたもの)
87+
const midi = ref<Midi | null>(null);
88+
// トラック
8589
const tracks = computed(() =>
8690
midi.value
8791
? midi.value.tracks.map((track, index) => ({
@@ -90,29 +94,29 @@ const tracks = computed(() =>
9094
}))
9195
: []
9296
);
97+
// 選択中のトラック
98+
const selectedTrack = ref<string | number | null>(null);
9399
94-
const resetMidiFile = () => {
100+
// データ初期化
101+
const initializeValues = () => {
95102
midiFile.value = null;
96-
};
97-
98-
const resetValues = () => {
99103
midi.value = null;
100104
selectedTrack.value = null;
101105
};
102106
107+
// MIDIファイル変更時
103108
const handleMidiFileChange = (event: Event) => {
104109
const input = event.target as HTMLInputElement;
105110
if (!input.files) return;
111+
midi.value = null;
112+
selectedTrack.value = null;
106113
const file = input.files[0];
107114
const reader = new FileReader();
108115
reader.onload = (e) => {
109-
resetValues();
110116
midi.value = new Midi(e.target?.result as ArrayBuffer);
111117
selectedTrack.value = 0;
112118
};
113119
reader.onerror = () => {
114-
resetMidiFile();
115-
resetValues();
116120
throw new Error("Failed to read MIDI file");
117121
};
118122
reader.readAsArrayBuffer(file);
@@ -124,12 +128,8 @@ const handleImportTrack = () => {
124128
trackIndex: selectedTrack.value as number,
125129
});
126130
onDialogOK();
127-
resetMidiFile();
128-
resetValues();
129131
};
130132
const handleCancel = () => {
131133
onDialogCancel();
132-
resetMidiFile();
133-
resetValues();
134134
};
135135
</script>

0 commit comments

Comments
 (0)