Audacity 3.2.0
ImportExportCommands.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2009 Audacity Team
5 File License: wxWidgets
6
7 Dan Horgan
8 James Crook
9
10******************************************************************//*******************************************************************/
16
17
19
20#include "LoadCommands.h"
21#include "../ProjectFileManager.h"
22#include "ViewInfo.h"
23#include "../export/Export.h"
24#include "../SelectUtilities.h"
25#include "../Shuttle.h"
26#include "../ShuttleGui.h"
27#include "Track.h"
28#include "wxFileNameWrapper.h"
29#include "CommandContext.h"
30
32{ XO("Import2") };
33
35
36template<bool Const>
38 S.Define( mFileName, wxT("Filename"), wxString{} );
39 return true;
40}
41
43 { return VisitSettings<false>(S); }
44
46 { return VisitSettings<true>(S); }
47
49{
50 S.AddSpace(0, 5);
51
52 S.StartMultiColumn(2, wxALIGN_CENTER);
53 {
54 S.TieTextBox(XXO("File Name:"),mFileName);
55 }
56 S.EndMultiColumn();
57}
58
60{
61 bool wasEmpty = TrackList::Get( context.project ).Any().empty();
62 bool success = ProjectFileManager::Get( context.project )
63 .Import(mFileName, false);
64
65 if (success && wasEmpty)
66 {
68 }
69
70 return success;
71}
72
73template<bool Const>
75 wxFileName fn = FileNames::FindDefaultPath(FileNames::Operation::Export);
76 fn.SetName("exported.wav");
77 S.Define(mFileName, wxT("Filename"), fn.GetFullPath());
78 S.Define( mnChannels, wxT("NumChannels"), 1 );
79 return true;
80}
81
83 { return VisitSettings<false>(S); }
84
86 { return VisitSettings<true>(S); }
87
89{ XO("Export2") };
90
92
94{
95 S.AddSpace(0, 5);
96
97 S.StartMultiColumn(2, wxALIGN_CENTER);
98 {
99 S.TieTextBox(XXO("File Name:"),mFileName);
100 S.TieTextBox(XXO("Number of Channels:"),mnChannels);
101 }
102 S.EndMultiColumn();
103}
104
106{
107 double t0, t1;
108 auto &selectedRegion = ViewInfo::Get( context.project ).selectedRegion;
109 t0 = selectedRegion.t0();
110 t1 = selectedRegion.t1();
111
112 // Find the extension and check it's valid
113 int splitAt = mFileName.Find(wxUniChar('.'), true);
114 if (splitAt < 0)
115 {
116 context.Error(wxT("Export filename must have an extension!"));
117 return false;
118 }
119 wxString extension = mFileName.Mid(splitAt+1).MakeUpper();
120
121 Exporter exporter{ context.project };
122
123 bool exportSuccess = exporter.Process(std::max(0, mnChannels),
124 extension, mFileName,
125 true, t0, t1);
126
127 if (exportSuccess)
128 {
129 context.Status(wxString::Format(wxT("Exported to %s format: %s"),
130 extension, mFileName));
131 return true;
132 }
133
134 context.Error(wxString::Format(wxT("Could not export to %s format!"), extension));
135 return false;
136}
137
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define S(N)
Definition: ToChars.cpp:64
declares abstract base class Track, TrackList, and iterators over TrackList
static const auto fn
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
virtual void Error(const wxString &message) const
virtual void Status(const wxString &message, bool bFlush=false) const
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static const ComponentInterfaceSymbol Symbol
bool Apply(const CommandContext &context) override
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
void PopulateOrExchange(ShuttleGui &S) override
static const ComponentInterfaceSymbol Symbol
double t0() const
Definition: ViewInfo.h:34
bool Import(const FilePath &fileName, bool addToHistory=true)
static ProjectFileManager & Get(AudacityProject &project)
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Definition: Shuttle.h:115
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1435
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
FILES_API FilePath FindDefaultPath(Operation op)
void SelectAllIfNone(AudacityProject &project)
BuiltinCommandsModule::Registration< ImportCommand > reg
BuiltinCommandsModule::Registration< ExportCommand > reg2