Audacity 3.2.0
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{
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
55template<bool Const>
57 S.OptionalY( bHasContainsTime ).Define( mContainsTime, wxT("At"), 0.0, 0.0, 100000.0 );
58 S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
59 // Allowing a negative start time is not a mistake.
60 // It will be used in demonstrating time before zero.
61 S.OptionalN( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -5.0, 1000000.0);
62 return true;
63};
65 { return VisitSettings<false>(S); }
66
68 { return VisitSettings<true>(S); }
69
71{
72 S.AddSpace(0, 5);
73
74 S.StartMultiColumn(3, wxALIGN_CENTER);
75 {
76 S.Optional( bHasContainsTime).TieNumericTextBox( XXO("At:"), mContainsTime );
77 S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
79 S.Optional( bHasT0 ).TieNumericTextBox( XXO("Start:"), mT0 );
80 S.Optional( bHasName ).TieTextBox( XXO("Name:"), mName );
81 }
82 S.EndMultiColumn();
83}
84
86{
87 // if no 'At' is specified, then any clip in any selected track will be set.
88 t->TypeSwitch([&](WaveTrack *waveTrack) {
89 WaveClipPointers ptrs( waveTrack->SortedClipArray());
90 for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
91 WaveClip * pClip = *it;
92 bool bFound =
94 ( pClip->GetPlayStartTime() <= mContainsTime ) &&
95 ( pClip->GetPlayEndTime() >= mContainsTime )
96 );
97 if( bFound )
98 {
99 // Inside this IF is where we actually apply the command
100
101 if( bHasColour )
102 pClip->SetColourIndex(mColour);
103 // No validation of overlap yet. We assume the user is sensible!
104 if( bHasT0 )
105 pClip->SetPlayStartTime(mT0);
106 // \todo Use SetClip to move a clip between tracks too.
107 if( bHasName )
108 pClip->SetName(mName);
109
110 }
111 }
112 } );
113 return true;
114}
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
kColours
@ kColour0
@ nColours
@ kColour1
@ kColour3
@ kColour2
static const EnumValueSymbol kColourStrings[nColours]
Declarations of SetClipCommand and SetClipCommandType classes.
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
std::vector< WaveClip * > WaveClipPointers
Definition: WaveTrack.h:46
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
static const ComponentInterfaceSymbol Symbol
bool ApplyInner(const CommandContext &context, Track *t) override
double mContainsTime
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:631
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
Definition: Track.h:824
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101
void SetPlayStartTime(double time)
Definition: WaveClip.cpp:903
void SetName(const wxString &name)
Definition: WaveClip.cpp:867
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:898
void SetColourIndex(int index)
Definition: WaveClip.h:148
double GetPlayEndTime() const
Definition: WaveClip.cpp:908
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2723
BuiltinCommandsModule::Registration< SetClipCommand > reg