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 "CommandDispatch.h"
23#include "CommandManager.h"
24#include "../CommonCommandFlags.h"
25#include "LoadCommands.h"
26#include "WaveClip.h"
27#include "WaveTrack.h"
28#include "SettingsVisitor.h"
29#include "ShuttleGui.h"
30
32{ XO("Set Clip") };
33
35
37{
38}
39
41{
47};
48
50{
51 { wxT("Color0"), XO("Color 0") },
52 { wxT("Color1"), XO("Color 1") },
53 { wxT("Color2"), XO("Color 2") },
54 { wxT("Color3"), XO("Color 3") },
55};
56
57
58template<bool Const>
60 S.OptionalY( bHasContainsTime ).Define( mContainsTime, wxT("At"), 0.0, 0.0, 100000.0 );
61 S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
62 // Allowing a negative start time is not a mistake.
63 // It will be used in demonstrating time before zero.
64 S.OptionalN( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -5.0, 1000000.0);
65 return true;
66};
68 { return VisitSettings<false>(S); }
69
71 { return VisitSettings<true>(S); }
72
74{
75 S.AddSpace(0, 5);
76
77 S.StartMultiColumn(3, wxALIGN_CENTER);
78 {
79 S.Optional( bHasContainsTime).TieNumericTextBox( XXO("At:"), mContainsTime );
80 S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
82 S.Optional( bHasT0 ).TieNumericTextBox( XXO("Start:"), mT0 );
83 S.Optional( bHasName ).TieTextBox( XXO("Name:"), mName );
84 }
85 S.EndMultiColumn();
86}
87
89{
90 // if no 'At' is specified, then any clip in any selected track will be set.
91 t->TypeSwitch([&](WaveTrack *waveTrack) {
92 WaveClipPointers ptrs( waveTrack->SortedClipArray());
93 for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
94 WaveClip * pClip = *it;
95 bool bFound =
97 ( pClip->GetPlayStartTime() <= mContainsTime ) &&
98 ( pClip->GetPlayEndTime() >= mContainsTime )
99 );
100 if( bFound )
101 {
102 // Inside this IF is where we actually apply the command
103
104 if( bHasColour )
105 pClip->SetColourIndex(mColour);
106 // No validation of overlap yet. We assume the user is sensible!
107 if( bHasT0 )
108 pClip->SetPlayStartTime(mT0);
109 // \todo Use SetClip to move a clip between tracks too.
110 if( bHasName )
111 pClip->SetName(mName);
112
113 }
114 }
115 } );
116 return true;
117}
118
119namespace {
120using namespace MenuTable;
121
122// Register menu items
123
125 wxT("Optional/Extra/Part2/Scriptables1"),
126 // Note that the PLUGIN_SYMBOL must have a space between words,
127 // whereas the short-form used here must not.
128 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
129 // you would have to use "CompareAudio" here.)
130 Command( wxT("SetClip"), XXO("Set Clip..."),
132};
133}
wxT("CloseDown"))
AttachedItem sAttachment1
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
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:40
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 ...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:226
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
Definition: Track.h:833
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101
void SetPlayStartTime(double time)
Definition: WaveClip.cpp:884
void SetName(const wxString &name)
Definition: WaveClip.cpp:848
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:879
void SetColourIndex(int index)
Definition: WaveClip.h:149
double GetPlayEndTime() const
Definition: WaveClip.cpp:889
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2459
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
BuiltinCommandsModule::Registration< SetClipCommand > reg