Audacity  3.0.3
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 
18 #include "ImportExportCommands.h"
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 
37  S.Define( mFileName, wxT("Filename"), "" );
38  return true;
39 }
40 
42 {
43  S.AddSpace(0, 5);
44 
45  S.StartMultiColumn(2, wxALIGN_CENTER);
46  {
47  S.TieTextBox(XXO("File Name:"),mFileName);
48  }
49  S.EndMultiColumn();
50 }
51 
52 bool ImportCommand::Apply(const CommandContext & context)
53 {
54  bool wasEmpty = TrackList::Get( context.project ).Any().empty();
55  bool success = ProjectFileManager::Get( context.project )
56  .Import(mFileName, false);
57 
58  if (success && wasEmpty)
59  {
61  }
62 
63  return success;
64 }
65 
66 
67 
69  wxFileName fn = FileNames::FindDefaultPath(FileNames::Operation::Export);
70  fn.SetName("exported.wav");
71  S.Define(mFileName, wxT("Filename"), fn.GetFullPath());
72  S.Define( mnChannels, wxT("NumChannels"), 1 );
73  return true;
74 }
75 
77 { XO("Export2") };
78 
80 
82 {
83  S.AddSpace(0, 5);
84 
85  S.StartMultiColumn(2, wxALIGN_CENTER);
86  {
87  S.TieTextBox(XXO("File Name:"),mFileName);
88  S.TieTextBox(XXO("Number of Channels:"),mnChannels);
89  }
90  S.EndMultiColumn();
91 }
92 
93 bool ExportCommand::Apply(const CommandContext & context)
94 {
95  double t0, t1;
96  auto &selectedRegion = ViewInfo::Get( context.project ).selectedRegion;
97  t0 = selectedRegion.t0();
98  t1 = selectedRegion.t1();
99 
100  // Find the extension and check it's valid
101  int splitAt = mFileName.Find(wxUniChar('.'), true);
102  if (splitAt < 0)
103  {
104  context.Error(wxT("Export filename must have an extension!"));
105  return false;
106  }
107  wxString extension = mFileName.Mid(splitAt+1).MakeUpper();
108 
109  Exporter exporter{ context.project };
110 
111  bool exportSuccess = exporter.Process(std::max(0, mnChannels),
112  extension, mFileName,
113  true, t0, t1);
114 
115  if (exportSuccess)
116  {
117  context.Status(wxString::Format(wxT("Exported to %s format: %s"),
118  extension, mFileName));
119  return true;
120  }
121 
122  context.Error(wxString::Format(wxT("Could not export to %s format!"), extension));
123  return false;
124 }
125 
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:156
LoadCommands.h
fn
static const auto fn
Definition: WaveformView.cpp:1114
ExportCommand::Apply
bool Apply(const CommandContext &context) override
Definition: ImportExportCommands.cpp:93
ExportCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: ImportExportCommands.h:47
Exporter
Definition: Export.h:166
ImportCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: ImportExportCommands.h:29
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2447
XO
#define XO(s)
Definition: Internat.h:31
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
ExportCommand::mnChannels
int mnChannels
Definition: ImportExportCommands.h:60
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
anonymous_namespace{ImportExportCommands.cpp}::reg
BuiltinCommandsModule::Registration< ImportCommand > reg
Definition: ImportExportCommands.cpp:34
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
anonymous_namespace{ImportExportCommands.cpp}::reg2
BuiltinCommandsModule::Registration< ExportCommand > reg2
Definition: ImportExportCommands.cpp:79
ShuttleGuiBase::TieTextBox
wxTextCtrl * TieTextBox(const TranslatableString &Caption, wxString &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1652
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
CommandContext::Status
virtual void Status(const wxString &message, bool bFlush=false) const
Definition: CommandContext.cpp:63
CommandContext.h
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:200
XXO
#define XXO(s)
Definition: Internat.h:44
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:22
ImportCommand::mFileName
wxString mFileName
Definition: ImportExportCommands.h:41
ProjectFileManager::Get
static ProjectFileManager & Get(AudacityProject &project)
Definition: ProjectFileManager.cpp:61
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ExportCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: ImportExportCommands.cpp:68
SelectUtilities::SelectAllIfNone
void SelectAllIfNone(AudacityProject &project)
Definition: SelectUtilities.cpp:84
ExportCommand::mFileName
wxString mFileName
Definition: ImportExportCommands.h:59
ExportCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: ImportExportCommands.cpp:81
CommandContext::Error
virtual void Error(const wxString &message) const
Definition: CommandContext.cpp:73
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:495
ImportCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: ImportExportCommands.cpp:41
ImportCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: ImportExportCommands.cpp:36
ProjectFileManager::Import
bool Import(const FilePath &fileName, bool addToHistory=true)
Definition: ProjectFileManager.cpp:1197
NotifyingSelectedRegion::t0
double t0() const
Definition: ViewInfo.h:45
ShuttleParams::Define
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:332
TrackList::Any
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1355
FileNames::FindDefaultPath
AUDACITY_DLL_API FilePath FindDefaultPath(Operation op)
ImportCommand::Apply
bool Apply(const CommandContext &context) override
Definition: ImportExportCommands.cpp:52
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:52
ImportExportCommands.h
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631