Skip to content

Commit ac52364

Browse files
committed
Update audio-export-related functionalities
1 parent f13e243 commit ac52364

7 files changed

Lines changed: 42 additions & 12 deletions

File tree

src/plugins/audio/audioexport/AudioExporter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ namespace Audio {
149149

150150
auto projectTimeline = windowHandle->projectTimeline();
151151
Q_ASSERT(projectTimeline);
152+
// TODO change `rangeHint` to the real project length (类似ProjectWindowInterface::boundTimelineRangeHint,但是只考虑最远的剪辑)
152153
return {0, projectTimeline->rangeHint()};
153154
}
154155

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
#include <QAKQuick/quickactioncontext.h>
1818

19-
#include <audio/AudioExporterConfig.h>
20-
#include <audio/internal/AudioExporterPresets.h>
2119
#include <coreplugin/ProjectDocumentContext.h>
2220
#include <coreplugin/ProjectWindowInterface.h>
2321

22+
#include <audio/AudioExporter.h>
23+
#include <audio/AudioExporterConfig.h>
24+
#include <audio/internal/AudioExporterPresets.h>
25+
2426
namespace Audio::Internal {
2527
namespace {
2628
QString documentsDirectory() {
@@ -38,6 +40,14 @@ namespace Audio::Internal {
3840
}
3941
return documentsDirectory();
4042
}
43+
44+
void applyFileType(AudioExporterConfig &config, int index) {
45+
const QFileInfo fileInfo(config.fileName());
46+
config.setFileType(static_cast<AudioExporterConfig::FileType>(index));
47+
config.setFormatOption(0);
48+
config.setFileName(fileInfo.completeBaseName() + QStringLiteral(".") +
49+
AudioExporterConfig::extensionOfType(static_cast<AudioExporterConfig::FileType>(index)));
50+
}
4151
}
4252

4353
ExportAudioAddOn::ExportAudioAddOn(QObject *parent) : WindowInterfaceAddOn(parent) {
@@ -76,12 +86,20 @@ namespace Audio::Internal {
7686
if (!windowInterface || !windowInterface->window())
7787
return;
7888

89+
AudioExporter exporter(windowInterface, this);
90+
91+
connect(AudioExporterPresets::instance(), &AudioExporterPresets::currentConfigChanged, &exporter, [&exporter] {
92+
exporter.setConfig(AudioExporterPresets::instance()->currentConfig());
93+
});
94+
exporter.setConfig(AudioExporterPresets::instance()->currentConfig());
95+
7996
QQmlComponent component(Core::RuntimeInterface::qmlEngine(), "DiffScope.Audio", "AudioExportDialog");
8097
if (component.isError()) {
8198
qFatal() << component.errorString();
8299
}
83100
std::unique_ptr<QWindow> dialog(qobject_cast<QWindow *>(component.createWithInitialProperties({
84-
{"addOn", QVariant::fromValue(this)}
101+
{"addOn", QVariant::fromValue(this)},
102+
{"exporter", QVariant::fromValue(&exporter)},
85103
})));
86104
if (!dialog) {
87105
qFatal() << component.errorString();
@@ -112,7 +130,7 @@ namespace Audio::Internal {
112130
const auto path = QFileDialog::getSaveFileName(
113131
nullptr,
114132
{},
115-
QDir(projectDirectory(windowInterface)).absoluteFilePath(config.fileName()),
133+
QDir(projectDirectory(windowInterface)).absoluteFilePath(config.fileDirectory()),
116134
filters.join(QStringLiteral(";;")),
117135
&selectedFilter
118136
);
@@ -126,7 +144,7 @@ namespace Audio::Internal {
126144
: QStringLiteral("_${trackIndex}_${trackName}.");
127145
config.setFileName(fileInfo.completeBaseName() + templateSuffix + fileInfo.suffix());
128146
config.setFileDirectory(fileInfo.dir().canonicalPath());
129-
config.setFileType(static_cast<AudioExporterConfig::FileType>(filters.indexOf(selectedFilter)));
147+
applyFileType(config, filters.indexOf(selectedFilter));
130148
presets->setCurrentConfig(config);
131149
}
132150

@@ -153,6 +171,13 @@ namespace Audio::Internal {
153171
presets->setCurrentConfig(config);
154172
}
155173

174+
void ExportAudioAddOn::setFileType(int index) {
175+
auto presets = AudioExporterPresets::instance();
176+
auto config = presets->currentConfig();
177+
applyFileType(config, index);
178+
presets->setCurrentConfig(config);
179+
}
180+
156181
}
157182

158183
#include "moc_ExportAudioAddOn.cpp"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace Audio::Internal {
2929
Q_INVOKABLE QStringList formatOptions(int fileType) const;
3030
Q_INVOKABLE void browseFile();
3131
Q_INVOKABLE void setMixingOption(int index);
32+
Q_INVOKABLE void setFileType(int index);
3233
};
3334

3435
}

src/plugins/audio/internal/utils/AudioQmlHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Audio::Internal {
3131
return AudioClipAudioContext::of(audioClip);
3232
}
3333

34-
QString AudioQmlHelper::getDisplayRealPath(const QString &path) {
34+
QString AudioQmlHelper::getNativeSeparatorPath(const QString &path) {
3535
return QDir::toNativeSeparators(path);
3636
}
3737

src/plugins/audio/internal/utils/AudioQmlHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Audio::Internal {
3434

3535
Q_INVOKABLE static QString getDisplayAudioFilePath(const dspx::AudioPathInfo &pathInfo);
3636
Q_INVOKABLE static AudioClipAudioContext *getAudioClipAudioContext(QObject *object);
37-
Q_INVOKABLE static QString getDisplayRealPath(const QString &path);
37+
Q_INVOKABLE static QString getNativeSeparatorPath(const QString &path);
3838
Q_INVOKABLE static AudioClipAddOn *getAudioClipAddOn(Core::ProjectWindowInterface *win);
3939
};
4040

src/plugins/audio/qml/dialogs/AudioExportDialog.qml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Window {
1010
id: dialog
1111

1212
required property ExportAudioAddOn addOn
13+
required property QtObject exporter
1314
readonly property QtObject trackList: addOn.windowHandle.projectDocumentContext.document.model.tracks
1415
readonly property var tracks: trackList.items
1516
readonly property QtObject trackSelectionModel: addOn.windowHandle.projectDocumentContext.document.selectionModel.trackSelectionModel
@@ -235,6 +236,7 @@ Window {
235236
Label {
236237
Layout.fillWidth: true
237238
wrapMode: Text.Wrap
239+
text: AudioQmlHelper.getNativeSeparatorPath(dialog.exporter.fileList[0] ?? "")
238240
}
239241
}
240242
}
@@ -258,15 +260,14 @@ Window {
258260
qsTr("MP3"),
259261
]
260262
currentIndex: AudioExporterPresets.currentConfig.fileType
261-
onActivated: (index) => {
262-
AudioExporterPresets.currentConfig.fileType = index
263-
AudioExporterPresets.currentConfig.formatOption = 0
264-
}
263+
onActivated: (index) => dialog.addOn.setFileType(index)
265264
}
266265
Layout.fillWidth: true
267266
}
268267
FormGroup {
268+
id: optionFormGroup
269269
label: qsTr("Option")
270+
enabled: dialog.addOn.formatOptions(AudioExporterPresets.currentConfig.fileType).length > 0
270271
columnItem: ComboBox {
271272
model: dialog.addOn.formatOptions(AudioExporterPresets.currentConfig.fileType)
272273
currentIndex: AudioExporterPresets.currentConfig.formatOption
@@ -311,7 +312,9 @@ Window {
311312
Layout.fillWidth: true
312313
}
313314
FormGroup {
315+
id: qualityFormGroup
314316
label: qsTr("Quality")
317+
enabled: AudioExporterPresets.currentConfig.fileType !== 0 && AudioExporterPresets.currentConfig.fileType !== 1
315318
columnItem: RowLayout {
316319
Slider {
317320
Layout.fillWidth: true

src/plugins/audio/qml/propertyeditors/AudioPropertyEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ PropertyEditorGroupBox {
7979
FormGroup {
8080
id: actualPathFormGroup
8181
visible: groupBox.audioClipAudioContext?.status === AudioClipAudioContext.FileMoved
82-
readonly property string path: AudioQmlHelper.getDisplayRealPath(groupBox.audioClipAudioContext?.realAudioPath ?? "")
82+
readonly property string path: AudioQmlHelper.getNativeSeparatorPath(groupBox.audioClipAudioContext?.realAudioPath ?? "")
8383
Layout.fillWidth: true
8484
label: qsTr("Actual path")
8585
rowItem: ToolButton {

0 commit comments

Comments
 (0)