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"
47#include "WaveTrack.h"
48#include "../prefs/WaveformSettings.h"
49#include "../prefs/SpectrogramSettings.h"
50#include "SettingsVisitor.h"
51#include "ShuttleGui.h"
52#include "../tracks/playabletrack/wavetrack/ui/WaveChannelView.h"
53#include "../tracks/playabletrack/wavetrack/ui/WaveChannelViewConstants.h"
54#include "CommandContext.h"
55
57{
58 auto &tracks = TrackList::Get(context.project);
59 for (auto t : tracks) {
60 if (t->GetSelected())
61 ApplyInner(context, *t);
62 }
63 return true;
64}
65
67{ XO("Set Track Status") };
68
70
71template<bool Const>
73 S.OptionalN( bHasTrackName ).Define( mTrackName, wxT("Name"), _("Unnamed") );
74 // There is also a select command. This is an alternative.
75 S.OptionalN( bHasSelected ).Define( bSelected, wxT("Selected"), false );
76 S.OptionalN( bHasFocused ).Define( bFocused, wxT("Focused"), false );
77 return true;
78};
79
81 { return VisitSettings<false>(S); }
82
84 { return VisitSettings<true>(S); }
85
87{
88 S.StartMultiColumn(3, wxEXPAND);
89 {
90 S.SetStretchyCol( 2 );
91 S.Optional( bHasTrackName ).TieTextBox( XXO("Name:"), mTrackName );
92 }
93 S.EndMultiColumn();
94 S.StartMultiColumn(2, wxEXPAND);
95 {
96 S.SetStretchyCol( 1 );
97 S.Optional( bHasSelected ).TieCheckBox( XXO("Selected"), bSelected );
98 S.Optional( bHasFocused ).TieCheckBox( XXO("Focused"), bFocused);
99 }
100 S.EndMultiColumn();
101}
102
104{
105 //auto wt = dynamic_cast<WaveTrack *>(t);
106 //auto pt = dynamic_cast<PlayableTrack *>(t);
107
108 if (bHasTrackName)
110
111 if (bHasSelected)
113
114 if (bHasFocused) {
115 auto &trackFocus = TrackFocus::Get(context.project);
116 if (bFocused)
117 trackFocus.Set(&t);
118 else if (&t == trackFocus.Get())
119 trackFocus.Set(nullptr);
120 }
121 return true;
122}
123
124
125
127{ XO("Set Track Audio") };
128
130
131template<bool Const>
133 S.OptionalN( bHasMute ).Define( bMute, wxT("Mute"), false );
134 S.OptionalN( bHasSolo ).Define( bSolo, wxT("Solo"), false );
135
136 S.OptionalN( bHasGain ).Define( mGain, wxT("Gain"), 0.0, -36.0, 36.0);
137 S.OptionalN( bHasPan ).Define( mPan, wxT("Pan"), 0.0, -100.0, 100.0);
138 return true;
139};
140
142 { return VisitSettings<false>(S); }
143
145 { return VisitSettings<true>(S); }
146
148{
149 S.StartMultiColumn(2, wxEXPAND);
150 {
151 S.SetStretchyCol( 1 );
152 S.Optional( bHasMute ).TieCheckBox( XXO("Mute"), bMute);
153 S.Optional( bHasSolo ).TieCheckBox( XXO("Solo"), bSolo);
154 }
155 S.EndMultiColumn();
156 S.StartMultiColumn(3, wxEXPAND);
157 {
158 S.SetStretchyCol( 2 );
159 S.Optional( bHasGain ).TieSlider( XXO("Gain:"), mGain, 36.0,-36.0);
160 S.Optional( bHasPan ).TieSlider( XXO("Pan:"), mPan, 100.0, -100.0);
161 }
162 S.EndMultiColumn();
163}
164
166{
167 static_cast<void>(context);
168 auto wt = dynamic_cast<WaveTrack *>(&t);
169 auto pt = dynamic_cast<PlayableTrack *>(&t);
170
171 if (wt && bHasGain)
172 wt->SetGain(DB_TO_LINEAR(mGain));
173 if (wt && bHasPan)
174 wt->SetPan(mPan/100.0);
175
176 if (pt && bHasSolo)
177 pt->SetSolo(bSolo);
178 if (pt && bHasMute)
179 pt->SetMute(bMute);
180 return true;
181}
182
183
184
186{ XO("Set Track Visuals") };
187
189
191{
198
200{
201 { wxT("Color0"), XO("Color 0") },
202 { wxT("Color1"), XO("Color 1") },
203 { wxT("Color2"), XO("Color 2") },
204 { wxT("Color3"), XO("Color 3") },
205};
206
207
209{
215
217{
218 /* i18n-hint: abbreviates amplitude */
219 { wxT("Linear"), XO("Linear (amp)") },
220 /* i18n-hint: abbreviates decibels */
221 { wxT("dB"), XO("Logarithmic (dB)") },
222 /* i18n-hint: abbreviates decibels */
223 { wxT("LinearDB"), XO("Linear (dB)")}
224};
225
227{
233
235{
236 { XO("Reset") },
237 { wxT("Times2"), XO("Times 2") },
238 { XO("HalfWave") },
239};
240
242{
243 const auto &types = WaveChannelSubViewType::All();
244 auto result = transform_container< EnumValueSymbols >(
245 types, std::mem_fn(&WaveChannelSubView::Type::name) );
247 return result;
248}
249
250template<bool Const>
252 S.OptionalN( bHasHeight ).Define( mHeight, wxT("Height"), 120, 44, 2000 );
253
254 {
255 auto symbols = DiscoverSubViewTypes();
256 S.OptionalN( bHasDisplayType ).DefineEnum( mDisplayType, wxT("Display"), 0, symbols.data(), symbols.size() );
257 }
258
259 S.OptionalN( bHasScaleType ).DefineEnum( mScaleType, wxT("Scale"), kLinearAmp, kScaleTypeStrings, nScaleTypes );
260 S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
261 S.OptionalN( bHasVZoom ).DefineEnum( mVZoom, wxT("VZoom"), kReset, kZoomTypeStrings, nZoomTypes );
262 S.OptionalN( bHasVZoomTop ).Define( mVZoomTop, wxT("VZoomHigh"), 1.0, -2.0, 2.0 );
263 S.OptionalN( bHasVZoomBottom ).Define( mVZoomBottom, wxT("VZoomLow"), -1.0, -2.0, 2.0 );
264
265 S.OptionalN( bHasUseSpecPrefs ).Define( bUseSpecPrefs, wxT("SpecPrefs"), false );
266 S.OptionalN( bHasSpectralSelect ).Define( bSpectralSelect, wxT("SpectralSel"),true );
267
269 S.OptionalN( bHasSpecColorScheme).DefineEnum( mSpecColorScheme,wxT("SpecColor"), SpectrogramSettings::csColorNew, schemes.data(), schemes.size());
270
271 return true;
272};
273
275 { return VisitSettings<false>(S); }
276
278 { return VisitSettings<true>(S); }
279
281{
282 S.StartMultiColumn(3, wxEXPAND);
283 {
284 S.SetStretchyCol( 2 );
285 S.Optional( bHasHeight ).TieNumericTextBox( XXO("Height:"), mHeight );
286 S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
288
289 {
290 auto symbols = DiscoverSubViewTypes();
291 auto typeNames = transform_container<TranslatableStrings>(
292 symbols, std::mem_fn( &EnumValueSymbol::Stripped ) );
293 S.Optional( bHasDisplayType ).TieChoice( XXO("Display:"), mDisplayType,
294 typeNames );
295 }
296
297 S.Optional( bHasScaleType ).TieChoice( XXO("Scale:"), mScaleType,
299 S.Optional( bHasVZoom ).TieChoice( XXO("VZoom:"), mVZoom,
301 S.Optional( bHasVZoomTop ).TieTextBox( XXO("VZoom Top:"), mVZoomTop );
302 S.Optional( bHasVZoomBottom ).TieTextBox( XXO("VZoom Bottom:"), mVZoomBottom );
303 }
304 S.EndMultiColumn();
305 S.StartMultiColumn(2, wxEXPAND);
306 {
307 S.SetStretchyCol( 1 );
308 S.Optional( bHasUseSpecPrefs ).TieCheckBox( XXO("Use Spectral Prefs"), bUseSpecPrefs );
309 S.Optional( bHasSpectralSelect ).TieCheckBox( XXO("Spectral Select"), bSpectralSelect);
310 }
311 S.EndMultiColumn();
312 S.StartMultiColumn(3, wxEXPAND);
313 {
314 S.SetStretchyCol( 2 );
316 S.Optional( bHasSpecColorScheme).TieChoice( XC("Sche&me:", "spectrum prefs"), mSpecColorScheme,
317 Msgids( schemes.data(), schemes.size() ) );
318 }
319 S.EndMultiColumn();
320}
321
323 const CommandContext & context, Track &t)
324{
325 static_cast<void>(context);
326 const auto wt = dynamic_cast<WaveTrack *>(&t);
327 if (!wt)
328 return true;
329 //auto pt = dynamic_cast<PlayableTrack *>(t);
330 static const double ZOOMLIMIT = 0.001f;
331
332 if (bHasColour)
334
335 if (bHasHeight)
336 for (auto pChannel : t.Channels<WaveTrack>())
338
339 if (bHasDisplayType) {
340 auto &view = WaveChannelView::Get(*wt);
341 auto &all = WaveChannelSubViewType::All();
342 if (mDisplayType < all.size())
343 view.SetDisplay( all[ mDisplayType ].id );
344 else {
345 view.SetMultiView( true );
346 view.SetDisplay(WaveChannelSubViewType::Default(), false);
347 }
348 }
349 if (bHasScaleType) {
350 auto &scaleType = WaveformSettings::Get(*wt).scaleType;
351 switch (mScaleType) {
352 default:
355 case kLinearDb: scaleType = WaveformSettings::stLinearDb;
356 }
357 }
358
359 if (bHasVZoom) {
360 auto &cache = WaveformScale::Get(*wt);
361 switch( mVZoom ){
362 default:
363 case kReset: cache.SetDisplayBounds(-1,1); break;
364 case kTimes2: cache.SetDisplayBounds(-2,2); break;
365 case kHalfWave: cache.SetDisplayBounds(0,1); break;
366 }
367 }
368
370 float vzmin, vzmax;
371 auto &cache = WaveformScale::Get(*wt);
372 cache.GetDisplayBounds(vzmin, vzmax);
373
374 if ( !bHasVZoomTop ){
375 mVZoomTop = vzmax;
376 }
377 if ( !bHasVZoomBottom ){
378 mVZoomBottom = vzmin;
379 }
380
381 mVZoomTop = std::clamp(mVZoomTop, -2.0, 2.0);
382 mVZoomBottom = std::clamp(mVZoomBottom, -2.0, 2.0);
383
384 if (mVZoomBottom > mVZoomTop){
386 }
387 if ( mVZoomTop - mVZoomBottom < ZOOMLIMIT ){
388 double c = (mVZoomBottom + mVZoomTop) / 2;
389 mVZoomBottom = c - ZOOMLIMIT / 2.0;
390 mVZoomTop = c + ZOOMLIMIT / 2.0;
391 }
392 cache.SetDisplayBounds(mVZoomBottom, mVZoomTop);
393 auto &tp = TrackPanel::Get( context.project );
394 tp.UpdateVRulers();
395 }
396
397 if (bHasUseSpecPrefs) {
398 if (bUseSpecPrefs)
399 // reset it, and next we will be getting the defaults.
401 else
403 }
405 if (wt && bHasSpectralSelect)
406 settings.spectralSelection = bSpectralSelect;
407 if (wt && bHasSpecColorScheme)
408 settings.colorScheme =
410
411 return true;
412}
413
414
416{ XO("Set Track") };
417
419
421 { return VisitSettings<false>(S); }
423 { return VisitSettings<true>(S); }
424
425namespace {
426using namespace MenuRegistry;
427
428// Register menu items
429
431 Items( wxT(""),
432 // Note that the PLUGIN_SYMBOL must have a space between words,
433 // whereas the short-form used here must not.
434 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
435 // you would have to use "CompareAudio" here.)
436 Command( wxT("SetTrackStatus"), XXO("Set Track Status..."),
438 Command( wxT("SetTrackAudio"), XXO("Set Track Audio..."),
440 Command( wxT("SetTrackVisuals"), XXO("Set Track Visuals..."),
442 ),
443 wxT("Optional/Extra/Part2/Scriptables1")
444};
445
447 // Note that the PLUGIN_SYMBOL must have a space between words,
448 // whereas the short-form used here must not.
449 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
450 // you would have to use "CompareAudio" here.)
451 Command( wxT("SetTrack"), XXO("Set Track..."),
453 wxT("Optional/Extra/Part2/Scriptables2")
454};
455}
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:561
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:69
IteratorRange< ChannelIterator< ChannelType > > Channels()
Get range of channels with mutative access.
Definition: Channel.h:408
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:317
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:630
static void Reset(WaveTrack &track)
Make track lose indpendent settings and use defaults.
static SpectrogramSettings & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
static const EnumValueSymbols & GetColorSchemeNames()
static SpectrogramSettings & Own(WaveTrack &track)
Track * Get()
Definition: TrackFocus.cpp:156
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
virtual void SetSelected(bool s)
Definition: Track.cpp:75
void SetName(const wxString &n)
Definition: Track.cpp:61
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
static WaveChannelView & Get(WaveChannel &channel)
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
void SetWaveColorIndex(int colorIndex)
Definition: WaveTrack.cpp:1194
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:645
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.