Skip to content

Commit 7fbb6ae

Browse files
committed
Support play notification sound when export finishes
1 parent aed5220 commit 7fbb6ae

6 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/plugins/audio/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ diffscope_add_builtin_plugin(${PROJECT_NAME}
2929
INCLUDE_PRIVATE
3030
internal/**
3131
)
32+
33+
file(GLOB _res_icons res/soundfx/*)
34+
35+
qt_add_resources(${PROJECT_NAME} soundfx
36+
PREFIX /diffscope/audio/soundfx
37+
BASE res/soundfx
38+
FILES ${_res_icons}
39+
)

src/plugins/audio/internal/AudioPreference.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Audio::Internal {
1313
bool audioExporterClippingCheckEnabled{true};
1414
bool audioExporterEnableAdvancedOptions{false};
1515
bool audioExporterUseTemporaryFile{true};
16+
bool shouldPlayNotificationSoundWhenExportCompleted{true};
1617
};
1718

1819
static AudioPreference *m_instance = nullptr;
@@ -39,11 +40,13 @@ namespace Audio::Internal {
3940
d->audioExporterClippingCheckEnabled = settings->value("audioExporterClippingCheckEnabled", true).toBool();
4041
d->audioExporterEnableAdvancedOptions = settings->value("audioExporterEnableAdvancedOptions", true).toBool();
4142
d->audioExporterUseTemporaryFile = settings->value("audioExporterUseTemporaryFile", true).toBool();
43+
d->shouldPlayNotificationSoundWhenExportCompleted = settings->value("shouldPlayNotificationSoundWhenExportCompleted", true).toBool();
4244
emit playbackBehaviorChanged();
4345
emit playbackTogglingActionChanged();
4446
emit audioExporterClippingCheckEnabledChanged();
4547
emit audioExporterEnableAdvancedOptionsChanged();
4648
emit audioExporterUseTemporaryFileChanged();
49+
emit shouldPlayNotificationSoundWhenExportCompletedChanged();
4750
settings->endGroup();
4851
}
4952

@@ -56,6 +59,7 @@ namespace Audio::Internal {
5659
settings->setValue("audioExporterClippingCheckEnabled", d->audioExporterClippingCheckEnabled);
5760
settings->setValue("audioExporterEnableAdvancedOptions", d->audioExporterEnableAdvancedOptions);
5861
settings->setValue("audioExporterUseTemporaryFile", d->audioExporterUseTemporaryFile);
62+
settings->setValue("shouldPlayNotificationSoundWhenExportCompleted", d->shouldPlayNotificationSoundWhenExportCompleted);
5963
settings->endGroup();
6064
}
6165

@@ -128,4 +132,17 @@ namespace Audio::Internal {
128132
emit m_instance->audioExporterUseTemporaryFileChanged();
129133
}
130134

135+
bool AudioPreference::shouldPlayNotificationSoundWhenExportCompleted() {
136+
M_INSTANCE_D;
137+
return d->shouldPlayNotificationSoundWhenExportCompleted;
138+
}
139+
140+
void AudioPreference::setShouldPlayNotificationSoundWhenExportCompleted(bool shouldPlay) {
141+
M_INSTANCE_D;
142+
if (d->shouldPlayNotificationSoundWhenExportCompleted == shouldPlay)
143+
return;
144+
d->shouldPlayNotificationSoundWhenExportCompleted = shouldPlay;
145+
emit m_instance->shouldPlayNotificationSoundWhenExportCompletedChanged();
146+
}
147+
131148
}

src/plugins/audio/internal/AudioPreference.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Audio::Internal {
2424
Q_PROPERTY(bool audioExporterClippingCheckEnabled READ audioExporterClippingCheckEnabled WRITE setAudioExporterClippingCheckEnabled NOTIFY audioExporterClippingCheckEnabledChanged)
2525
Q_PROPERTY(bool audioExporterEnableAdvancedOptions READ audioExporterEnableAdvancedOptions WRITE setAudioExporterEnableAdvancedOptions NOTIFY audioExporterEnableAdvancedOptionsChanged)
2626
Q_PROPERTY(bool audioExporterUseTemporaryFile READ audioExporterUseTemporaryFile WRITE setAudioExporterUseTemporaryFile NOTIFY audioExporterUseTemporaryFileChanged)
27+
Q_PROPERTY(bool shouldPlayNotificationSoundWhenExportCompleted READ shouldPlayNotificationSoundWhenExportCompleted WRITE setShouldPlayNotificationSoundWhenExportCompleted NOTIFY shouldPlayNotificationSoundWhenExportCompletedChanged)
2728

2829
public:
2930
~AudioPreference() override;
@@ -60,13 +61,16 @@ namespace Audio::Internal {
6061
static void setAudioExporterEnableAdvancedOptions(bool enabled);
6162
static bool audioExporterUseTemporaryFile();
6263
static void setAudioExporterUseTemporaryFile(bool enabled);
64+
static bool shouldPlayNotificationSoundWhenExportCompleted();
65+
static void setShouldPlayNotificationSoundWhenExportCompleted(bool shouldPlay);
6366

6467
Q_SIGNALS:
6568
void playbackBehaviorChanged();
6669
void playbackTogglingActionChanged();
6770
void audioExporterClippingCheckEnabledChanged();
6871
void audioExporterEnableAdvancedOptionsChanged();
6972
void audioExporterUseTemporaryFileChanged();
73+
void shouldPlayNotificationSoundWhenExportCompletedChanged();
7074

7175
private:
7276
friend class AudioPlugin;

src/plugins/audio/internal/addon/ExportAudioAddOn.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <SVSCraftCore/MusicTime.h>
2323
#include <SVSCraftCore/MusicTimeline.h>
2424

25+
#include <TalcsFormat/AbstractAudioFormatIO.h>
26+
#include <TalcsFormat/FormatManager.h>
27+
2528
#include <QAKQuick/quickactioncontext.h>
2629

2730
#include <dspxmodel/Clip.h>
@@ -40,7 +43,10 @@
4043

4144
#include <audio/AudioExporter.h>
4245
#include <audio/AudioExporterConfig.h>
46+
#include <audio/GlobalAudioContext.h>
47+
#include <audio/PreviewSoundPlayer.h>
4348
#include <audio/internal/AudioExporterPresets.h>
49+
#include <audio/internal/AudioPreference.h>
4450
#include <audio/private/AudioExporter_p.h>
4551

4652
namespace Audio::Internal {
@@ -109,6 +115,10 @@ namespace Audio::Internal {
109115
m_exportCompletedMessage->setAllowDoNotShowAgain(true);
110116
m_exportCompletedMessage->setDoNotShowAgainIdentifier("org.diffscope.audio.exportaudioaddon.message");
111117

118+
auto io = GlobalAudioContext::formatManager()->getFormatLoad(":/diffscope/audio/soundfx/export_completed.ogg");
119+
Q_ASSERT(io);
120+
m_completedSound = new PreviewSoundPlayer(io, this);
121+
112122
QQmlComponent component(Core::RuntimeInterface::qmlEngine(), "DiffScope.Audio", "ExportAudioAddOnActions");
113123
if (component.isError()) {
114124
qFatal() << component.errorString();
@@ -372,6 +382,9 @@ namespace Audio::Internal {
372382
const auto sendExportCompletedNotification = [this, windowInterface] {
373383
m_exportCompletedMessage->close();
374384
windowInterface->sendNotification(m_exportCompletedMessage, Core::ProjectWindowInterface::AutoHide);
385+
if (AudioPreference::shouldPlayNotificationSoundWhenExportCompleted()) {
386+
m_completedSound->play();
387+
}
375388
};
376389

377390
QQmlComponent component(Core::RuntimeInterface::qmlEngine(), "DiffScope.Audio", "AudioExportProgressDialog");

src/plugins/audio/internal/addon/ExportAudioAddOn.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Core {
1717

1818
namespace Audio {
1919
class AudioExporter;
20+
class PreviewSoundPlayer;
2021
}
2122

2223
namespace Audio::Internal {
@@ -110,6 +111,7 @@ namespace Audio::Internal {
110111
AudioExporterParameter m_currentParameter;
111112
AudioExporterConfig m_simpleConfig;
112113
Core::NotificationMessage *m_exportCompletedMessage{};
114+
PreviewSoundPlayer *m_completedSound{};
113115
};
114116

115117
}
160 KB
Binary file not shown.

0 commit comments

Comments
 (0)