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 "MenuRegistry.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 for (const auto pClip : waveTrack.SortedIntervalArray()) {
79 bool bFound =
80 !bHasT || (
81 (pClip->GetPlayStartTime() <= mT) &&
82 (pClip->GetPlayEndTime() >= mT)
83 );
84 if (bFound) {
85 // Inside this IF is where we actually apply the command
86 auto &env = pClip->GetEnvelope();
87 bool didSomething = false;
88 if (bHasDelete && mbDelete)
89 env.Clear(), didSomething = true;
90 if (bHasT && bHasV)
91 env.InsertOrReplace(mT, env.ClampValue(mV)),
92 didSomething = true;
93
94 if (didSomething)
95 // Consolidate, because this ApplyInner() function may be
96 // visited multiple times in one command invocation
97 ProjectHistory::Get(context.project).PushState(
98 XO("Edited Envelope"), XO("Envelope"),
99 UndoPush::CONSOLIDATE);
100 }
101 }
102 } );
103
104
105 return true;
106}
107
108namespace {
109using namespace MenuRegistry;
110
111// Register menu items
112
114 // Note that the PLUGIN_SYMBOL must have a space between words,
115 // whereas the short-form used here must not.
116 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
117 // you would have to use "CompareAudio" here.)
118 Command( wxT("SetEnvelope"), XXO("Set Envelope..."),
120 wxT("Optional/Extra/Part2/Scriptables1")
121};
122}
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
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Generates classes whose instances register items at construction.
Definition: Registry.h:388
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:640
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
R TypeSwitch(const Functions &...functions)
Definition: Track.h:381
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
IntervalHolders SortedIntervalArray()
Return all WaveClips sorted by clip play start time.
Definition: WaveTrack.cpp:3270
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< SetEnvelopeCommand > reg