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