Audacity 3.2.0
SetEnvelopeCommand.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 "SetEnvelopeCommand.h"
21
22#include "CommandContext.h"
23#include "CommandDispatch.h"
24#include "CommandManager.h"
25#include "../CommonCommandFlags.h"
26#include "LoadCommands.h"
27#include "ProjectHistory.h"
28#include "UndoManager.h"
29#include "WaveClip.h"
30#include "WaveTrack.h"
31#include "Envelope.h"
32#include "SettingsVisitor.h"
33#include "ShuttleGui.h"
34
36{ XO("Set Envelope") };
37
39
40
42{
43}
44
45template<bool Const>
47 S.OptionalY( bHasT ).Define( mT, wxT("Time"), 0.0, 0.0, 100000.0);
48 S.OptionalY( bHasV ).Define( mV, wxT("Value"), 1.0, 0.0, 2.0);
49 S.OptionalN( bHasDelete ).Define( mbDelete, wxT("Delete"), false );
50 return true;
51};
52
54 { return VisitSettings<false>(S); }
55
57 { return VisitSettings<true>(S); }
58
60{
61 S.AddSpace(0, 5);
62
63 S.StartMultiColumn(3, wxALIGN_CENTER);
64 {
65 S.Optional( bHasT ).TieNumericTextBox( XXO("Time:"), mT );
66 S.Optional( bHasV ).TieNumericTextBox( XXO("Value:"), mV );
67 S.Optional( bHasDelete ).TieCheckBox( XXO("Delete"), mbDelete );
68 }
69 S.EndMultiColumn();
70}
71
73{
74 // if no time is specified, then
75 // - delete deletes any envelope in selected tracks.
76 // - value is not set for any clip
77 t->TypeSwitch([&](WaveTrack *waveTrack) {
78 WaveClipPointers ptrs( waveTrack->SortedClipArray());
79 for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
80 WaveClip * pClip = *it;
81 bool bFound =
82 !bHasT || (
83 ( pClip->GetPlayStartTime() <= mT) &&
84 ( pClip->GetPlayEndTime() >= mT )
85 );
86 if( bFound )
87 {
88 // Inside this IF is where we actually apply the command
89 Envelope* pEnv = pClip->GetEnvelope();
90 bool didSomething = false;
91 if( bHasDelete && mbDelete )
92 pEnv->Clear(), didSomething = true;
93 if( bHasT && bHasV )
94 pEnv->InsertOrReplace( mT, pEnv->ClampValue( mV ) ),
95 didSomething = true;
96
97 if (didSomething)
98 // Consolidate, because this ApplyInner() function may be
99 // visited multiple times in one command invocation
101 XO("Edited Envelope"), XO("Envelope"),
103 }
104 }
105 } );
106
107 return true;
108}
109
110namespace {
111using namespace MenuTable;
112
113// Register menu items
114
116 wxT("Optional/Extra/Part2/Scriptables1"),
117 // Note that the PLUGIN_SYMBOL must have a space between words,
118 // whereas the short-form used here must not.
119 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
120 // you would have to use "CompareAudio" here.)
121 Command( wxT("SetEnvelope"), XXO("Set Envelope..."),
123};
124}
wxT("CloseDown"))
AttachedItem sAttachment1
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
Declarations of SetEnvelopeCommand class.
#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,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
void Clear()
Definition: Envelope.h:172
int InsertOrReplace(double when, double value)
Add a point at a particular absolute time coordinate.
Definition: Envelope.h:175
double ClampValue(double value)
Definition: Envelope.h:104
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
bool ApplyInner(const CommandContext &context, Track *t) override
static const ComponentInterfaceSymbol Symbol
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
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
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:878
double GetPlayEndTime() const
Definition: WaveClip.cpp:888
Envelope * GetEnvelope()
Definition: WaveClip.h:219
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< SetEnvelopeCommand > reg