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 "LoadCommands.h"
40#include "Project.h"
41#include "../TrackPanelAx.h"
42#include "../TrackPanel.h"
43#include "../WaveTrack.h"
44#include "../prefs/WaveformSettings.h"
45#include "../prefs/SpectrogramSettings.h"
46#include "../Shuttle.h"
47#include "../ShuttleGui.h"
48#include "../tracks/playabletrack/wavetrack/ui/WaveTrackView.h"
49#include "../tracks/playabletrack/wavetrack/ui/WaveTrackViewConstants.h"
50#include "CommandContext.h"
51
53 mbPromptForTracks = true;
54 bIsSecondChannel = false;
55}
56
57//Define for the old scheme, where SetTrack defines its own track selection.
58//rather than using the current selection.
59//#define USE_OWN_TRACK_SELECTION
60
61
63{
64 static_cast<void>(&context);
65 static_cast<void>(&t);
66 return true;
67};
68
69template<bool Const>
71{
72 static_cast<void>(S);
73#ifdef USE_OWN_TRACK_SELECTION
74 S.OptionalY( bHasTrackIndex ).Define( mTrackIndex, wxT("Track"), 0, 0, 100 );
75 S.OptionalN( bHasChannelIndex ).Define( mChannelIndex, wxT("Channel"), 0, 0, 100 );
76#endif
77 return true;
78}
79
81 { return VisitSettings<false>(S); }
82
84 { return VisitSettings<true>(S); }
85
87{
88 static_cast<void>(S);
89#ifdef USE_OWN_TRACK_SELECTION
91 return;
92 S.AddSpace(0, 5);
93 S.StartMultiColumn(3, wxEXPAND);
94 {
95 S.SetStretchyCol( 2 );
96 S.Optional( bHasTrackIndex ).TieNumericTextBox( XO("Track Index:"), mTrackIndex );
97 S.Optional( bHasChannelIndex).TieNumericTextBox( XO("Channel Index:"), mChannelIndex );
98 }
99 S.EndMultiColumn();
100#endif
101}
102
104{
105 long i = 0;// track counter
106 long j = 0;// channel counter
107 auto &tracks = TrackList::Get( context.project );
108 for ( auto t : tracks.Leaders() )
109 {
110 auto channels = TrackList::Channels(t);
111 for ( auto channel : channels ) {
112 bool bThisTrack =
113#ifdef USE_OWN_TRACK_SELECTION
114 (bHasTrackIndex && (i==mTrackIndex)) ||
115 (bHasChannelIndex && (j==mChannelIndex ) ) ||
117#else
118 channel->GetSelected();
119#endif
120
121 if( bThisTrack ){
122 ApplyInner( context, channel );
123 }
124 ++j; // count all channels
125 }
126 ++i; // count groups of channels
127 }
128 return true;
129}
130
132{ XO("Set Track Status") };
133
135
136template<bool Const>
139 S.OptionalN( bHasTrackName ).Define( mTrackName, wxT("Name"), _("Unnamed") );
140 // There is also a select command. This is an alternative.
141 S.OptionalN( bHasSelected ).Define( bSelected, wxT("Selected"), false );
142 S.OptionalN( bHasFocused ).Define( bFocused, wxT("Focused"), false );
143 return true;
144};
145
147 { return VisitSettings<false>(S); }
148
150 { return VisitSettings<true>(S); }
151
153{
155 S.StartMultiColumn(3, wxEXPAND);
156 {
157 S.SetStretchyCol( 2 );
158 S.Optional( bHasTrackName ).TieTextBox( XXO("Name:"), mTrackName );
159 }
160 S.EndMultiColumn();
161 S.StartMultiColumn(2, wxEXPAND);
162 {
163 S.SetStretchyCol( 1 );
164 S.Optional( bHasSelected ).TieCheckBox( XXO("Selected"), bSelected );
165 S.Optional( bHasFocused ).TieCheckBox( XXO("Focused"), bFocused);
166 }
167 S.EndMultiColumn();
168}
169
171{
172 //auto wt = dynamic_cast<WaveTrack *>(t);
173 //auto pt = dynamic_cast<PlayableTrack *>(t);
174
175 // You can get some intriguing effects by setting R and L channels to
176 // different values.
177 if( bHasTrackName )
179
180 // In stereo tracks, both channels need selecting/deselecting.
181 if( bHasSelected )
183
184 // These ones don't make sense on the second channel of a stereo track.
185 if( !bIsSecondChannel ){
186 if( bHasFocused )
187 {
188 auto &trackFocus = TrackFocus::Get( context.project );
189 if( bFocused)
190 trackFocus.Set( t );
191 else if( t == trackFocus.Get() )
192 trackFocus.Set( nullptr );
193 }
194 }
195 return true;
196}
197
198
199
201{ XO("Set Track Audio") };
202
204
205template<bool Const>
208 S.OptionalN( bHasMute ).Define( bMute, wxT("Mute"), false );
209 S.OptionalN( bHasSolo ).Define( bSolo, wxT("Solo"), false );
210
211 S.OptionalN( bHasGain ).Define( mGain, wxT("Gain"), 0.0, -36.0, 36.0);
212 S.OptionalN( bHasPan ).Define( mPan, wxT("Pan"), 0.0, -100.0, 100.0);
213 return true;
214};
215
217 { return VisitSettings<false>(S); }
218
220 { return VisitSettings<true>(S); }
221
223{
225 S.StartMultiColumn(2, wxEXPAND);
226 {
227 S.SetStretchyCol( 1 );
228 S.Optional( bHasMute ).TieCheckBox( XXO("Mute"), bMute);
229 S.Optional( bHasSolo ).TieCheckBox( XXO("Solo"), bSolo);
230 }
231 S.EndMultiColumn();
232 S.StartMultiColumn(3, wxEXPAND);
233 {
234 S.SetStretchyCol( 2 );
235 S.Optional( bHasGain ).TieSlider( XXO("Gain:"), mGain, 36.0,-36.0);
236 S.Optional( bHasPan ).TieSlider( XXO("Pan:"), mPan, 100.0, -100.0);
237 }
238 S.EndMultiColumn();
239}
240
242{
243 static_cast<void>(context);
244 auto wt = dynamic_cast<WaveTrack *>(t);
245 auto pt = dynamic_cast<PlayableTrack *>(t);
246
247 if( wt && bHasGain )
248 wt->SetGain(DB_TO_LINEAR(mGain));
249 if( wt && bHasPan )
250 wt->SetPan(mPan/100.0);
251
252 // These ones don't make sense on the second channel of a stereo track.
253 if( !bIsSecondChannel ){
254 if( pt && bHasSolo )
255 pt->SetSolo(bSolo);
256 if( pt && bHasMute )
257 pt->SetMute(bMute);
258 }
259 return true;
260}
261
262
263
265{ XO("Set Track Visuals") };
266
268
270{
277
279{
280 { wxT("Color0"), XO("Color 0") },
281 { wxT("Color1"), XO("Color 1") },
282 { wxT("Color2"), XO("Color 2") },
283 { wxT("Color3"), XO("Color 3") },
284};
285
286
288{
293
295{
296 // These are acceptable dual purpose internal/visible names
297 { XO("Linear") },
298 /* i18n-hint: abbreviates decibels */
299 { XO("dB") },
300};
301
303{
309
311{
312 { XO("Reset") },
313 { wxT("Times2"), XO("Times 2") },
314 { XO("HalfWave") },
315};
316
318{
319 const auto &types = WaveTrackSubViewType::All();
320 auto result = transform_container< EnumValueSymbols >(
321 types, std::mem_fn( &WaveTrackSubView::Type::name ) );
322 result.push_back( WaveTrackViewConstants::MultiViewSymbol );
323 return result;
324}
325
326template<bool Const>
329 S.OptionalN( bHasHeight ).Define( mHeight, wxT("Height"), 120, 44, 2000 );
330
331 {
332 auto symbols = DiscoverSubViewTypes();
333 S.OptionalN( bHasDisplayType ).DefineEnum( mDisplayType, wxT("Display"), 0, symbols.data(), symbols.size() );
334 }
335
336 S.OptionalN( bHasScaleType ).DefineEnum( mScaleType, wxT("Scale"), kLinear, kScaleTypeStrings, nScaleTypes );
337 S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
338 S.OptionalN( bHasVZoom ).DefineEnum( mVZoom, wxT("VZoom"), kReset, kZoomTypeStrings, nZoomTypes );
339 S.OptionalN( bHasVZoomTop ).Define( mVZoomTop, wxT("VZoomHigh"), 1.0, -2.0, 2.0 );
340 S.OptionalN( bHasVZoomBottom ).Define( mVZoomBottom, wxT("VZoomLow"), -1.0, -2.0, 2.0 );
341
342 S.OptionalN( bHasUseSpecPrefs ).Define( bUseSpecPrefs, wxT("SpecPrefs"), false );
343 S.OptionalN( bHasSpectralSelect ).Define( bSpectralSelect, wxT("SpectralSel"),true );
344
346 S.OptionalN( bHasSpecColorScheme).DefineEnum( mSpecColorScheme,wxT("SpecColor"), SpectrogramSettings::csColorNew, schemes.data(), schemes.size());
347
348 return true;
349};
350
352 { return VisitSettings<false>(S); }
353
355 { return VisitSettings<true>(S); }
356
358{
360 S.StartMultiColumn(3, wxEXPAND);
361 {
362 S.SetStretchyCol( 2 );
363 S.Optional( bHasHeight ).TieNumericTextBox( XXO("Height:"), mHeight );
364 S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
366
367 {
368 auto symbols = DiscoverSubViewTypes();
369 auto typeNames = transform_container<TranslatableStrings>(
370 symbols, std::mem_fn( &EnumValueSymbol::Stripped ) );
371 S.Optional( bHasDisplayType ).TieChoice( XXO("Display:"), mDisplayType,
372 typeNames );
373 }
374
375 S.Optional( bHasScaleType ).TieChoice( XXO("Scale:"), mScaleType,
377 S.Optional( bHasVZoom ).TieChoice( XXO("VZoom:"), mVZoom,
379 S.Optional( bHasVZoomTop ).TieTextBox( XXO("VZoom Top:"), mVZoomTop );
380 S.Optional( bHasVZoomBottom ).TieTextBox( XXO("VZoom Bottom:"), mVZoomBottom );
381 }
382 S.EndMultiColumn();
383 S.StartMultiColumn(2, wxEXPAND);
384 {
385 S.SetStretchyCol( 1 );
386 S.Optional( bHasUseSpecPrefs ).TieCheckBox( XXO("Use Spectral Prefs"), bUseSpecPrefs );
387 S.Optional( bHasSpectralSelect ).TieCheckBox( XXO("Spectral Select"), bSpectralSelect);
388 }
389 S.EndMultiColumn();
390 S.StartMultiColumn(3, wxEXPAND);
391 {
392 S.SetStretchyCol( 2 );
394 S.Optional( bHasSpecColorScheme).TieChoice( XC("Sche&me", "spectrum prefs"), mSpecColorScheme,
395 Msgids( schemes.data(), schemes.size() ) );
396 }
397 S.EndMultiColumn();
398}
399
401{
402 static_cast<void>(context);
403 auto wt = dynamic_cast<WaveTrack *>(t);
404 //auto pt = dynamic_cast<PlayableTrack *>(t);
405 static const double ZOOMLIMIT = 0.001f;
406
407 // You can get some intriguing effects by setting R and L channels to
408 // different values.
409 if( wt && bHasColour )
411
412 if( t && bHasHeight )
414
415 if( wt && bHasDisplayType ) {
416 auto &view = WaveTrackView::Get( *wt );
417 auto &all = WaveTrackSubViewType::All();
418 if (mDisplayType < all.size())
419 view.SetDisplay( all[ mDisplayType ].id );
420 else {
421 view.SetMultiView( true );
422 view.SetDisplay( WaveTrackSubViewType::Default(), false );
423 }
424 }
425 if( wt && bHasScaleType )
426 wt->GetWaveformSettings().scaleType =
427 (mScaleType==kLinear) ?
430
431 if( wt && bHasVZoom ){
432 switch( mVZoom ){
433 default:
434 case kReset: wt->SetDisplayBounds(-1,1); break;
435 case kTimes2: wt->SetDisplayBounds(-2,2); break;
436 case kHalfWave: wt->SetDisplayBounds(0,1); break;
437 }
438 }
439
440 if ( wt && (bHasVZoomTop || bHasVZoomBottom) && !bHasVZoom){
441 float vzmin, vzmax;
442 wt->GetDisplayBounds(&vzmin, &vzmax);
443
444 if ( !bHasVZoomTop ){
445 mVZoomTop = vzmax;
446 }
447 if ( !bHasVZoomBottom ){
448 mVZoomBottom = vzmin;
449 }
450
451 // Can't use std::clamp until C++17
452 mVZoomTop = std::max(-2.0, std::min(mVZoomTop, 2.0));
453 mVZoomBottom = std::max(-2.0, std::min(mVZoomBottom, 2.0));
454
455 if (mVZoomBottom > mVZoomTop){
457 }
458 if ( mVZoomTop - mVZoomBottom < ZOOMLIMIT ){
459 double c = (mVZoomBottom + mVZoomTop) / 2;
460 mVZoomBottom = c - ZOOMLIMIT / 2.0;
461 mVZoomTop = c + ZOOMLIMIT / 2.0;
462 }
463 wt->SetDisplayBounds(mVZoomBottom, mVZoomTop);
464 auto &tp = TrackPanel::Get( context.project );
465 tp.UpdateVRulers();
466 }
467
468 if( wt && bHasUseSpecPrefs ){
469 wt->UseSpectralPrefs( bUseSpecPrefs );
470 }
471 if( wt && bHasSpectralSelect ){
472 wt->GetSpectrogramSettings().spectralSelection = bSpectralSelect;
473 }
474 if (wt && bHasSpecColorScheme) {
475 wt->GetSpectrogramSettings().colorScheme = (SpectrogramSettings::ColorScheme)mSpecColorScheme;
476 }
477
478 return true;
479}
480
481
483{ XO("Set Track") };
484
486
488{
492}
493
495 { return VisitSettings<false>(S); }
497 { return VisitSettings<true>(S); }
498
wxT("CloseDown"))
int min(int a, int b)
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define XC(s, c)
Definition: Internat.h:37
#define _(s)
Definition: Internat.h:75
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:543
kColours
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
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: Track.h:916
static const ComponentInterfaceSymbol Symbol
bool ApplyInner(const CommandContext &context, Track *t) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
virtual bool ApplyInner(const CommandContext &context, Track *t)
bool Apply(const CommandContext &context) override
virtual void PopulateOrExchange(ShuttleGui &S) override
SetTrackStatusCommand mSetStatus
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
SetTrackVisualsCommand mSetVisuals
SetTrackAudioCommand mSetAudio
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 ...
Definition: Shuttle.h:115
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
static const EnumValueSymbols & GetColorSchemeNames()
Track * Get()
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
virtual void SetPan(float)
Definition: Track.h:485
virtual void SetSelected(bool s)
Definition: Track.cpp:87
void SetName(const wxString &n)
Definition: Track.cpp:79
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1541
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:230
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:57
void SetWaveColorIndex(int colorIndex)
Definition: WaveTrack.cpp:568
static WaveTrackView & Get(WaveTrack &track)
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:753
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.