Audacity  2.2.2
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 #include "../Audacity.h"
18 #include "ImportExportCommands.h"
19 #include "../Project.h"
20 #include "../Track.h"
21 #include "../export/Export.h"
22 #include "../ShuttleGui.h"
23 #include "CommandContext.h"
24 
26  S.Define( mFileName, wxT("Filename"), "" );
27  return true;
28 }
29 
31 {
32  S.AddSpace(0, 5);
33 
34  S.StartMultiColumn(2, wxALIGN_CENTER);
35  {
36  S.TieTextBox(_("File Name:"),mFileName);
37  }
38  S.EndMultiColumn();
39 }
40 
41 bool ImportCommand::Apply(const CommandContext & context){
42  return context.GetProject()->Import(mFileName);
43 }
44 
45 
46 
48  S.Define( mFileName, wxT("Filename"), "exported.wav" );
49  S.Define( mnChannels, wxT("NumChannels"), 1 );
50  return true;
51 }
52 
54 {
55  S.AddSpace(0, 5);
56 
57  S.StartMultiColumn(2, wxALIGN_CENTER);
58  {
59  S.TieTextBox(_("File Name:"),mFileName);
60  S.TieTextBox(_("Number of Channels:"),mnChannels);
61  }
62  S.EndMultiColumn();
63 }
64 
65 bool ExportCommand::Apply(const CommandContext & context)
66 {
67  double t0, t1;
68  t0 = context.GetProject()->mViewInfo.selectedRegion.t0();
69  t1 = context.GetProject()->mViewInfo.selectedRegion.t1();
70 
71  // Find the extension and check it's valid
72  int splitAt = mFileName.Find(wxUniChar('.'), true);
73  if (splitAt < 0)
74  {
75  context.Error(wxT("Export filename must have an extension!"));
76  return false;
77  }
78  wxString extension = mFileName.Mid(splitAt+1).MakeUpper();
79 
80  Exporter exporter;
81 
82  bool exportSuccess = exporter.Process(context.GetProject(),
83  std::max(0, mnChannels),
84  extension, mFileName,
85  true, t0, t1);
86 
87  if (exportSuccess)
88  {
89  context.Status(wxString::Format(wxT("Exported to %s format: %s"),
90  extension, mFileName));
91  return true;
92  }
93 
94  context.Error(wxString::Format(wxT("Could not export to %s format!"), extension));
95  return false;
96 }
97 
AudacityProject * GetProject() const
double t0() const
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
void EndMultiColumn()
bool Process(AudacityProject *project, bool selectedOnly, double t0, double t1)
Definition: Export.cpp:338
virtual void Status(const wxString &message, bool bFlush=false) const
void PopulateOrExchange(ShuttleGui &S) override
bool DefineParams(ShuttleParams &S) override
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
double t1() const
void PopulateOrExchange(ShuttleGui &S) override
bool Import(const wxString &fileName, WaveTrackArray *pTrackArray=NULL)
Definition: Project.cpp:4379
bool DefineParams(ShuttleParams &S) override
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
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:339
ViewInfo mViewInfo
Definition: Project.h:558
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
virtual void Error(const wxString &message) const
wxSizerItem * AddSpace(int width, int height)
wxTextCtrl * TieTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
virtual bool Apply()