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 "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 for(const auto track : TrackList::Get(context.project))
91 {
92 if(!track->GetSelected())
93 continue;
94
95 // if no 'At' is specified, then any clip in any selected track will be set.
96 track->TypeSwitch([&](WaveTrack &waveTrack) {
97 for(const auto& interval : waveTrack.Intervals())
98 {
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 interval->SetColorIndex(mColour);
106 // No validation of overlap yet. We assume the user is sensible!
107 if( bHasT0 )
108 interval->SetPlayStartTime(mT0);
109 // \todo Use SetClip to move a clip between tracks too.
110 if( bHasName )
111 interval->SetName(mName);
112 }
113 }
114 } );
115 }
116 return true;
117}
118
119namespace {
120using namespace MenuRegistry;
121
122// Register menu items
123
125 // Note that the PLUGIN_SYMBOL must have a space between words,
126 // whereas the short-form used here must not.
127 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
128 // you would have to use "CompareAudio" here.)
129 Command( wxT("SetClip"), XXO("Set Clip..."),
131 wxT("Optional/Extra/Part2/Scriptables1")
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
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:630
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
auto Intervals()
Definition: WaveTrack.h:1029
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< SetClipCommand > reg