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 "CommandContext.h"
23#include "CommandDispatch.h"
24#include "MenuRegistry.h"
25#include "../CommonCommandFlags.h"
26#include "LoadCommands.h"
27#include "../tracks/playabletrack/wavetrack/ui/WaveformAppearance.h"
28#include "WaveTrack.h"
29#include "SettingsVisitor.h"
30#include "ShuttleGui.h"
31
33{ XO("Set Clip") };
34
36
38{
39}
40
42{
48};
49
51{
52 { wxT("Color0"), XO("Color 0") },
53 { wxT("Color1"), XO("Color 1") },
54 { wxT("Color2"), XO("Color 2") },
55 { wxT("Color3"), XO("Color 3") },
56};
57
58
59template<bool Const>
61 S.OptionalY( bHasContainsTime ).Define( mContainsTime, wxT("At"), 0.0, 0.0, 100000.0 );
62 S.OptionalN( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, kColourStrings, nColours );
63 // Allowing a negative start time is not a mistake.
64 // It will be used in demonstrating time before zero.
65 S.OptionalN( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -5.0, 1000000.0);
66 return true;
67};
69 { return VisitSettings<false>(S); }
70
72 { return VisitSettings<true>(S); }
73
75{
76 S.AddSpace(0, 5);
77
78 S.StartMultiColumn(3, wxALIGN_CENTER);
79 {
80 S.Optional( bHasContainsTime).TieNumericTextBox( XXO("At:"), mContainsTime );
81 S.Optional( bHasColour ).TieChoice( XXO("Color:"), mColour,
83 S.Optional( bHasT0 ).TieNumericTextBox( XXO("Start:"), mT0 );
84 S.Optional( bHasName ).TieTextBox( XXO("Name:"), mName );
85 }
86 S.EndMultiColumn();
87}
88
90{
91 for(const auto track : TrackList::Get(context.project))
92 {
93 if(!track->GetSelected())
94 continue;
95
96 // if no 'At' is specified, then any clip in any selected track will be set.
97 track->TypeSwitch([&](WaveTrack &waveTrack) {
98 for (const auto &interval : waveTrack.Intervals()) {
99 if(!bHasContainsTime ||
100 (interval->Start() <= mContainsTime &&
101 interval->End() >= mContainsTime ))
102 {
103 // Inside this IF is where we actually apply the command
104 if (bHasColour) {
105 for (const auto channel : interval->Channels())
106 WaveColorAttachment::Get(*channel).SetColorIndex(mColour);
107 }
108 // No validation of overlap yet. We assume the user is sensible!
109 if( bHasT0 )
110 interval->SetPlayStartTime(mT0);
111 // \todo Use SetClip to move a clip between tracks too.
112 if( bHasName )
113 interval->SetName(mName);
114 }
115 }
116 } );
117 }
118 return true;
119}
120
121namespace {
122using namespace MenuRegistry;
123
124// Register menu items
125
127 // Note that the PLUGIN_SYMBOL must have a space between words,
128 // whereas the short-form used here must not.
129 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
130 // you would have to use "CompareAudio" here.)
131 Command( wxT("SetClip"), XXO("Set Clip..."),
133 wxT("Optional/Extra/Part2/Scriptables1")
134};
135}
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
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Generates classes whose instances register items at construction.
Definition: Registry.h:388
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
static const ComponentInterfaceSymbol Symbol
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:640
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
auto Intervals()
Definition: WaveTrack.h:670
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< SetClipCommand > reg