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  S.Optional( bHasName ).TieTextBox( XXO("Name:"), mName );
75  }
76  S.EndMultiColumn();
77 }
78 
80 {
81  // if no 'At' is specified, then any clip in any selected track will be set.
82  t->TypeSwitch([&](WaveTrack *waveTrack) {
83  WaveClipPointers ptrs( waveTrack->SortedClipArray());
84  for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
85  WaveClip * pClip = *it;
86  bool bFound =
87  !bHasContainsTime || (
88  ( pClip->GetPlayStartTime() <= mContainsTime ) &&
89  ( pClip->GetPlayEndTime() >= mContainsTime )
90  );
91  if( bFound )
92  {
93  // Inside this IF is where we actually apply the command
94 
95  if( bHasColour )
96  pClip->SetColourIndex(mColour);
97  // No validation of overlap yet. We assume the user is sensible!
98  if( bHasT0 )
99  pClip->SetPlayStartTime(mT0);
100  // \todo Use SetClip to move a clip between tracks too.
101  if( bHasName )
102  pClip->SetName(mName);
103 
104  }
105  }
106  } );
107  return true;
108 }
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.
SetClipCommand::SetClipCommand
SetClipCommand()
Definition: SetClipCommand.cpp:33
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2459
SetClipCommand::ApplyInner
bool ApplyInner(const CommandContext &context, Track *t) override
Definition: SetClipCommand.cpp:79
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
ShuttleGuiBase::TieTextBox
wxTextCtrl * TieTextBox(const TranslatableString &Caption, wxString &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1652
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
WaveTrack::SortedClipArray
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2595
SetClipCommand::mName
wxString mName
Definition: SetClipCommand.h:41
kColours
kColours
Definition: SetClipCommand.cpp:38
WaveClip
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:175
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:34
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
SetClipCommand::bHasName
bool bHasName
Definition: SetClipCommand.h:47
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
WaveClip::SetName
void SetName(const wxString &name)
Definition: WaveClip.cpp:1759
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
WaveClip::SetColourIndex
void SetColourIndex(int index)
Definition: WaveClip.h:220
WaveClip::GetPlayEndTime
double GetPlayEndTime() const
Definition: WaveClip.cpp:1800
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:2522
SetClipCommand::bHasContainsTime
bool bHasContainsTime
Definition: SetClipCommand.h:44
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:709
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:46
nColours
@ nColours
Definition: SetClipCommand.cpp:43
SetClipCommand::bHasColour
bool bHasColour
Definition: SetClipCommand.h:45
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
WaveClip::SetPlayStartTime
void SetPlayStartTime(double time)
Definition: WaveClip.cpp:1795
WaveClip::GetPlayStartTime
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:1790
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