Audacity 3.2.0
SetTrackInfoCommand.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2018 Audacity Team
5 License: wxwidgets
6
7 Dan Horgan
8 James Crook
9
10******************************************************************//*******************************************************************/
36
37
38#include "SetTrackInfoCommand.h"
39
40#include "CommandDispatch.h"
41#include "MenuRegistry.h"
42#include "../CommonCommandFlags.h"
43#include "LoadCommands.h"
44#include "Project.h"
45#include "TrackFocus.h"
46#include "../TrackPanel.h"
48#include "../prefs/WaveformSettings.h"
49#include "WaveTrack.h"
50#include "../prefs/SpectrogramSettings.h"
51#include "SettingsVisitor.h"
52#include "ShuttleGui.h"
53#include "../tracks/playabletrack/wavetrack/ui/WaveChannelView.h"
54#include "../tracks/playabletrack/wavetrack/ui/WaveChannelViewConstants.h"
55#include "../tracks/playabletrack/wavetrack/ui/WaveformView.h"
56#include "CommandContext.h"
57
59{
60 auto &tracks = TrackList::Get(context.project);
61 for (auto t : tracks) {
62 if (t->GetSelected())
63 ApplyInner(context, *t);
64 }
65 return true;
66}
67
69{ XO("Set Track Status") };
70
72
73template<bool Const>
75 S.OptionalN( bHasTrackName ).Define( mTrackName, wxT("Name"), _("Unnamed") );
76 // There is also a select command. This is an alternative.
77 S.OptionalN( bHasSelected ).Define( bSelected, wxT("Selected"), false );
78 S.OptionalN( bHasFocused ).Define( bFocused, wxT("Focused"), false );
79 return true;
80};
81
83 { return VisitSettings<false>(S); }
84
86 { return VisitSettings<true>(S); }
87
89{
90 S.StartMultiColumn(3, wxEXPAND);
91 {
92 S.SetStretchyCol( 2 );
93 S.Optional( bHasTrackName ).TieTextBox( XXO("Name:"), mTrackName );
94 }
95 S.EndMultiColumn();
96 S.StartMultiColumn(2, wxEXPAND);
97 {
98 S.SetStretchyCol( 1 );
99 S.Optional( bHasSelected ).TieCheckBox( XXO("Selected"), bSelected );
100 S.Optional( bHasFocused ).TieCheckBox( XXO("Focused"), bFocused);
101 }
102 S.EndMultiColumn();
103}
104
106{
107 //auto wt = dynamic_cast<WaveTrack *>(t);
108 //auto pt = dynamic_cast<PlayableTrack *>(t);
109
110 if (bHasTrackName)
112
113 if (bHasSelected)
115
116 if (bHasFocused) {
117 auto &trackFocus = TrackFocus::Get(context.project);
118 if (bFocused)
119 trackFocus.Set(&t);
120 else if (&t == trackFocus.Get())
121 trackFocus.Set(nullptr);
122 }
123 return true;
124}
125
126
127
129{ XO("Set Track Audio") };
130
132
133template<bool Const>
135 S.OptionalN( bHasMute ).Define( bMute, wxT("Mute"), false );
136 S.OptionalN( bHasSolo ).Define( bSolo, wxT("Solo"), false );
137
138 S.OptionalN( bHasGain ).Define( mGain, wxT("Gain"), 0.0, -36.0, 36.0);
139 S.OptionalN( bHasPan ).Define( mPan, wxT("Pan"), 0.0, -100.0, 100.0);
140 return true;
141};
142
144 { return VisitSettings<false>(S); }
145
147 { return VisitSettings<true>(S); }
148
150{
151 S.StartMultiColumn(2, wxEXPAND);
152 {
153 S.SetStretchyCol( 1 );
154 S.Optional( bHasMute ).TieCheckBox( XXO("Mute"), bMute);
155 S.Optional( bHasSolo ).TieCheckBox( XXO("Solo"), bSolo);
156 }
157 S.EndMultiColumn();
158 S.StartMultiColumn(3, wxEXPAND);
159 {
160 S.SetStretchyCol( 2 );
161 S.Optional( bHasGain ).TieSlider( XXO("Gain:"), mGain, 36.0,-36.0);
162 S.Optional( bHasPan ).TieSlider( XXO("Pan:"), mPan, 100.0, -100.0);
163 }
164 S.EndMultiColumn();
165}
166
168{
169 static_cast<void>(context);
170 auto wt = dynamic_cast<WaveTrack *>(&t);
171 auto pt = dynamic_cast<PlayableTrack *>(&t);
172
173 if (wt && bHasGain)
174 wt->SetGain(DB_TO_LINEAR(mGain));
175 if (wt && bHasPan)
176 wt->SetPan(mPan/100.0);
177
178 if (pt && bHasSolo)
179 pt->SetSolo(bSolo);
180 if (pt && bHasMute)
181 pt->SetMute(bMute);
182 return true;
183}
184
185
186
188{ XO("Set Track Visuals") };
189
191
193{
200
202{
203 { wxT("Color0"), XO("Color 0") },
204 { wxT("Color1"), XO("Color 1") },
205 { wxT("Color2"), XO("Color 2") },
206 { wxT("Color3"), XO("Color 3") },
207};
208
209
211{
217
219{
220 /* i18n-hint: abbreviates amplitude */
221 { wxT("Linear"), XO("Linear (amp)") },
222 /* i18n-hint: abbreviates decibels */
223 { wxT("dB"), XO("Logarithmic (dB)") },
224 /* i18n-hint: abbreviates decibels */
225 { wxT("LinearDB"), XO("Linear (dB)")}
226};
227
229{
235
237{
238 { XO("Reset") },
239 { wxT("Times2"), XO("Times 2") },
240 { XO("HalfWave") },
241};
242
244{
245 const auto &types = WaveChannelSubViewType::All();
246 auto result = transform_container< EnumValueSymbols >(
247 types, std::mem_fn(&WaveChannelSubView::Type::name) );
249 return result;
250}
251
252template<bool Const>
254 S.OptionalN( bHasHeight ).Define( mHeight, wxT("Height"), 120, 44, 2000 );
255
256 {
257 auto symbols = DiscoverSubViewTypes();
258 S.OptionalN( bHasDisplayType ).DefineEnum( mDisplayType, wxT("Display"), 0, symbols.data(), symbols.size() );
259 }
260
261 S.OptionalN( bHasScaleType ).DefineEnum( mScaleType, wxT("Scale"), kLinearAmp, kScaleTypeStrings, nScaleTypes );
262 S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
263 S.OptionalN( bHasVZoom ).DefineEnum( mVZoom, wxT("VZoom"), kReset, kZoomTypeStrings, nZoomTypes );
264 S.OptionalN( bHasVZoomTop ).Define( mVZoomTop, wxT("VZoomHigh"), 1.0, -2.0, 2.0 );
265 S.OptionalN( bHasVZoomBottom ).Define( mVZoomBottom, wxT("VZoomLow"), -1.0, -2.0, 2.0 );
266
267 S.OptionalN( bHasUseSpecPrefs ).Define( bUseSpecPrefs, wxT("SpecPrefs"), false );
268 S.OptionalN( bHasSpectralSelect ).Define( bSpectralSelect, wxT("SpectralSel"),true );
269
271 S.OptionalN( bHasSpecColorScheme).DefineEnum( mSpecColorScheme,wxT("SpecColor"), SpectrogramSettings::csColorNew, schemes.data(), schemes.size());
272
273 return true;
274};
275
277 { return VisitSettings<false>(S); }
278
280 { return VisitSettings<true>(S); }
281
283{
284 S.StartMultiColumn(3, wxEXPAND);
285 {
286 S.SetStretchyCol( 2 );
287 S.Optional( bHasHeight ).TieNumericTextBox( XXO("Height:"), mHeight );
288 S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
290
291 {
292 auto symbols = DiscoverSubViewTypes();
293 auto typeNames = transform_container<TranslatableStrings>(
294 symbols, std::mem_fn( &EnumValueSymbol::Stripped ) );
295 S.Optional( bHasDisplayType ).TieChoice( XXO("Display:"), mDisplayType,
296 typeNames );
297 }
298
299 S.Optional( bHasScaleType ).TieChoice( XXO("Scale:"), mScaleType,
301 S.Optional( bHasVZoom ).TieChoice( XXO("VZoom:"), mVZoom,
303 S.Optional( bHasVZoomTop ).TieTextBox( XXO("VZoom Top:"), mVZoomTop );
304 S.Optional( bHasVZoomBottom ).TieTextBox( XXO("VZoom Bottom:"), mVZoomBottom );
305 }
306 S.EndMultiColumn();
307 S.StartMultiColumn(2, wxEXPAND);
308 {
309 S.SetStretchyCol( 1 );
310 S.Optional( bHasUseSpecPrefs ).TieCheckBox( XXO("Use Spectral Prefs"), bUseSpecPrefs );
311 S.Optional( bHasSpectralSelect ).TieCheckBox( XXO("Spectral Select"), bSpectralSelect);
312 }
313 S.EndMultiColumn();
314 S.StartMultiColumn(3, wxEXPAND);
315 {
316 S.SetStretchyCol( 2 );
318 S.Optional( bHasSpecColorScheme).TieChoice( XC("Sche&me:", "spectrum prefs"), mSpecColorScheme,
319 Msgids( schemes.data(), schemes.size() ) );
320 }
321 S.EndMultiColumn();
322}
323
325 const CommandContext & context, Track &t)
326{
327 static_cast<void>(context);
328 const auto wt = dynamic_cast<WaveTrack *>(&t);
329 if (!wt)
330 return true;
331 auto &wc = **wt->Channels().begin();
332 //auto pt = dynamic_cast<PlayableTrack *>(t);
333 static const double ZOOMLIMIT = 0.001f;
334
335 if (bHasColour)
337
338 if (bHasHeight)
339 for (auto pChannel : t.Channels<WaveChannel>())
341
342 if (bHasDisplayType) {
343 auto &view = WaveChannelView::Get(wc);
344 auto &all = WaveChannelSubViewType::All();
345 if (mDisplayType < all.size())
346 view.SetDisplay( all[ mDisplayType ].id );
347 else {
348 view.SetMultiView( true );
349 view.SetDisplay(WaveChannelSubViewType::Default(), false);
350 }
351 }
352 if (bHasScaleType) {
353 auto &scaleType = WaveformSettings::Get(*wt).scaleType;
354 switch (mScaleType) {
355 default:
358 case kLinearDb: scaleType = WaveformSettings::stLinearDb;
359 }
360 }
361
362 if (bHasVZoom) {
363 auto &cache = WaveformScale::Get(*wt);
364 switch( mVZoom ){
365 default:
366 case kReset: cache.SetDisplayBounds(-1,1); break;
367 case kTimes2: cache.SetDisplayBounds(-2,2); break;
368 case kHalfWave: cache.SetDisplayBounds(0,1); break;
369 }
370 }
371
373 float vzmin, vzmax;
374 auto &cache = WaveformScale::Get(*wt);
375 cache.GetDisplayBounds(vzmin, vzmax);
376
377 if ( !bHasVZoomTop ){
378 mVZoomTop = vzmax;
379 }
380 if ( !bHasVZoomBottom ){
381 mVZoomBottom = vzmin;
382 }
383
384 mVZoomTop = std::clamp(mVZoomTop, -2.0, 2.0);
385 mVZoomBottom = std::clamp(mVZoomBottom, -2.0, 2.0);
386
387 if (mVZoomBottom > mVZoomTop){
389 }
390 if ( mVZoomTop - mVZoomBottom < ZOOMLIMIT ){
391 double c = (mVZoomBottom + mVZoomTop) / 2;
392 mVZoomBottom = c - ZOOMLIMIT / 2.0;
393 mVZoomTop = c + ZOOMLIMIT / 2.0;
394 }
395 cache.SetDisplayBounds(mVZoomBottom, mVZoomTop);
396 auto &tp = TrackPanel::Get( context.project );
397 tp.UpdateVRulers();
398 }
399
400 if (bHasUseSpecPrefs) {
401 if (bUseSpecPrefs)
402 // reset it, and next we will be getting the defaults.
404 else
406 }
408 if (wt && bHasSpectralSelect)
409 settings.spectralSelection = bSpectralSelect;
410 if (wt && bHasSpecColorScheme)
411 settings.colorScheme =
413
414 return true;
415}
416
417
419{ XO("Set Track") };
420
422
424 { return VisitSettings<false>(S); }
426 { return VisitSettings<true>(S); }
427
428namespace {
429using namespace MenuRegistry;
430
431// Register menu items
432
434 Items( wxT(""),
435 // Note that the PLUGIN_SYMBOL must have a space between words,
436 // whereas the short-form used here must not.
437 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
438 // you would have to use "CompareAudio" here.)
439 Command( wxT("SetTrackStatus"), XXO("Set Track Status..."),
441 Command( wxT("SetTrackAudio"), XXO("Set Track Audio..."),
443 Command( wxT("SetTrackVisuals"), XXO("Set Track Visuals..."),
445 ),
446 wxT("Optional/Extra/Part2/Scriptables1")
447};
448
450 // Note that the PLUGIN_SYMBOL must have a space between words,
451 // whereas the short-form used here must not.
452 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
453 // you would have to use "CompareAudio" here.)
454 Command( wxT("SetTrack"), XXO("Set Track..."),
456 wxT("Optional/Extra/Part2/Scriptables2")
457};
458}
wxT("CloseDown"))
AttachedItem sAttachment1
AttachedItem sAttachment2
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define XC(s, c)
Definition: Internat.h:37
#define _(s)
Definition: Internat.h:73
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:338
kColours
@ kLogarithmicDb
static const EnumValueSymbol kScaleTypeStrings[nScaleTypes]
static const EnumValueSymbol kZoomTypeStrings[nZoomTypes]
static EnumValueSymbols DiscoverSubViewTypes()
static const EnumValueSymbol kColourStrings[nColours]
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
const auto tracks
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:47
IteratorRange< ChannelIterator< ChannelType > > Channels()
Get range of channels with mutative access.
Definition: Channel.h:381
static ChannelView & Get(Channel &channel)
void SetExpandedHeight(int height)
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:318
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const TranslatableString Stripped() const
AudioTrack subclass that can also be audibly replayed by the program.
Definition: PlayableTrack.h:40
void SetSolo(bool s)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
bool ApplyInner(const CommandContext &context, Track &t) override
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
void PopulateOrExchange(ShuttleGui &S) override
bool Apply(const CommandContext &context) final
virtual bool ApplyInner(const CommandContext &context, Track &t)=0
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
void PopulateOrExchange(ShuttleGui &S) override
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool ApplyInner(const CommandContext &context, Track &t) override
static const ComponentInterfaceSymbol Symbol
bool ApplyInner(const CommandContext &context, Track &t) override
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
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:640
static SpectrogramSettings & Get(const WaveTrack &track)
static const EnumValueSymbols & GetColorSchemeNames()
static SpectrogramSettings & Own(WaveChannel &wc)
static void Reset(WaveChannel &channel)
Make channel lose indpendent settings and use defaults.
Track * Get()
Definition: TrackFocus.cpp:156
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
virtual void SetSelected(bool s)
Definition: Track.cpp:83
void SetName(const wxString &n)
Definition: Track.cpp:69
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
static WaveChannelView & Get(WaveChannel &channel)
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
auto Channels()
Definition: WaveTrack.h:263
static WaveformAppearance & Get(WaveTrack &track)
void SetColorIndex(int colorIndex)
static WaveformScale & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
static WaveformSettings & Get(const WaveTrack &track)
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
AUDACITY_DLL_API const EnumValueSymbol MultiViewSymbol
String identifier for a preference for one of each type of view.
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:628
BuiltinCommandsModule::Registration< SetTrackAudioCommand > reg2
BuiltinCommandsModule::Registration< SetTrackCommand > reg4
BuiltinCommandsModule::Registration< SetTrackStatusCommand > reg
BuiltinCommandsModule::Registration< SetTrackVisualsCommand > reg3
static Display Default()
Return a preferred type.
static const std::vector< WaveChannelSubViewType > & All()
Discover all registered types.