Audacity  3.0.3
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 
20 #include "SetClipCommand.h"
21 
22 #include "LoadCommands.h"
23 #include "../WaveClip.h"
24 #include "../WaveTrack.h"
25 #include "../Shuttle.h"
26 #include "../ShuttleGui.h"
27 
29 { XO("Set Clip") };
30 
32 
34 {
35 }
36 
38 {
43  nColours
44 };
45 
47 {
48  { wxT("Color0"), XO("Color 0") },
49  { wxT("Color1"), XO("Color 1") },
50  { wxT("Color2"), XO("Color 2") },
51  { wxT("Color3"), XO("Color 3") },
52 };
53 
54 
56  S.OptionalY( bHasContainsTime ).Define( mContainsTime, wxT("At"), 0.0, 0.0, 100000.0 );
58  // Allowing a negative start time is not a mistake.
59  // It will be used in demonstrating time before zero.
60  S.OptionalN( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -5.0, 1000000.0);
61  return true;
62 };
63 
65 {
66  S.AddSpace(0, 5);
67 
68  S.StartMultiColumn(3, wxALIGN_CENTER);
69  {
71  S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
73  S.Optional( bHasT0 ).TieNumericTextBox( XXO("Start:"), mT0 );
74  }
75  S.EndMultiColumn();
76 }
77 
79 {
80  // if no 'At' is specified, then any clip in any selected track will be set.
81  t->TypeSwitch([&](WaveTrack *waveTrack) {
82  WaveClipPointers ptrs( waveTrack->SortedClipArray());
83  for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
84  WaveClip * pClip = *it;
85  bool bFound =
86  !bHasContainsTime || (
87  ( pClip->GetStartTime() <= mContainsTime ) &&
88  ( pClip->GetEndTime() >= mContainsTime )
89  );
90  if( bFound )
91  {
92  // Inside this IF is where we actually apply the command
93 
94  if( bHasColour )
95  pClip->SetColourIndex(mColour);
96  // No validation of overlap yet. We assume the user is sensible!
97  if( bHasT0 )
98  pClip->SetOffset(mT0);
99  // \todo Use SetClip to move a clip between tracks too.
100 
101  }
102  }
103  } );
104  return true;
105 }
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
LoadCommands.h
kColour0
@ kColour0
Definition: SetClipCommand.cpp:39
SetClipCommand.h
Declarations of SetClipCommand and SetClipCommandType classes.
WaveClip::SetOffset
void SetOffset(double offset)
Definition: WaveClip.cpp:214
SetClipCommand::SetClipCommand
SetClipCommand()
Definition: SetClipCommand.cpp:33
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2447
SetClipCommand::ApplyInner
bool ApplyInner(const CommandContext &context, Track *t) override
Definition: SetClipCommand.cpp:78
WaveClip::GetEndTime
double GetEndTime() const
Definition: WaveClip.cpp:253
XO
#define XO(s)
Definition: Internat.h:31
SetClipCommand::mT0
double mT0
Definition: SetClipCommand.h:40
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
WaveClipPointers
std::vector< WaveClip * > WaveClipPointers
Definition: WaveTrack.h:41
kColour1
@ kColour1
Definition: SetClipCommand.cpp:40
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
WaveTrack::SortedClipArray
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2504
WaveClip::GetStartTime
double GetStartTime() const
Definition: WaveClip.cpp:247
kColours
kColours
Definition: SetClipCommand.cpp:38
WaveClip
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:173
XXO
#define XXO(s)
Definition: Internat.h:44
SetClipCommand::mColour
int mColour
Definition: SetClipCommand.h:39
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:22
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
anonymous_namespace{SetClipCommand.cpp}::reg
BuiltinCommandsModule::Registration< SetClipCommand > reg
Definition: SetClipCommand.cpp:31
ShuttleParams::DefineEnum
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const EnumValueSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:339
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
WaveClip::SetColourIndex
void SetColourIndex(int index)
Definition: WaveClip.h:217
ShuttleGuiBase::TieNumericTextBox
wxTextCtrl * TieNumericTextBox(const TranslatableString &Prompt, int &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1673
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
Definition: ShuttleGui.cpp:2510
SetClipCommand::bHasContainsTime
bool bHasContainsTime
Definition: SetClipCommand.h:43
kColour2
@ kColour2
Definition: SetClipCommand.cpp:41
SetClipCommand::mContainsTime
double mContainsTime
Definition: SetClipCommand.h:38
Track::TypeSwitch
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
Definition: Track.h:693
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
SetClipCommand::bHasT0
bool bHasT0
Definition: SetClipCommand.h:45
nColours
@ nColours
Definition: SetClipCommand.cpp:43
SetClipCommand::bHasColour
bool bHasColour
Definition: SetClipCommand.h:44
SetClipCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: SetClipCommand.h:24
kColour3
@ kColour3
Definition: SetClipCommand.cpp:42
SetClipCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: SetClipCommand.cpp:55
SetClipCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: SetClipCommand.cpp:64
ShuttleParams::Define
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:332
ShuttleGui::Optional
ShuttleGui & Optional(bool &bVar)
Definition: ShuttleGui.cpp:2280
kColourStrings
static const EnumValueSymbol kColourStrings[nColours]
Definition: SetClipCommand.cpp:46
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1727
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631