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******************************************************************//*******************************************************************/
35
36
37#include "SetTrackInfoCommand.h"
38
39#include "CommandDispatch.h"
40#include "CommandManager.h"
41#include "../CommonCommandFlags.h"
42#include "LoadCommands.h"
43#include "Project.h"
44#include "../TrackPanelAx.h"
45#include "../TrackPanel.h"
46#include "WaveTrack.h"
47#include "../prefs/WaveformSettings.h"
48#include "../prefs/SpectrogramSettings.h"
49#include "SettingsVisitor.h"
50#include "ShuttleGui.h"
51#include "../tracks/playabletrack/wavetrack/ui/WaveTrackView.h"
52#include "../tracks/playabletrack/wavetrack/ui/WaveTrackViewConstants.h"
53#include "CommandContext.h"
54
55bool SetTrackBase::Apply(const CommandContext & context )
56{
57 auto &tracks = TrackList::Get( context.project );
58 for (auto t : tracks.Leaders()) {
59 if (t->GetSelected())
60 for (Track *channel : TrackList::Channels(t))
61 ApplyInner(context, channel);
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 {
116 auto &trackFocus = TrackFocus::Get( context.project );
117 if( bFocused)
118 trackFocus.Set( t );
119 else if( t == trackFocus.Get() )
120 trackFocus.Set( nullptr );
121 }
122 return true;
123}
124
125
126
128{ XO("Set Track Audio") };
129
131
132template<bool Const>
134 S.OptionalN( bHasMute ).Define( bMute, wxT("Mute"), false );
135 S.OptionalN( bHasSolo ).Define( bSolo, wxT("Solo"), false );
136
137 S.OptionalN( bHasGain ).Define( mGain, wxT("Gain"), 0.0, -36.0, 36.0);
138 S.OptionalN( bHasPan ).Define( mPan, wxT("Pan"), 0.0, -100.0, 100.0);
139 return true;
140};
141
143 { return VisitSettings<false>(S); }
144
146 { return VisitSettings<true>(S); }
147
149{
150 S.StartMultiColumn(2, wxEXPAND);
151 {
152 S.SetStretchyCol( 1 );
153 S.Optional( bHasMute ).TieCheckBox( XXO("Mute"), bMute);
154 S.Optional( bHasSolo ).TieCheckBox( XXO("Solo"), bSolo);
155 }
156 S.EndMultiColumn();
157 S.StartMultiColumn(3, wxEXPAND);
158 {
159 S.SetStretchyCol( 2 );
160 S.Optional( bHasGain ).TieSlider( XXO("Gain:"), mGain, 36.0,-36.0);
161 S.Optional( bHasPan ).TieSlider( XXO("Pan:"), mPan, 100.0, -100.0);
162 }
163 S.EndMultiColumn();
164}
165
167{
168 static_cast<void>(context);
169 auto wt = dynamic_cast<WaveTrack *>(t);
170 auto pt = dynamic_cast<PlayableTrack *>(t);
171
172 if (wt && bHasGain)
173 wt->SetGain(DB_TO_LINEAR(mGain));
174 if (wt && bHasPan)
175 wt->SetPan(mPan/100.0);
176
177 if (pt && bHasSolo)
178 pt->SetSolo(bSolo);
179 if (pt && bHasMute)
180 pt->SetMute(bMute);
181 return true;
182}
183
184
185
187{ XO("Set Track Visuals") };
188
190
192{
199
201{
202 { wxT("Color0"), XO("Color 0") },
203 { wxT("Color1"), XO("Color 1") },
204 { wxT("Color2"), XO("Color 2") },
205 { wxT("Color3"), XO("Color 3") },
206};
207
208
210{
216
218{
219 /* i18n-hint: abbreviates amplitude */
220 { wxT("Linear"), XO("Linear (amp)") },
221 /* i18n-hint: abbreviates decibels */
222 { wxT("dB"), XO("Logarithmic (dB)") },
223 /* i18n-hint: abbreviates decibels */
224 { wxT("LinearDB"), XO("Linear (dB)")}
225};
226
228{
234
236{
237 { XO("Reset") },
238 { wxT("Times2"), XO("Times 2") },
239 { XO("HalfWave") },
240};
241
243{
244 const auto &types = WaveTrackSubViewType::All();
245 auto result = transform_container< EnumValueSymbols >(
246 types, std::mem_fn( &WaveTrackSubView::Type::name ) );
247 result.push_back( WaveTrackViewConstants::MultiViewSymbol );
248 return result;
249}
250
251template<bool Const>
253 S.OptionalN( bHasHeight ).Define( mHeight, wxT("Height"), 120, 44, 2000 );
254
255 {
256 auto symbols = DiscoverSubViewTypes();
257 S.OptionalN( bHasDisplayType ).DefineEnum( mDisplayType, wxT("Display"), 0, symbols.data(), symbols.size() );
258 }
259
260 S.OptionalN( bHasScaleType ).DefineEnum( mScaleType, wxT("Scale"), kLinearAmp, kScaleTypeStrings, nScaleTypes );
261 S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
262 S.OptionalN( bHasVZoom ).DefineEnum( mVZoom, wxT("VZoom"), kReset, kZoomTypeStrings, nZoomTypes );
263 S.OptionalN( bHasVZoomTop ).Define( mVZoomTop, wxT("VZoomHigh"), 1.0, -2.0, 2.0 );
264 S.OptionalN( bHasVZoomBottom ).Define( mVZoomBottom, wxT("VZoomLow"), -1.0, -2.0, 2.0 );
265
266 S.OptionalN( bHasUseSpecPrefs ).Define( bUseSpecPrefs, wxT("SpecPrefs"), false );
267 S.OptionalN( bHasSpectralSelect ).Define( bSpectralSelect, wxT("SpectralSel"),true );
268
270 S.OptionalN( bHasSpecColorScheme).DefineEnum( mSpecColorScheme,wxT("SpecColor"), SpectrogramSettings::csColorNew, schemes.data(), schemes.size());
271
272 return true;
273};
274
276 { return VisitSettings<false>(S); }
277
279 { return VisitSettings<true>(S); }
280
282{
283 S.StartMultiColumn(3, wxEXPAND);
284 {
285 S.SetStretchyCol( 2 );
286 S.Optional( bHasHeight ).TieNumericTextBox( XXO("Height:"), mHeight );
287 S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
289
290 {
291 auto symbols = DiscoverSubViewTypes();
292 auto typeNames = transform_container<TranslatableStrings>(
293 symbols, std::mem_fn( &EnumValueSymbol::Stripped ) );
294 S.Optional( bHasDisplayType ).TieChoice( XXO("Display:"), mDisplayType,
295 typeNames );
296 }
297
298 S.Optional( bHasScaleType ).TieChoice( XXO("Scale:"), mScaleType,
300 S.Optional( bHasVZoom ).TieChoice( XXO("VZoom:"), mVZoom,
302 S.Optional( bHasVZoomTop ).TieTextBox( XXO("VZoom Top:"), mVZoomTop );
303 S.Optional( bHasVZoomBottom ).TieTextBox( XXO("VZoom Bottom:"), mVZoomBottom );
304 }
305 S.EndMultiColumn();
306 S.StartMultiColumn(2, wxEXPAND);
307 {
308 S.SetStretchyCol( 1 );
309 S.Optional( bHasUseSpecPrefs ).TieCheckBox( XXO("Use Spectral Prefs"), bUseSpecPrefs );
310 S.Optional( bHasSpectralSelect ).TieCheckBox( XXO("Spectral Select"), bSpectralSelect);
311 }
312 S.EndMultiColumn();
313 S.StartMultiColumn(3, wxEXPAND);
314 {
315 S.SetStretchyCol( 2 );
317 S.Optional( bHasSpecColorScheme).TieChoice( XC("Sche&me", "spectrum prefs"), mSpecColorScheme,
318 Msgids( schemes.data(), schemes.size() ) );
319 }
320 S.EndMultiColumn();
321}
322
324{
325 static_cast<void>(context);
326 auto wt = dynamic_cast<WaveTrack *>(t);
327 //auto pt = dynamic_cast<PlayableTrack *>(t);
328 static const double ZOOMLIMIT = 0.001f;
329
330 // You can get some intriguing effects by setting R and L channels to
331 // different values.
332 if( wt && bHasColour )
334
335 if( t && bHasHeight )
337
338 if( wt && bHasDisplayType ) {
339 auto &view = WaveTrackView::Get( *wt );
340 auto &all = WaveTrackSubViewType::All();
341 if (mDisplayType < all.size())
342 view.SetDisplay( all[ mDisplayType ].id );
343 else {
344 view.SetMultiView( true );
345 view.SetDisplay( WaveTrackSubViewType::Default(), false );
346 }
347 }
348 if (wt && bHasScaleType) {
349 auto &scaleType = WaveformSettings::Get(*wt).scaleType;
350 switch (mScaleType) {
351 default:
354 case kLinearDb: scaleType = WaveformSettings::stLinearDb;
355 }
356 }
357
358 if( wt && bHasVZoom ){
359 auto &cache = WaveformScale::Get(*wt);
360 switch( mVZoom ){
361 default:
362 case kReset: cache.SetDisplayBounds(-1,1); break;
363 case kTimes2: cache.SetDisplayBounds(-2,2); break;
364 case kHalfWave: cache.SetDisplayBounds(0,1); break;
365 }
366 }
367
368 if ( wt && (bHasVZoomTop || bHasVZoomBottom) && !bHasVZoom){
369 float vzmin, vzmax;
370 auto &cache = WaveformScale::Get(*wt);
371 cache.GetDisplayBounds(vzmin, vzmax);
372
373 if ( !bHasVZoomTop ){
374 mVZoomTop = vzmax;
375 }
376 if ( !bHasVZoomBottom ){
377 mVZoomBottom = vzmin;
378 }
379
380 // Can't use std::clamp until C++17
381 mVZoomTop = std::max(-2.0, std::min(mVZoomTop, 2.0));
382 mVZoomBottom = std::max(-2.0, std::min(mVZoomBottom, 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( wt && bHasUseSpecPrefs ){
398 if( bUseSpecPrefs ){
399 // reset it, and next we will be getting the defaults.
401 }
402 else {
404 }
405 }
407 if (wt && bHasSpectralSelect)
408 settings.spectralSelection = bSpectralSelect;
409 if (wt && bHasSpecColorScheme)
410 settings.colorScheme =
412
413 return true;
414}
415
416
418{ XO("Set Track") };
419
421
423 { return VisitSettings<false>(S); }
425 { return VisitSettings<true>(S); }
426
427namespace {
428using namespace MenuTable;
429
430// Register menu items
431
433 wxT("Optional/Extra/Part2/Scriptables1"),
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};
447
449 wxT("Optional/Extra/Part2/Scriptables2"),
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};
457}
wxT("CloseDown"))
AttachedItem sAttachment1
AttachedItem sAttachment2
const ReservedCommandFlag & AudioIONotBusyFlag()
int min(int a, int b)
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:560
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.
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:83
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:309
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)
static const ComponentInterfaceSymbol Symbol
bool ApplyInner(const CommandContext &context, Track *t) override
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 ApplyInner(const CommandContext &context, Track *t) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
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:625
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()
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:162
virtual void SetSelected(bool s)
Definition: Track.cpp:87
void SetName(const wxString &n)
Definition: Track.cpp:73
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:385
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1417
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:231
void SetExpandedHeight(int height)
Definition: TrackView.cpp:172
static TrackView & Get(Track &)
Definition: TrackView.cpp:69
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
void SetWaveColorIndex(int colorIndex)
Definition: WaveTrack.cpp:498
static WaveTrackView & Get(WaveTrack &track)
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
constexpr auto Command
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:752
BuiltinCommandsModule::Registration< SetTrackAudioCommand > reg2
BuiltinCommandsModule::Registration< SetTrackCommand > reg4
BuiltinCommandsModule::Registration< SetTrackStatusCommand > reg
BuiltinCommandsModule::Registration< SetTrackVisualsCommand > reg3
static const std::vector< WaveTrackSubViewType > & All()
Discover all registered types.
static Display Default()
Return a preferred type.