Audacity 3.2.0
Export.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Export.cpp
6
7 Dominic Mazzoni
8
9*******************************************************************//*****************************************************************/
15
16#include "Export.h"
17
18#include <numeric>
19
20#include "BasicUI.h"
22#include "Mix.h"
23#include "Project.h"
24#include "WaveTrack.h"
25#include "wxFileNameWrapper.h"
26#include "StretchingSequence.h"
27
28#include "ExportUtils.h"
29
32
34{
35 mFileName = filename;
36 return *this;
37}
38
39ExportTaskBuilder& ExportTaskBuilder::SetRange(double t0, double t1, bool selectedOnly) noexcept
40{
41 mT0 = t0;
42 mT1 = t1;
43 mSelectedOnly = selectedOnly;
44 return *this;
45}
46
48{
49 mParameters = std::move(parameters);
50 return *this;
51}
52
53ExportTaskBuilder& ExportTaskBuilder::SetNumChannels(unsigned int numChannels) noexcept
54{
55 mNumChannels = numChannels;
56 return *this;
57}
58
60{
61 mPlugin = plugin;
62 mFormat = format;
63 return *this;
64}
65
67{
68 mMixerSpec = mixerSpec;
69 return *this;
70}
71
73{
74 mSampleRate = sampleRate;
75 return *this;
76}
77
79{
80 mTags = tags;
81 return *this;
82}
83
85{
86 //File rename stuff should be moved out to somewhere else...
87 auto filename = mFileName;
88
89 //For safety, if the file already exists we use temporary filename
90 //and replace original one export succeeded
91 int suffix = 0;
92 while (filename.FileExists()) {
93 filename.SetName(mFileName.GetName() +
94 wxString::Format(wxT("%d"), suffix));
95 suffix++;
96 }
97
98 auto processor = mPlugin->CreateProcessor(mFormat);
99 if(!processor->Initialize(project,
101 mFileName.GetFullPath(),
105 mTags))
106 {
108 }
109
110 return ExportTask([actualFilename = filename,
111 targetFilename = mFileName,
112 processor = std::shared_ptr<ExportProcessor>(processor.release())]
113 (ExportProcessorDelegate& delegate)
114 {
115 auto result = ExportResult::Error;
116 auto cleanup = finally( [&] {
117 if(result == ExportResult::Success || result == ExportResult::Stopped)
118 {
119 if (actualFilename != targetFilename)
120 {
121 //may fail...
122 ::wxRenameFile(actualFilename.GetFullPath(),
123 targetFilename.GetFullPath(),
124 true);
125 }
126 }
127 else
128 ::wxRemoveFile(actualFilename.GetFullPath());
129 } );
130 result = processor->Process(delegate);
131 return result;
132 });
133}
134
136{
138 XO("Warning"),
140 "Error:_Disk_full_or_not_writable"
141 );
142}
143
145 const TranslatableString& caption,
146 bool allowReporting)
147{
148 ShowExportErrorDialog(message, caption, {}, allowReporting);
149}
150
152 const TranslatableString& caption,
153 const ManualPageID& helpPageId,
154 bool allowReporting)
155{
156 using namespace BasicUI;
157 ShowErrorDialog( {},
158 caption,
159 message,
160 helpPageId,
161 ErrorDialogOptions { allowReporting ? ErrorDialogType::ModalErrorReport : ErrorDialogType::ModalError });
162}
wxT("CloseDown"))
Toolkit-neutral facade for basic user interface services.
void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName)
Definition: Export.cpp:135
void ShowExportErrorDialog(const TranslatableString &message, const TranslatableString &caption, bool allowReporting)
Definition: Export.cpp:144
std::packaged_task< ExportResult(ExportProcessorDelegate &)> ExportTask
Definition: ExportTypes.h:31
XO("Cut/Copy/Paste")
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
virtual std::unique_ptr< ExportProcessor > CreateProcessor(int format) const =0
std::vector< std::tuple< ExportOptionID, ExportValue > > Parameters
Definition: ExportPlugin.h:93
bool mSelectedOnly
Definition: Export.h:54
ExportTaskBuilder & SetPlugin(const ExportPlugin *plugin, int format=0) noexcept
Definition: Export.cpp:59
double mSampleRate
Definition: Export.h:56
ExportTaskBuilder & SetTags(const Tags *tags) noexcept
Definition: Export.cpp:78
ExportProcessor::Parameters mParameters
Definition: Export.h:57
ExportTaskBuilder & SetMixerSpec(MixerOptions::Downmix *mixerSpec) noexcept
Definition: Export.cpp:66
MixerOptions::Downmix * mMixerSpec
Definition: Export.h:60
const Tags * mTags
Definition: Export.h:61
ExportTask Build(AudacityProject &project)
Definition: Export.cpp:84
ExportTaskBuilder & SetParameters(ExportProcessor::Parameters parameters) noexcept
Definition: Export.cpp:47
ExportTaskBuilder & SetNumChannels(unsigned numChannels) noexcept
Definition: Export.cpp:53
double mT1
Definition: Export.h:53
ExportTaskBuilder & SetSampleRate(double sampleRate) noexcept
Definition: Export.cpp:72
ExportTaskBuilder & SetFileName(const wxFileName &filename)
Definition: Export.cpp:33
double mT0
Definition: Export.h:52
const ExportPlugin * mPlugin
Definition: Export.h:58
unsigned mNumChannels
Definition: Export.h:55
wxFileName mFileName
Definition: Export.h:51
ExportTaskBuilder & SetRange(double t0, double t1, bool selectedOnly=false) noexcept
Definition: Export.cpp:39
static TranslatableString WriteFailureMessage(const wxFileName &fileName)
A matrix of booleans, one row per input channel, column per output.
Definition: MixerOptions.h:32
unsigned GetNumChannels() const
Definition: MixerOptions.h:47
ID3 Tags (for MP3)
Definition: Tags.h:73
Holds a msgid for the translation catalog; may also bind format arguments.
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
Definition: BasicUI.h:262
Options for variations of error dialogs; the default is for modal dialogs.
Definition: BasicUI.h:52