Skip to content

Commit cae672e

Browse files
committed
Update audio export
1 parent 576ceb6 commit cae672e

12 files changed

Lines changed: 858 additions & 98 deletions

src/plugins/audio/audioexport/AudioExporter.cpp

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include <coreplugin/ProjectTimeline.h>
3232
#include <coreplugin/ProjectWindowInterface.h>
3333

34+
#include <dspxmodel/Clip.h>
35+
#include <dspxmodel/ClipSequence.h>
36+
#include <dspxmodel/ClipTime.h>
3437
#include <dspxmodel/Model.h>
3538
#include <dspxmodel/SelectionModel.h>
3639
#include <dspxmodel/Timeline.h>
@@ -142,15 +145,25 @@ namespace Audio {
142145
const auto model = document->model();
143146
Q_ASSERT(model);
144147

145-
auto timeline = model->timeline();
146-
if (config.timeRange() == AudioExporterConfig::TR_LoopSection && timeline->isLoopEnabled() && timeline->loopLength() > 0) {
147-
return {timeline->loopStart(), timeline->loopLength()};
148+
switch (config.timeRange()) {
149+
case AudioExporterConfig::TR_All:
150+
break;
151+
case AudioExporterConfig::TR_LoopSection: {
152+
auto timeline = model->timeline();
153+
if (timeline->isLoopEnabled() && timeline->loopLength() > 0) {
154+
return {timeline->loopStart(), timeline->loopLength()};
155+
}
156+
break;
157+
}
158+
case AudioExporterConfig::TR_Custom:
159+
return {parameter.rangeStart(), parameter.rangeLength()};
148160
}
149161

150-
auto projectTimeline = windowHandle->projectTimeline();
151-
Q_ASSERT(projectTimeline);
152-
// TODO change `rangeHint` to the real project length (类似ProjectWindowInterface::boundTimelineRangeHint,但是只考虑最远的剪辑)
153-
return {0, projectTimeline->rangeHint()};
162+
return {0, std::ranges::max(std::views::transform(model->tracks()->items(), [](dspx::Track *track) {
163+
return track->clips()->size() == 0 ? 0 : std::ranges::max(std::views::transform(track->clips()->asRange(), [](dspx::Clip *clip) {
164+
return clip->position() + clip->time()->clipLen();
165+
}));
166+
}))};
154167
}
155168

156169
QList<int> AudioExporterPrivate::sourceIndexes(bool *ok) const {
@@ -186,7 +199,7 @@ namespace Audio {
186199
break;
187200
}
188201
case AudioExporterConfig::SO_Custom:
189-
indexes = config.source();
202+
indexes = parameter.source();
190203
for (const auto index : indexes) {
191204
if (index < 0 || index >= trackList.size()) {
192205
if (ok) {
@@ -308,11 +321,12 @@ namespace Audio {
308321

309322
bool sourcesOk = true;
310323
const auto indexes = sourceIndexes(&sourcesOk);
311-
if (!sourcesOk || indexes.isEmpty()) {
324+
const auto isMixed = config.mixingOption() == AudioExporterConfig::MO_Mixed;
325+
if (!sourcesOk || (!isMixed && indexes.isEmpty())) {
312326
preflightWarnings |= AudioExporter::PW_NoFile;
313327
}
314328

315-
if (indexes.isEmpty()) {
329+
if (!sourcesOk || (!isMixed && indexes.isEmpty())) {
316330
if (oldWarnings != preflightWarnings) {
317331
Q_EMIT q->preflightWarningsChanged();
318332
}
@@ -323,7 +337,7 @@ namespace Audio {
323337
}
324338

325339
const auto directory = QDir(projectDirectory()).absoluteFilePath(config.fileDirectory());
326-
if (config.mixingOption() == AudioExporterConfig::MO_Mixed) {
340+
if (isMixed) {
327341
auto fileName = config.fileName();
328342
if (!resolveTemplate(fileName)) {
329343
preflightWarnings |= AudioExporter::PW_UnrecognizedTemplate;
@@ -458,6 +472,21 @@ namespace Audio {
458472
d->refreshPreflight();
459473
}
460474

475+
AudioExporterParameter AudioExporter::parameter() const {
476+
Q_D(const AudioExporter);
477+
return d->parameter;
478+
}
479+
480+
void AudioExporter::setParameter(const AudioExporterParameter &parameter) {
481+
Q_D(AudioExporter);
482+
if (d->parameter == parameter) {
483+
return;
484+
}
485+
d->parameter = parameter;
486+
Q_EMIT parameterChanged();
487+
d->refreshPreflight();
488+
}
489+
461490
AudioExporter::PreflightWarnings AudioExporter::preflightWarnings() const {
462491
Q_D(const AudioExporter);
463492
return d->preflightWarnings;
@@ -534,7 +563,8 @@ namespace Audio {
534563

535564
bool sourcesOk = true;
536565
const auto sourceIndexes = d->sourceIndexes(&sourcesOk);
537-
if (!sourcesOk || sourceIndexes.isEmpty() || d->fileList.isEmpty()) {
566+
if (!sourcesOk || d->fileList.isEmpty() ||
567+
(d->config.mixingOption() != AudioExporterConfig::MO_Mixed && sourceIndexes.isEmpty())) {
538568
d->setError(InvalidSource, tr("No file will be exported. Please check if any source is selected."));
539569
return R_Fail;
540570
}
@@ -705,6 +735,10 @@ namespace Audio {
705735
Q_EMIT runtimeWarningAdded(message, sourceIndex);
706736
}
707737

738+
AudioExporterPrivate *AudioExporterPrivate::of(AudioExporter *q) {
739+
return q->d_func();
740+
}
741+
708742
}
709743

710744
#include "moc_AudioExporter.cpp"

src/plugins/audio/audioexport/AudioExporter.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace Audio {
3232
Q_DECLARE_PRIVATE(AudioExporter)
3333
Q_PROPERTY(Core::ProjectWindowInterface *windowHandle READ windowHandle CONSTANT)
3434
Q_PROPERTY(Audio::AudioExporterConfig config READ config WRITE setConfig NOTIFY configChanged)
35+
Q_PROPERTY(Audio::AudioExporterParameter parameter READ parameter WRITE setParameter NOTIFY parameterChanged)
3536
Q_PROPERTY(PreflightWarnings preflightWarnings READ preflightWarnings NOTIFY preflightWarningsChanged)
3637
Q_PROPERTY(QStringList fileList READ fileList NOTIFY fileListChanged)
3738
Q_PROPERTY(Error error READ error NOTIFY errorChanged)
@@ -49,6 +50,9 @@ namespace Audio {
4950
AudioExporterConfig config() const;
5051
void setConfig(const AudioExporterConfig &config);
5152

53+
AudioExporterParameter parameter() const;
54+
void setParameter(const AudioExporterParameter &parameter);
55+
5256
enum PreflightWarningFlag {
5357
PW_NoFile = 0x0001,
5458
PW_DuplicatedFile = 0x0002,
@@ -61,7 +65,7 @@ namespace Audio {
6165
Q_FLAG(PreflightWarnings)
6266

6367
PreflightWarnings preflightWarnings() const;
64-
static QStringList preflightWarningTexts(PreflightWarnings warnings);
68+
Q_INVOKABLE static QStringList preflightWarningTexts(PreflightWarnings warnings);
6569

6670
QStringList fileList() const;
6771
QStringList dryRun() const;
@@ -99,6 +103,7 @@ namespace Audio {
99103

100104
Q_SIGNALS:
101105
void configChanged();
106+
void parameterChanged();
102107
void preflightWarningsChanged();
103108
void fileListChanged();
104109
void errorChanged();

src/plugins/audio/audioexport/AudioExporterConfig.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
#include "AudioExporterConfig.h"
22
#include "AudioExporterConfig_p.h"
33

4-
#include <QJsonArray>
54
#include <QJsonValue>
65

76
namespace Audio {
87

8+
QList<int> AudioExporterParameter::source() const {
9+
return m_source;
10+
}
11+
12+
void AudioExporterParameter::setSource(const QList<int> &source) {
13+
m_source = source;
14+
}
15+
16+
int AudioExporterParameter::rangeStart() const {
17+
return m_rangeStart;
18+
}
19+
20+
void AudioExporterParameter::setRangeStart(int rangeStart) {
21+
m_rangeStart = rangeStart;
22+
}
23+
24+
int AudioExporterParameter::rangeLength() const {
25+
return m_rangeLength;
26+
}
27+
28+
void AudioExporterParameter::setRangeLength(int rangeLength) {
29+
m_rangeLength = rangeLength;
30+
}
31+
32+
bool AudioExporterParameter::operator==(const AudioExporterParameter &other) const {
33+
return m_source == other.m_source && m_rangeStart == other.m_rangeStart &&
34+
m_rangeLength == other.m_rangeLength;
35+
}
36+
937
AudioExporterConfig::AudioExporterConfig() : d(new AudioExporterConfigData) {
1038
}
1139

@@ -133,14 +161,6 @@ namespace Audio {
133161
d->sourceOption = sourceOption;
134162
}
135163

136-
QList<int> AudioExporterConfig::source() const {
137-
return d->source;
138-
}
139-
140-
void AudioExporterConfig::setSource(const QList<int> &source) {
141-
d->source = source;
142-
}
143-
144164
AudioExporterConfig::TimeRange AudioExporterConfig::timeRange() const {
145165
return d->timeRange;
146166
}
@@ -150,11 +170,6 @@ namespace Audio {
150170
}
151171

152172
QJsonObject AudioExporterConfig::toJsonObject() const {
153-
QJsonArray sourceArray;
154-
for (const auto sourceIndex : d->source) {
155-
sourceArray.append(sourceIndex);
156-
}
157-
158173
return {
159174
{"fileName", d->fileName },
160175
{"fileDirectory", d->fileDirectory },
@@ -166,7 +181,6 @@ namespace Audio {
166181
{"mixingOption", static_cast<int>(d->mixingOption) },
167182
{"isMuteSoloEnabled", d->isMuteSoloEnabled },
168183
{"sourceOption", static_cast<int>(d->sourceOption) },
169-
{"source", sourceArray },
170184
{"timeRange", static_cast<int>(d->timeRange) },
171185
};
172186
}
@@ -219,30 +233,13 @@ namespace Audio {
219233
assignInt(QStringLiteral("sourceOption"), sourceOption);
220234
config.d->sourceOption = static_cast<SourceOption>(sourceOption);
221235

222-
value = object.value(QStringLiteral("source"));
223-
if (value.isArray()) {
224-
QList<int> source;
225-
bool ok = true;
226-
for (const auto item : value.toArray()) {
227-
if (!item.isDouble()) {
228-
ok = false;
229-
break;
230-
}
231-
source.append(item.toInt());
232-
}
233-
if (ok) {
234-
config.d->source = source;
235-
}
236-
}
237-
238236
int timeRange = config.d->timeRange;
239237
assignInt(QStringLiteral("timeRange"), timeRange);
240238
config.d->timeRange = static_cast<TimeRange>(timeRange);
241239
return config;
242240
}
243241

244242
bool AudioExporterConfig::operator==(const AudioExporterConfig &other) const {
245-
// `source` is not compared
246243
return d->fileName == other.d->fileName && d->fileDirectory == other.d->fileDirectory &&
247244
d->fileType == other.d->fileType && d->formatMono == other.d->formatMono &&
248245
d->formatOption == other.d->formatOption && d->formatQuality == other.d->formatQuality &&

src/plugins/audio/audioexport/AudioExporterConfig.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ namespace Audio {
1414

1515
class AudioExporterConfigData;
1616

17+
class AUDIO_EXPORT AudioExporterParameter {
18+
Q_GADGET
19+
Q_PROPERTY(QList<int> source READ source WRITE setSource)
20+
Q_PROPERTY(int rangeStart READ rangeStart WRITE setRangeStart)
21+
Q_PROPERTY(int rangeLength READ rangeLength WRITE setRangeLength)
22+
public:
23+
QList<int> source() const;
24+
void setSource(const QList<int> &source);
25+
26+
int rangeStart() const;
27+
void setRangeStart(int rangeStart);
28+
29+
int rangeLength() const;
30+
void setRangeLength(int rangeLength);
31+
32+
bool operator==(const AudioExporterParameter &other) const;
33+
34+
private:
35+
QList<int> m_source;
36+
int m_rangeStart{};
37+
int m_rangeLength{};
38+
};
39+
1740
class AUDIO_EXPORT AudioExporterConfig {
1841
Q_GADGET
1942
Q_PROPERTY(QString fileName READ fileName WRITE setFileName)
@@ -26,7 +49,6 @@ namespace Audio {
2649
Q_PROPERTY(MixingOption mixingOption READ mixingOption WRITE setMixingOption)
2750
Q_PROPERTY(bool muteSoloEnabled READ isMuteSoloEnabled WRITE setMuteSoloEnabled)
2851
Q_PROPERTY(SourceOption sourceOption READ sourceOption WRITE setSourceOption)
29-
Q_PROPERTY(QList<int> source READ source WRITE setSource)
3052
Q_PROPERTY(TimeRange timeRange READ timeRange WRITE setTimeRange)
3153
Q_DECLARE_TR_FUNCTIONS(Audio::AudioExporterConfig)
3254
public:
@@ -89,12 +111,10 @@ namespace Audio {
89111
SourceOption sourceOption() const;
90112
void setSourceOption(SourceOption sourceOption);
91113

92-
QList<int> source() const;
93-
void setSource(const QList<int> &source);
94-
95114
enum TimeRange {
96115
TR_All,
97116
TR_LoopSection,
117+
TR_Custom,
98118
};
99119
Q_ENUM(TimeRange)
100120
TimeRange timeRange() const;

src/plugins/audio/audioexport/AudioExporterConfig_p.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace Audio {
1919
AudioExporterConfig::MixingOption mixingOption{};
2020
bool isMuteSoloEnabled{};
2121
AudioExporterConfig::SourceOption sourceOption{};
22-
QList<int> source;
2322
AudioExporterConfig::TimeRange timeRange{};
2423
};
2524

src/plugins/audio/audioexport/AudioExporter_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Audio {
2424
AudioExporter *q_ptr{};
2525
Core::ProjectWindowInterface *windowHandle{};
2626
AudioExporterConfig config;
27+
AudioExporterParameter parameter;
2728
bool configInitialized{};
2829
AudioExporter::PreflightWarnings preflightWarnings{};
2930
QStringList fileList;
@@ -50,6 +51,8 @@ namespace Audio {
5051
void setError(AudioExporter::Error error, const QString &message = {});
5152
void clearError();
5253
void setRunning(bool running);
54+
55+
static AudioExporterPrivate *of(AudioExporter *q);
5356
};
5457

5558
}

src/plugins/audio/internal/AudioExporterPresets.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ namespace Audio::Internal {
316316
config.setMixingOption(mixingOption);
317317
config.setMuteSoloEnabled(true);
318318
config.setSourceOption(AudioExporterConfig::SO_All);
319-
config.setSource({});
320319
config.setTimeRange(AudioExporterConfig::TR_All);
321320
return config;
322321
};

0 commit comments

Comments
 (0)