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 "CommandDispatch.h"
21#include "CommandManager.h"
22#include "../CommonCommandFlags.h"
23#include "LoadCommands.h"
24#include "../ProjectFileManager.h"
25#include "ViewInfo.h"
26#include "../export/Export.h"
27#include "../SelectUtilities.h"
28#include "SettingsVisitor.h"
29#include "ShuttleGui.h"
30#include "Track.h"
31#include "wxFileNameWrapper.h"
32#include "CommandContext.h"
33
35{ XO("Import2") };
36
38
39template<bool Const>
41 S.Define( mFileName, wxT("Filename"), wxString{} );
42 return true;
43}
44
46 { return VisitSettings<false>(S); }
47
49 { return VisitSettings<true>(S); }
50
52{
53 S.AddSpace(0, 5);
54
55 S.StartMultiColumn(2, wxALIGN_CENTER);
56 {
57 S.TieTextBox(XXO("File Name:"),mFileName);
58 }
59 S.EndMultiColumn();
60}
61
63{
64 bool wasEmpty = TrackList::Get( context.project ).Any().empty();
65 bool success = ProjectFileManager::Get( context.project )
66 .Import(mFileName, false);
67
68 if (success && wasEmpty)
69 {
71 }
72
73 return success;
74}
75
76template<bool Const>
78 wxFileName fn = FileNames::FindDefaultPath(FileNames::Operation::Export);
79 fn.SetName("exported.wav");
80 S.Define(mFileName, wxT("Filename"), fn.GetFullPath());
81 S.Define( mnChannels, wxT("NumChannels"), 1 );
82 return true;
83}
84
86 { return VisitSettings<false>(S); }
87
89 { return VisitSettings<true>(S); }
90
92{ XO("Export2") };
93
95
97{
98 S.AddSpace(0, 5);
99
100 S.StartMultiColumn(2, wxALIGN_CENTER);
101 {
102 S.TieTextBox(XXO("File Name:"),mFileName);
103 S.TieTextBox(XXO("Number of Channels:"),mnChannels);
104 }
105 S.EndMultiColumn();
106}
107
109{
110 double t0, t1;
111 auto &selectedRegion = ViewInfo::Get( context.project ).selectedRegion;
112 t0 = selectedRegion.t0();
113 t1 = selectedRegion.t1();
114
115 // Find the extension and check it's valid
116 int splitAt = mFileName.Find(wxUniChar('.'), true);
117 if (splitAt < 0)
118 {
119 context.Error(wxT("Export filename must have an extension!"));
120 return false;
121 }
122 wxString extension = mFileName.Mid(splitAt+1).MakeUpper();
123
124 Exporter exporter{ context.project };
125
126 bool exportSuccess = exporter.Process(std::max(0, mnChannels),
127 extension, mFileName,
128 true, t0, t1);
129
130 if (exportSuccess)
131 {
132 context.Status(wxString::Format(wxT("Exported to %s format: %s"),
133 extension, mFileName));
134 return true;
135 }
136
137 context.Error(wxString::Format(wxT("Could not export to %s format!"), extension));
138 return false;
139}
140
141namespace {
142using namespace MenuTable;
143
144// Register menu items
145
147 wxT("Optional/Extra/Part2/Scriptables2"),
148 Items( wxT(""),
149 // Note that the PLUGIN_SYMBOL must have a space between words,
150 // whereas the short-form used here must not.
151 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
152 // you would have to use "CompareAudio" here.)
153 Command( wxT("Import2"), XXO("Import..."),
155 Command( wxT("Export2"), XXO("Export..."),
157 )
158};
159}
wxT("CloseDown"))
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#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:35
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 ...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1302
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:360
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
FILES_API FilePath FindDefaultPath(Operation op)
constexpr auto Items
constexpr auto Command
void SelectAllIfNone(AudacityProject &project)
BuiltinCommandsModule::Registration< ImportCommand > reg
BuiltinCommandsModule::Registration< ExportCommand > reg2