forked from VOICEVOX/voicevox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioAccent.vue
165 lines (156 loc) · 4.09 KB
/
AudioAccent.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
<div
class="accent-slider-cell"
:style="{
'grid-column': `1 / span ${accentPhrase.moras.length * 2 - 1}`,
}"
>
<!-- div for input width -->
<div>
<div>
<QSlider
v-if="accentPhrase.moras.length > 1"
snap
dense
color="primary"
trackSize="2px"
:min="previewAccentSlider.qSliderProps.min.value"
:max="previewAccentSlider.qSliderProps.max.value"
:step="previewAccentSlider.qSliderProps.step.value"
:disable="previewAccentSlider.qSliderProps.disable.value"
:modelValue="previewAccentSlider.qSliderProps.modelValue.value"
@update:modelValue="
previewAccentSlider.qSliderProps['onUpdate:modelValue']
"
@click.stop="stopPropagation"
@change="previewAccentSlider.qSliderProps.onChange"
@wheel="previewAccentSlider.qSliderProps.onWheel"
@pan="previewAccentSlider.qSliderProps.onPan"
/>
</div>
</div>
</div>
<div
class="accent-draw-cell"
:style="{
'grid-column': `1 / span ${accentPhrase.moras.length * 2 - 1}`,
}"
>
<svg :viewBox="`0 0 ${accentPhrase.moras.length * 40 - 20} 50`">
<polyline :points="accentLine" />
</svg>
</div>
<template v-for="(mora, moraIndex) in accentPhrase.moras" :key="moraIndex">
<div
:class="[
'accent-select-cell',
{
'accent-select-cell-selected':
previewAccentSlider.state.currentValue.value == moraIndex + 1,
},
]"
:style="{ 'grid-column': `${moraIndex * 2 + 1} / span 1` }"
@click="uiLocked || changeAccent(moraIndex + 1)"
>
<svg width="19" height="50" viewBox="0 0 19 50">
<line x1="9" y1="0" x2="9" y2="50" stroke-width="1" />
</svg>
</div>
</template>
</template>
<script setup lang="ts">
import { computed } from "vue";
import { previewSliderHelper } from "@/helpers/previewSliderHelper";
import { AccentPhrase } from "@/openapi";
const props = withDefaults(
defineProps<{
accentPhrase: AccentPhrase;
accentPhraseIndex: number;
uiLocked: boolean;
shiftKeyFlag?: boolean;
onChangeAccent: (
accentPhraseIndex: number,
accent: number,
) => Promise<void>;
}>(),
{
shiftKeyFlag: false,
},
);
const changeAccent = (accent: number) =>
props.onChangeAccent(props.accentPhraseIndex, accent);
const previewAccentSlider = previewSliderHelper({
onChange: changeAccent,
modelValue: () => props.accentPhrase.accent,
disable: () => props.uiLocked,
disableScroll: () => props.shiftKeyFlag,
max: () => props.accentPhrase.moras.length,
min: () => 1,
step: () => 1,
});
const accentLine = computed(() => {
const accent = previewAccentSlider.state.currentValue.value ?? 0;
return [...Array(props.accentPhrase.moras.length).keys()]
.map(
(index) =>
`${index * 40 + 10} ${
index + 1 == accent || (index != 0 && index < accent) ? 5 : 45
}`,
)
.toString();
});
// クリックでアクセント句が選択されないように、@click.stopに渡す
const stopPropagation = () => {
// fn is not a function エラーを回避するために何もしない関数を渡す
};
</script>
<style scoped lang="scss">
@use "@/styles/colors" as colors;
div {
padding: 0px;
&.accent-slider-cell {
grid-row-start: 1;
align-self: flex-end;
margin-left: 5px;
margin-right: 10px;
position: relative;
> div {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 18px;
> div {
padding-left: 5px;
}
}
}
&.accent-draw-cell {
grid-row-start: 2;
svg {
line {
stroke: colors.$display;
}
polyline {
stroke: colors.$display;
fill: none;
}
}
}
&.accent-select-cell {
grid-row-start: 2;
text-align: center;
cursor: pointer;
svg line {
stroke: colors.$primary;
stroke-dasharray: 3;
}
}
&.accent-select-cell-selected {
svg line {
stroke-dasharray: none;
stroke-width: 3;
}
}
}
</style>