14#include <rapidjson/document.h>
43 "%lld", std::chrono::system_clock::now().time_since_epoch().count()),
46 fileName.Mkdir(0700, wxPATH_MKDIR_FULL);
48 if (fileName.Exists())
50 if (!wxRemoveFile(fileName.GetFullPath()))
61 range.begin(), range.end(),
63 { return IsMono(*track) && track->GetPan() == 0; }) ?
71 for (
const auto& track :
73 .Any<PlayableTrack>())
75 if (track->GetStartTime() != track->GetEndTime())
101 mCancelled.store(
true, std::memory_order_release);
115 mParent.UploadMixdown();
119 mParent.ReportProgress(
132 return mCancelled.load(std::memory_order_acquire);
149 auto future = mTask.get_future();
151 const auto result = future.get();
157 HandleExportDiskFullError(error);
161 HandleExportError(error);
165 HandleExportException(error);
169 HandleUnkonwnException();
180 ShowDiskFullExportErrorDialog(fileName);
191 ShowExportErrorDialog(message, XO(
"Export failed"), helpPage, true);
200 [
this, message = error.
What()]
202 ShowExportErrorDialog(Verbatim(message), XO(
"Export failed"), true);
217 std::atomic<bool> mCancelled {
false };
221MixdownUploader::MixdownUploader(
224 : mServiceConfig { config }
226 , mProgressCallback {
std::move(progressCallback) }
227 , mCancellationContext {
std::move(cancellationContext) }
242 if (!progressCallback)
243 progressCallback = [](
auto...) {
return true; };
245 if (!cancellationContext)
246 cancellationContext =
249 auto uploader = std::make_shared<MixdownUploader>(
250 Tag {}, cancellationContext, config,
project, std::move(progressCallback));
252 cancellationContext->OnCancelled(uploader);
301 [weakThis = weak_from_this(),
this]
303 auto lock = weakThis.lock();
322 mPromise.set_value({ state, uploadResult });
337 const double t0 = 0.0;
338 const double t1 =
tracks.GetEndTime();
342 auto hasMimeType = [](
const auto&& mimeTypes,
const std::string& mimeType)
344 return std::find(mimeTypes.begin(), mimeTypes.end(), mimeType) !=
350 for (
const auto& preferredMimeType :
356 auto pluginIt = std::find_if(
357 registry.begin(), registry.end(),
360 auto [plugin, formatIndex] = t;
363 plugin->GetMimeTypes(formatIndex), preferredMimeType) &&
364 plugin->ParseConfig(formatIndex, config, parameters);
367 if (pluginIt == registry.end())
370 const auto [plugin, formatIndex] = *pluginIt;
372 const auto formatInfo = plugin->GetFormatInfo(formatIndex);
423 const auto state = [code = result.
Code]
435 [
this, strongThis = shared_from_this()](
double progress)
Toolkit-neutral facade for basic user interface services.
Declare functions to perform UTF-8 to std::wstring conversions.
std::packaged_task< ExportResult(ExportProcessorDelegate &)> ExportTask
wxString FileExtension
File extension, not including any leading dot.
an object holding per-project preferred sample rate
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
const wxFileNameWrapper & GetFileName() const noexcept
const TranslatableString & GetMessage() const noexcept
const wxString & GetHelpPageId() const noexcept
const wxString & What() const noexcept
static ExportPluginRegistry & Get()
std::vector< std::tuple< ExportOptionID, ExportValue > > Parameters
ExportTaskBuilder & SetPlugin(const ExportPlugin *plugin, int format=0) noexcept
ExportTaskBuilder & SetParameters(ExportProcessor::Parameters parameters) noexcept
ExportTaskBuilder & SetNumChannels(unsigned numChannels) noexcept
ExportTaskBuilder & SetSampleRate(double sampleRate) noexcept
ExportTaskBuilder & SetFileName(const wxFileName &filename)
ExportTaskBuilder & SetRange(double t0, double t1, bool selectedOnly=false) noexcept
static ProjectRate & Get(AudacityProject &project)
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
auto Any() -> TrackIterRange< TrackType >
static TrackList & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Configuration for the audio.com.
rapidjson::Document GetExportConfig(const std::string &exporterName) const
Export configuration suitable for the mime type provided.
static DataUploader & Get()
void Upload(CancellationContextPtr cancellationContex, const ServiceConfig &config, const UploadUrls &target, std::vector< uint8_t > data, std::function< void(ResponseResult)> callback, std::function< void(double)> progressCallback={})
void SetStatusString(const TranslatableString &str) override
void HandleUnkonwnException()
std::thread mExportThread
void HandleExportException(const ExportException &error)
void HandleExportError(const ExportErrorException &error)
bool IsCancelled() const override
ExportResult GetResult() const
bool IsStopped() const override
void HandleExportDiskFullError(const ExportDiskFullError &error)
DataExporter(MixdownUploader &parent, ExportTask task)
void OnComplete(ExportResult result)
void OnProgress(double value) override
MixdownUploader & mParent
const ServiceConfig & mServiceConfig
const AudacityProject & mProject
MixdownProgressCallback mProgressCallback
void ReportProgress(MixdownState state, double progress, ResponseResult uploadResult)
std::condition_variable mUploadUrlsSet
std::promise< MixdownResult > mPromise
std::mutex mUploadUrlsMutex
std::string mExportedFilePath
std::atomic< double > mProgress
std::future< MixdownResult > GetResultFuture()
std::optional< UploadUrls > mUploadUrls
std::atomic< bool > mUploadCancelled
void SetUrls(const UploadUrls &urls)
std::unique_ptr< DataExporter > mDataExporter
bool mProgressUpdateQueued
static std::shared_ptr< MixdownUploader > Upload(concurrency::CancellationContextPtr cancellationContext, const ServiceConfig &config, const AudacityProject &project, MixdownProgressCallback progressCallback)
concurrency::CancellationContextPtr mCancellationContext
std::atomic< bool > mFinished
static CancellationContextPtr Create()
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
bool IsUiThread()
Whether the current thread is the UI thread.
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
ProjectFileIOExtensionRegistry::Extension extension
double GetRate(const Track &track)
int CalculateChannels(const TrackList &trackList)
std::string GenerateTempPath(FileExtension extension)
bool HasPlayableTracks(const AudacityProject &project)
std::function< void(double progress)> MixdownProgressCallback
wxString GetUploadTempPath()
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.
std::shared_ptr< CancellationContext > CancellationContextPtr
std::string ToUTF8(const std::wstring &wstr)
wxString ToWXString(const std::string &str)