Skip to content

Commit c564324

Browse files
committed
Add simple mode audio export dialog
1 parent 1f6952e commit c564324

6 files changed

Lines changed: 520 additions & 302 deletions

File tree

src/plugins/audio/audioexport/AudioExporter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef DIFFSCOPE_AUDIO_AUDIOEXPORTER_H
22
#define DIFFSCOPE_AUDIO_AUDIOEXPORTER_H
33

4+
#include <qqmlintegration.h>
5+
46
#include <QObject>
57
#include <QStringList>
68

@@ -29,6 +31,8 @@ namespace Audio {
2931

3032
class AUDIO_EXPORT AudioExporter : public QObject {
3133
Q_OBJECT
34+
QML_ELEMENT
35+
QML_UNCREATABLE("")
3236
Q_DECLARE_PRIVATE(AudioExporter)
3337
Q_PROPERTY(Core::ProjectWindowInterface *windowHandle READ windowHandle CONSTANT)
3438
Q_PROPERTY(Audio::AudioExporterConfig config READ config WRITE setConfig NOTIFY configChanged)

src/plugins/audio/internal/AudioPreference.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Audio::Internal {
1111
AudioPreference::PlayheadBehavior playbackBehavior{};
1212
AudioPreference::PlaybackTogglingAction playbackTogglingAction{AudioPreference::PTA_PlayStop};
1313
bool audioExporterClippingCheckEnabled{true};
14+
bool audioExporterEnableAdvancedOptions{false};
1415
bool audioExporterUseTemporaryFile{true};
1516
};
1617

@@ -36,10 +37,12 @@ namespace Audio::Internal {
3637
d->playbackBehavior = settings->value("playbackBehavior", QVariant::fromValue(PB_ReturnToStart)).value<PlayheadBehavior>();
3738
d->playbackTogglingAction = settings->value("playbackTogglingAction", QVariant::fromValue(PTA_PlayStop)).value<PlaybackTogglingAction>();
3839
d->audioExporterClippingCheckEnabled = settings->value("audioExporterClippingCheckEnabled", true).toBool();
40+
d->audioExporterEnableAdvancedOptions = settings->value("audioExporterEnableAdvancedOptions", true).toBool();
3941
d->audioExporterUseTemporaryFile = settings->value("audioExporterUseTemporaryFile", true).toBool();
4042
emit playbackBehaviorChanged();
4143
emit playbackTogglingActionChanged();
4244
emit audioExporterClippingCheckEnabledChanged();
45+
emit audioExporterEnableAdvancedOptionsChanged();
4346
emit audioExporterUseTemporaryFileChanged();
4447
settings->endGroup();
4548
}
@@ -51,6 +54,7 @@ namespace Audio::Internal {
5154
settings->setValue("playbackBehavior", d->playbackBehavior);
5255
settings->setValue("playbackTogglingAction", d->playbackTogglingAction);
5356
settings->setValue("audioExporterClippingCheckEnabled", d->audioExporterClippingCheckEnabled);
57+
settings->setValue("audioExporterEnableAdvancedOptions", d->audioExporterEnableAdvancedOptions);
5458
settings->setValue("audioExporterUseTemporaryFile", d->audioExporterUseTemporaryFile);
5559
settings->endGroup();
5660
}
@@ -98,6 +102,19 @@ namespace Audio::Internal {
98102
emit m_instance->audioExporterClippingCheckEnabledChanged();
99103
}
100104

105+
bool AudioPreference::audioExporterEnableAdvancedOptions() {
106+
M_INSTANCE_D;
107+
return d->audioExporterEnableAdvancedOptions;
108+
}
109+
110+
void AudioPreference::setAudioExporterEnableAdvancedOptions(bool enabled) {
111+
M_INSTANCE_D;
112+
if (d->audioExporterEnableAdvancedOptions == enabled)
113+
return;
114+
d->audioExporterEnableAdvancedOptions = enabled;
115+
emit m_instance->audioExporterEnableAdvancedOptionsChanged();
116+
}
117+
101118
bool AudioPreference::audioExporterUseTemporaryFile() {
102119
M_INSTANCE_D;
103120
return d->audioExporterUseTemporaryFile;

src/plugins/audio/internal/AudioPreference.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Audio::Internal {
2222
Q_PROPERTY(AudioPreference::PlayheadBehavior playbackBehavior READ playbackBehavior WRITE setPlaybackBehavior NOTIFY playbackBehaviorChanged)
2323
Q_PROPERTY(AudioPreference::PlaybackTogglingAction playbackTogglingAction READ playbackTogglingAction WRITE setPlaybackTogglingAction NOTIFY playbackTogglingActionChanged)
2424
Q_PROPERTY(bool audioExporterClippingCheckEnabled READ audioExporterClippingCheckEnabled WRITE setAudioExporterClippingCheckEnabled NOTIFY audioExporterClippingCheckEnabledChanged)
25+
Q_PROPERTY(bool audioExporterEnableAdvancedOptions READ audioExporterEnableAdvancedOptions WRITE setAudioExporterEnableAdvancedOptions NOTIFY audioExporterEnableAdvancedOptionsChanged)
2526
Q_PROPERTY(bool audioExporterUseTemporaryFile READ audioExporterUseTemporaryFile WRITE setAudioExporterUseTemporaryFile NOTIFY audioExporterUseTemporaryFileChanged)
2627

2728
public:
@@ -55,13 +56,16 @@ namespace Audio::Internal {
5556
static void setPlaybackTogglingAction(PlaybackTogglingAction playbackTogglingAction);
5657
static bool audioExporterClippingCheckEnabled();
5758
static void setAudioExporterClippingCheckEnabled(bool enabled);
59+
static bool audioExporterEnableAdvancedOptions();
60+
static void setAudioExporterEnableAdvancedOptions(bool enabled);
5861
static bool audioExporterUseTemporaryFile();
5962
static void setAudioExporterUseTemporaryFile(bool enabled);
6063

6164
Q_SIGNALS:
6265
void playbackBehaviorChanged();
6366
void playbackTogglingActionChanged();
6467
void audioExporterClippingCheckEnabledChanged();
68+
void audioExporterEnableAdvancedOptionsChanged();
6569
void audioExporterUseTemporaryFileChanged();
6670

6771
private:

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

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ namespace Audio::Internal {
9494
}
9595

9696
ExportAudioAddOn::ExportAudioAddOn(QObject *parent) : WindowInterfaceAddOn(parent) {
97+
m_simpleConfig.setFormatQuality(100);
98+
m_simpleConfig.setFormatSampleRate(48000);
9799
}
98100

99101
ExportAudioAddOn::~ExportAudioAddOn() = default;
@@ -141,6 +143,17 @@ namespace Audio::Internal {
141143
emit currentParameterChanged();
142144
}
143145

146+
AudioExporterConfig ExportAudioAddOn::simpleConfig() const {
147+
return m_simpleConfig;
148+
}
149+
150+
void ExportAudioAddOn::setSimpleConfig(const AudioExporterConfig &config) {
151+
if (m_simpleConfig == config)
152+
return;
153+
m_simpleConfig = config;
154+
emit simpleConfigChanged();
155+
}
156+
144157
void ExportAudioAddOn::exportAudio() {
145158
auto windowInterface = windowHandle()->cast<Core::ProjectWindowInterface>();
146159
if (!windowInterface || !windowInterface->window())
@@ -163,15 +176,16 @@ namespace Audio::Internal {
163176
m_currentParameter.setRangeStart(0);
164177
m_currentParameter.setRangeLength(timeRangeAllEnd);
165178

166-
connect(AudioExporterPresets::instance(), &AudioExporterPresets::currentConfigChanged, &exporter, [&exporter] {
167-
exporter.setConfig(AudioExporterPresets::instance()->currentConfig());
168-
});
169179
connect(this, &ExportAudioAddOn::currentParameterChanged, &exporter, [this, &exporter] {
170180
exporter.setParameter(currentParameter());
171181
});
172-
exporter.setConfig(AudioExporterPresets::instance()->currentConfig());
173182
exporter.setParameter(currentParameter());
174183

184+
if (m_simpleConfig.fileName().isEmpty() || m_simpleConfig.fileDirectory().isEmpty()) {
185+
m_simpleConfig.setFileDirectory(AudioExporterPrivate::of(&exporter)->projectDirectory());
186+
m_simpleConfig.setFileName(AudioExporterPrivate::of(&exporter)->projectName() + ".wav");
187+
}
188+
175189
QQmlComponent component(Core::RuntimeInterface::qmlEngine(), "DiffScope.Audio", "AudioExportDialog");
176190
if (component.isError()) {
177191
qFatal() << component.errorString();
@@ -230,6 +244,34 @@ namespace Audio::Internal {
230244
presets->setCurrentConfig(config);
231245
}
232246

247+
void ExportAudioAddOn::browseFileSimple() {
248+
auto windowInterface = windowHandle()->cast<Core::ProjectWindowInterface>();
249+
auto config = m_simpleConfig;
250+
const QStringList filters = {
251+
tr("WAV (*.wav)"),
252+
tr("Ogg Vorbis (*.ogg)"),
253+
};
254+
QString selectedFilter = filters.at(config.fileType() == AudioExporterConfig::FT_Wav ? 0 : 1);
255+
const auto path = QFileDialog::getSaveFileName(
256+
nullptr,
257+
{},
258+
calculateSimplePath(config),
259+
filters.join(QStringLiteral(";;")),
260+
&selectedFilter
261+
);
262+
if (path.isEmpty()) {
263+
return;
264+
}
265+
const QFileInfo fileInfo(path);
266+
const auto templateSuffix = config.mixingOption() == AudioExporterConfig::MO_Mixed
267+
? QStringLiteral(".")
268+
: QStringLiteral("_${trackIndex}_${trackName}.");
269+
config.setFileName(fileInfo.completeBaseName() + templateSuffix + fileInfo.suffix());
270+
config.setFileDirectory(fileInfo.dir().canonicalPath());
271+
applyFileType(config, filters.indexOf(selectedFilter) == 0 ? AudioExporterConfig::FT_Wav : AudioExporterConfig::FT_OggVorbis);
272+
setSimpleConfig(config);
273+
}
274+
233275
void ExportAudioAddOn::setMixingOption(int index) {
234276
auto presets = AudioExporterPresets::instance();
235277
auto config = presets->currentConfig();
@@ -260,6 +302,34 @@ namespace Audio::Internal {
260302
presets->setCurrentConfig(config);
261303
}
262304

305+
void ExportAudioAddOn::setMixingOptionSimple(int index) {
306+
auto config = m_simpleConfig;
307+
config.setMixingOption(static_cast<AudioExporterConfig::MixingOption>(index));
308+
309+
const QFileInfo fileInfo(config.fileName());
310+
auto basename = fileInfo.completeBaseName();
311+
auto suffix = fileInfo.suffix();
312+
if (index == AudioExporterConfig::MO_Mixed) {
313+
if (basename.endsWith(QStringLiteral("_${trackIndex}_${trackName}"))) {
314+
basename = basename.chopped(27);
315+
}
316+
} else if (!basename.contains(QStringLiteral("${trackIndex}")) &&
317+
!basename.contains(QStringLiteral("${trackName}"))) {
318+
basename += QStringLiteral("_${trackIndex}_${trackName}");
319+
}
320+
if (suffix.isEmpty()) {
321+
suffix = AudioExporterConfig::extensionOfType(config.fileType());
322+
}
323+
config.setFileName(basename + QStringLiteral(".") + suffix);
324+
setSimpleConfig(config);
325+
}
326+
327+
void ExportAudioAddOn::setFileTypeSimple(int index) {
328+
auto config = m_simpleConfig;
329+
applyFileType(config, index);
330+
setSimpleConfig(config);
331+
}
332+
263333
double ExportAudioAddOn::calculateDurationInMsec(AudioExporter *exporter) const {
264334
auto windowInterface = windowHandle()->cast<Core::ProjectWindowInterface>();
265335

@@ -269,6 +339,19 @@ namespace Audio::Internal {
269339
return musicTimeline->create(0, 0, range.second).millisecond() - musicTimeline->create(0, 0, range.first).millisecond();
270340
}
271341

342+
QString ExportAudioAddOn::calculateSimplePath(const AudioExporterConfig &config) {
343+
auto fileName = config.fileName();
344+
if (config.mixingOption() == AudioExporterConfig::MO_Mixed) {
345+
return QDir::toNativeSeparators(QDir(config.fileDirectory()).absoluteFilePath(fileName));
346+
} else {
347+
QFileInfo info(fileName);
348+
auto baseName = info.completeBaseName();
349+
Q_ASSERT(baseName.endsWith(QStringLiteral("_${trackIndex}_${trackName}")));
350+
baseName = baseName.chopped(27);
351+
return QDir::toNativeSeparators(QDir(config.fileDirectory()).absoluteFilePath(baseName + QStringLiteral(".") + info.suffix()));
352+
}
353+
}
354+
272355
void ExportAudioAddOn::appendFileNameTemplate(const QString &templateString) {
273356
auto config = AudioExporterPresets::instance()->currentConfig();
274357
QFileInfo info(config.fileName());

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace Audio::Internal {
6969
QML_ELEMENT
7070
QML_UNCREATABLE("")
7171
Q_PROPERTY(Audio::AudioExporterParameter currentParameter READ currentParameter WRITE setCurrentParameter NOTIFY currentParameterChanged)
72+
Q_PROPERTY(Audio::AudioExporterConfig simpleConfig READ simpleConfig WRITE setSimpleConfig NOTIFY simpleConfigChanged)
7273
public:
7374
explicit ExportAudioAddOn(QObject *parent = nullptr);
7475
~ExportAudioAddOn() override;
@@ -82,22 +83,32 @@ namespace Audio::Internal {
8283
AudioExporterParameter currentParameter() const;
8384
void setCurrentParameter(const AudioExporterParameter &parameter);
8485

86+
AudioExporterConfig simpleConfig() const;
87+
void setSimpleConfig(const AudioExporterConfig &config);
88+
8589
Q_INVOKABLE void exportAudio();
8690
Q_INVOKABLE void browseFile();
91+
Q_INVOKABLE void browseFileSimple();
8792
Q_INVOKABLE bool runExport(AudioExporter *exporter);
8893

8994
Q_INVOKABLE static QStringList formatOptions(int fileType) ;
9095
Q_INVOKABLE static void setMixingOption(int index);
9196
Q_INVOKABLE static void setFileType(int index);
97+
Q_INVOKABLE void setMixingOptionSimple(int index);
98+
Q_INVOKABLE void setFileTypeSimple(int index);
9299
Q_INVOKABLE static void appendFileNameTemplate(const QString &templateString);
93100

94101
Q_INVOKABLE double calculateDurationInMsec(AudioExporter *exporter) const;
95102

103+
Q_INVOKABLE static QString calculateSimplePath(const AudioExporterConfig &config);
104+
96105
Q_SIGNALS:
97106
void currentParameterChanged();
107+
void simpleConfigChanged();
98108

99109
private:
100110
AudioExporterParameter m_currentParameter;
111+
AudioExporterConfig m_simpleConfig;
101112
Core::NotificationMessage *m_exportCompletedMessage{};
102113
};
103114

0 commit comments

Comments
 (0)