Audacity  2.3.1
SetClipCommand.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  James Crook
8 
9 ******************************************************************//*******************************************************************/
18 
19 #include "../Audacity.h"
20 #include "SetClipCommand.h"
21 #include "../Project.h"
22 #include "../Track.h"
23 #include "../TrackPanel.h"
24 #include "../WaveTrack.h"
25 #include "../ShuttleGui.h"
26 #include "CommandContext.h"
27 
29 {
30 }
31 
33 {
39 };
40 
42 {
43  { wxT("Color0"), XO("Color 0") },
44  { wxT("Color1"), XO("Color 1") },
45  { wxT("Color2"), XO("Color 2") },
46  { wxT("Color3"), XO("Color 3") },
47 };
48 
49 
51  S.OptionalY( bHasContainsTime ).Define( mContainsTime, wxT("At"), 0.0, 0.0, 100000.0 );
52  S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
53  // Allowing a negative start time is not a mistake.
54  // It will be used in demonstrating time before zero.
55  S.OptionalN( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -5.0, 1000000.0);
56  return true;
57 };
58 
60 {
61  auto colours = LocalizedStrings( kColourStrings, nColours );
62 
63  S.AddSpace(0, 5);
64 
65  S.StartMultiColumn(3, wxALIGN_CENTER);
66  {
68  S.Optional( bHasColour ).TieChoice( _("Colour:"), mColour, &colours );
69  S.Optional( bHasT0 ).TieNumericTextBox( _("Start:"), mT0 );
70  }
71  S.EndMultiColumn();
72 }
73 
74 bool SetClipCommand::ApplyInner( const CommandContext & context, Track * t )
75 {
76  static_cast<void>(context);
77  // if no 'At' is specified, then any clip in any selected track will be set.
78  t->TypeSwitch([&](WaveTrack *waveTrack) {
79  WaveClipPointers ptrs( waveTrack->SortedClipArray());
80  for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
81  WaveClip * pClip = *it;
82  bool bFound =
83  !bHasContainsTime || (
84  ( pClip->GetStartTime() <= mContainsTime ) &&
85  ( pClip->GetEndTime() >= mContainsTime )
86  );
87  if( bFound )
88  {
89  // Inside this IF is where we actually apply the command
90 
91  if( bHasColour )
92  pClip->SetColourIndex(mColour);
93  // No validation of overlap yet. We assume the user is sensible!
94  if( bHasT0 )
95  pClip->SetOffset(mT0);
96  // \todo Use SetClip to move a clip between tracks too.
97 
98  }
99  }
100  } );
101  return true;
102 }
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
ShuttleGui & Optional(bool &bVar)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
R TypeSwitch(const Functions &...functions)
Definition: Track.h:630
double GetStartTime() const
Definition: WaveClip.cpp:421
Declarations of SetClipCommand and SetClipCommandType classes.
bool ApplyInner(const CommandContext &context, Track *t) override
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2597
kColours
void EndMultiColumn()
#define XO(s)
Definition: Internat.h:33
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
void SetOffset(double offset)
Definition: WaveClip.cpp:392
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:176
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const ComponentInterfaceSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:345
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:191
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:338
wxTextCtrl * TieNumericTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
static const ComponentInterfaceSymbol kColourStrings[nColours]
double mContainsTime
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
bool DefineParams(ShuttleParams &S) override
void PopulateOrExchange(ShuttleGui &S) override
double GetEndTime() const
Definition: WaveClip.cpp:427
std::vector< WaveClip * > WaveClipPointers
Definition: WaveClip.h:126
wxArrayString LocalizedStrings(const ComponentInterfaceSymbol strings[], size_t nStrings)
Definition: Internat.cpp:303
void SetColourIndex(int index)
Definition: WaveClip.h:219
wxSizerItem * AddSpace(int width, int height)