Skip to content

Commit 302a892

Browse files
committed
Add singer background
1 parent 65e73a0 commit 302a892

7 files changed

Lines changed: 176 additions & 3 deletions

File tree

src/plugins/audio/internal/waveformsinger/WaveformSingerMetadata.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace Audio::Internal {
6969
info.setName(tr("Waveform Synthesizer"));
7070
info.setMixGroup(QStringLiteral("waveform"));
7171
info.setAvatarUrl(QUrl(QStringLiteral("qrc:/diffscope/audio/singeravatar/waveform.svg")));
72+
info.setBackgroundUrl(QUrl(QStringLiteral("qrc:/diffscope/audio/singeravatar/waveform_portrait.svg")));
7273
info.setDefaultExtra(QJsonObject{
7374
{QStringLiteral("type"), WaveformSingerTypeCatalog::fallbackType()},
7475
});

src/plugins/audio/res/singeravatar/waveform_portrait.svg

Lines changed: 2 additions & 0 deletions
Loading

src/plugins/visualeditor/internal/EditorPreference.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace VisualEditor::Internal {
2525
bool displayPronunciationBelowNote{};
2626
int shortNoteThreshold{30};
2727
bool trackCursorPosition{true};
28+
bool showSingerBackground{true};
29+
double singerBackgroundOpacity{0.25};
2830
};
2931

3032
static EditorPreference *m_instance = nullptr;
@@ -72,6 +74,11 @@ namespace VisualEditor::Internal {
7274
emit shortNoteThresholdChanged();
7375
d->trackCursorPosition = settings->value("trackCursorPosition", true).toBool();
7476
emit trackCursorPositionChanged();
77+
d->showSingerBackground = settings->value("showSingerBackground", true).toBool();
78+
emit showSingerBackgroundChanged();
79+
d->singerBackgroundOpacity = qBound(
80+
0.0, settings->value("singerBackgroundOpacity", 0.25).toDouble(), 1.0);
81+
emit singerBackgroundOpacityChanged();
7582
settings->endGroup();
7683
}
7784

@@ -92,6 +99,8 @@ namespace VisualEditor::Internal {
9299
settings->setValue("displayPronunciationBelowNote", d->displayPronunciationBelowNote);
93100
settings->setValue("shortNoteThreshold", d->shortNoteThreshold);
94101
settings->setValue("trackCursorPosition", d->trackCursorPosition);
102+
settings->setValue("showSingerBackground", d->showSingerBackground);
103+
settings->setValue("singerBackgroundOpacity", d->singerBackgroundOpacity);
95104
settings->endGroup();
96105
}
97106

@@ -267,4 +276,31 @@ namespace VisualEditor::Internal {
267276
emit m_instance->trackCursorPositionChanged();
268277
}
269278

279+
bool EditorPreference::showSingerBackground() {
280+
M_INSTANCE_D;
281+
return d->showSingerBackground;
282+
}
283+
284+
void EditorPreference::setShowSingerBackground(bool showSingerBackground) {
285+
M_INSTANCE_D;
286+
if (d->showSingerBackground == showSingerBackground)
287+
return;
288+
d->showSingerBackground = showSingerBackground;
289+
emit m_instance->showSingerBackgroundChanged();
290+
}
291+
292+
double EditorPreference::singerBackgroundOpacity() {
293+
M_INSTANCE_D;
294+
return d->singerBackgroundOpacity;
295+
}
296+
297+
void EditorPreference::setSingerBackgroundOpacity(double singerBackgroundOpacity) {
298+
M_INSTANCE_D;
299+
singerBackgroundOpacity = qBound(0.0, singerBackgroundOpacity, 1.0);
300+
if (qFuzzyCompare(d->singerBackgroundOpacity, singerBackgroundOpacity))
301+
return;
302+
d->singerBackgroundOpacity = singerBackgroundOpacity;
303+
emit m_instance->singerBackgroundOpacityChanged();
304+
}
305+
270306
}

src/plugins/visualeditor/internal/EditorPreference.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace VisualEditor::Internal {
3232
Q_PROPERTY(bool displayPronunciationBelowNote READ displayPronunciationBelowNote WRITE setDisplayPronunciationBelowNote NOTIFY displayPronunciationBelowNoteChanged)
3333
Q_PROPERTY(int shortNoteThreshold READ shortNoteThreshold WRITE setShortNoteThreshold NOTIFY shortNoteThresholdChanged)
3434
Q_PROPERTY(bool trackCursorPosition READ trackCursorPosition WRITE setTrackCursorPosition NOTIFY trackCursorPositionChanged)
35+
Q_PROPERTY(bool showSingerBackground READ showSingerBackground WRITE setShowSingerBackground NOTIFY showSingerBackgroundChanged)
36+
Q_PROPERTY(double singerBackgroundOpacity READ singerBackgroundOpacity WRITE setSingerBackgroundOpacity NOTIFY singerBackgroundOpacityChanged)
3537

3638
public:
3739
~EditorPreference() override;
@@ -98,6 +100,12 @@ namespace VisualEditor::Internal {
98100
static bool trackCursorPosition();
99101
static void setTrackCursorPosition(bool trackCursorPosition);
100102

103+
static bool showSingerBackground();
104+
static void setShowSingerBackground(bool showSingerBackground);
105+
106+
static double singerBackgroundOpacity();
107+
static void setSingerBackgroundOpacity(double singerBackgroundOpacity);
108+
101109
Q_SIGNALS:
102110
void alternateAxisModifierChanged();
103111
void zoomModifierChanged();
@@ -112,6 +120,8 @@ namespace VisualEditor::Internal {
112120
void displayPronunciationBelowNoteChanged();
113121
void shortNoteThresholdChanged();
114122
void trackCursorPositionChanged();
123+
void showSingerBackgroundChanged();
124+
void singerBackgroundOpacityChanged();
115125

116126
private:
117127
friend class VisualEditorPlugin;
@@ -121,4 +131,4 @@ namespace VisualEditor::Internal {
121131

122132
}
123133

124-
#endif //DIFFSCOPE_VISUALEDITOR_EDITORPREFERENCE_H
134+
#endif //DIFFSCOPE_VISUALEDITOR_EDITORPREFERENCE_H

src/plugins/visualeditor/internal/settings/EditorPage.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ namespace VisualEditor::Internal {
7171
qCDebug(lcEditorPage) << m_widget->property("shortNoteThreshold");
7272
m_widget->setProperty("trackCursorPosition", EditorPreference::instance()->property("trackCursorPosition"));
7373
qCDebug(lcEditorPage) << m_widget->property("trackCursorPosition");
74+
m_widget->setProperty("showSingerBackground", EditorPreference::instance()->property("showSingerBackground"));
75+
qCDebug(lcEditorPage) << m_widget->property("showSingerBackground");
76+
m_widget->setProperty("singerBackgroundOpacity", EditorPreference::instance()->property("singerBackgroundOpacity"));
77+
qCDebug(lcEditorPage) << m_widget->property("singerBackgroundOpacity");
7478
m_widget->setProperty("started", true);
7579
Core::ISettingPage::beginSetting();
7680
}
@@ -103,6 +107,10 @@ namespace VisualEditor::Internal {
103107
EditorPreference::instance()->setProperty("shortNoteThreshold", m_widget->property("shortNoteThreshold"));
104108
qCDebug(lcEditorPage) << "trackCursorPosition" << m_widget->property("trackCursorPosition");
105109
EditorPreference::instance()->setProperty("trackCursorPosition", m_widget->property("trackCursorPosition"));
110+
qCDebug(lcEditorPage) << "showSingerBackground" << m_widget->property("showSingerBackground");
111+
EditorPreference::instance()->setProperty("showSingerBackground", m_widget->property("showSingerBackground"));
112+
qCDebug(lcEditorPage) << "singerBackgroundOpacity" << m_widget->property("singerBackgroundOpacity");
113+
EditorPreference::instance()->setProperty("singerBackgroundOpacity", m_widget->property("singerBackgroundOpacity"));
106114
EditorPreference::instance()->save();
107115
return Core::ISettingPage::accept();
108116
}
@@ -133,4 +141,4 @@ namespace VisualEditor::Internal {
133141
return ret;
134142
}
135143

136-
}
144+
}

src/plugins/visualeditor/qml/PianoRollView.qml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ Item {
5050
noteStartCursorBinding.when || noteEndCursorBinding.when
5151
|| pitchAnchorCursorBinding.when || pitchFreeEditCursorBinding.when
5252

53+
readonly property var singerBackgroundIds:
54+
flattenUniqueSingerIds(singerBackgroundIdProvider.singerTree)
55+
56+
function flattenUniqueSingerIds(singerTree) {
57+
const singerIds = []
58+
59+
function appendSingerIds(node) {
60+
if (typeof node === "string") {
61+
if (node !== "" && !singerIds.includes(node))
62+
singerIds.push(node)
63+
return
64+
}
65+
if (!node || typeof node.length !== "number")
66+
return
67+
for (let index = 0; index < node.length; ++index)
68+
appendSingerIds(node[index])
69+
}
70+
71+
appendSingerIds(singerTree)
72+
return singerIds
73+
}
74+
75+
ClipSingerIdProvider {
76+
id: singerBackgroundIdProvider
77+
sources: view.pianoRollPanelInterface?.editingClip?.sources ?? null
78+
}
79+
5380
function mapClipPositionToTimeline(position: int, clipViewModel): int {
5481
return position + (clipViewModel?.position ?? 0)
5582
- (clipViewModel?.clipStart ?? 0)
@@ -722,6 +749,54 @@ Item {
722749
clavierViewModel: view.pianoRollPanelInterface?.clavierViewModel ?? null
723750
scaleHighlightSequenceViewModel: view.pianoRollPanelInterface?.scaleHighlightEnabled ? (view.projectViewModelContext?.scaleHighlightSequenceViewModel ?? null) : null
724751
}
752+
RowLayout {
753+
id: singerBackgroundRow
754+
755+
anchors.top: parent.top
756+
anchors.right: parent.right
757+
anchors.bottom: parent.bottom
758+
anchors.margins: 32
759+
spacing: 16
760+
visible: EditorPreference.showSingerBackground
761+
opacity: EditorPreference.singerBackgroundOpacity
762+
763+
Repeater {
764+
model: view.singerBackgroundIds
765+
766+
delegate: Image {
767+
id: singerBackgroundImage
768+
769+
required property string modelData
770+
771+
readonly property url backgroundUrl:
772+
singerInfoProvider.info.backgroundUrl
773+
readonly property bool hasBackground:
774+
singerInfoProvider.exists
775+
&& String(backgroundUrl).length > 0
776+
777+
Layout.fillHeight: true
778+
Layout.preferredWidth: hasBackground
779+
&& sourceSize.height > 0
780+
? singerBackgroundRow.height
781+
* sourceSize.width
782+
/ sourceSize.height
783+
: 0
784+
785+
visible: hasBackground
786+
source: hasBackground ? backgroundUrl : ""
787+
fillMode: Image.PreserveAspectFit
788+
asynchronous: true
789+
mipmap: true
790+
791+
SingerInfoProvider {
792+
id: singerInfoProvider
793+
registry: CoreInterface.singerRegistry
794+
architectureId: singerBackgroundIdProvider.architectureId
795+
singerId: singerBackgroundImage.modelData
796+
}
797+
}
798+
}
799+
}
725800
Item {
726801
id: noteEditLayerSequenceStack
727802
anchors.fill: parent

src/plugins/visualeditor/qml/settings/EditorPage.qml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ ScrollView {
2626
property bool displayPronunciationBelowNote: false
2727
property int shortNoteThreshold: 30
2828
property bool trackCursorPosition: false
29+
property bool showSingerBackground: true
30+
property double singerBackgroundOpacity: 0.25
2931

3032
onAlternateAxisModifierChanged: if (started) pageHandle.markDirty()
3133
onZoomModifierChanged: if (started) pageHandle.markDirty()
@@ -40,6 +42,8 @@ ScrollView {
4042
onDisplayPronunciationBelowNoteChanged: if (started) pageHandle.markDirty()
4143
onShortNoteThresholdChanged: if (started) pageHandle.markDirty()
4244
onTrackCursorPositionChanged: if (started) pageHandle.markDirty()
45+
onShowSingerBackgroundChanged: if (started) pageHandle.markDirty()
46+
onSingerBackgroundOpacityChanged: if (started) pageHandle.markDirty()
4347

4448
anchors.fill: parent
4549
contentWidth: availableWidth
@@ -264,6 +268,43 @@ ScrollView {
264268
value: page.shortNoteThreshold
265269
onValueModified: page.shortNoteThreshold = value
266270
}
271+
272+
CheckBox {
273+
text: qsTr("Show singer background")
274+
TextMatcherItem on text { matcher: page.matcher }
275+
Layout.columnSpan: 3
276+
checked: page.showSingerBackground
277+
onClicked: page.showSingerBackground = checked
278+
}
279+
280+
Label {
281+
text: qsTr("Singer background opacity")
282+
TextMatcherItem on text { matcher: page.matcher }
283+
enabled: page.showSingerBackground
284+
}
285+
Slider {
286+
Layout.fillWidth: true
287+
from: 0
288+
to: 1
289+
value: page.singerBackgroundOpacity
290+
enabled: page.showSingerBackground
291+
onMoved: page.singerBackgroundOpacity = value
292+
ThemedItem.sliderTrackStartType: SVS.TS_Begin
293+
ThemedItem.onDoubleClickReset: page.singerBackgroundOpacity = 0.25
294+
}
295+
SpinBox {
296+
from: 0
297+
to: 100
298+
value: Math.round(page.singerBackgroundOpacity * 100)
299+
enabled: page.showSingerBackground
300+
onValueModified: page.singerBackgroundOpacity = value / 100.0
301+
textFromValue: function(value, locale) {
302+
return value + "%"
303+
}
304+
valueFromText: function(text, locale) {
305+
return parseInt(text.replace("%", ""))
306+
}
307+
}
267308
}
268309
}
269310

@@ -290,4 +331,4 @@ ScrollView {
290331

291332
}
292333
}
293-
}
334+
}

0 commit comments

Comments
 (0)