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 "LoadCommands.h"
24#include "ProjectHistory.h"
25#include "UndoManager.h"
26#include "../WaveClip.h"
27#include "../WaveTrack.h"
28#include "Envelope.h"
29#include "../Shuttle.h"
30#include "../ShuttleGui.h"
31
33{ XO("Set Envelope") };
34
36
37
39{
40}
41
42template<bool Const>
44 S.OptionalY( bHasT ).Define( mT, wxT("Time"), 0.0, 0.0, 100000.0);
45 S.OptionalY( bHasV ).Define( mV, wxT("Value"), 1.0, 0.0, 2.0);
46 S.OptionalN( bHasDelete ).Define( mbDelete, wxT("Delete"), false );
47 return true;
48};
49
51 { return VisitSettings<false>(S); }
52
54 { return VisitSettings<true>(S); }
55
57{
58 S.AddSpace(0, 5);
59
60 S.StartMultiColumn(3, wxALIGN_CENTER);
61 {
62 S.Optional( bHasT ).TieNumericTextBox( XXO("Time:"), mT );
63 S.Optional( bHasV ).TieNumericTextBox( XXO("Value:"), mV );
64 S.Optional( bHasDelete ).TieCheckBox( XXO("Delete"), mbDelete );
65 }
66 S.EndMultiColumn();
67}
68
70{
71 // if no time is specified, then
72 // - delete deletes any envelope in selected tracks.
73 // - value is not set for any clip
74 t->TypeSwitch([&](WaveTrack *waveTrack) {
75 WaveClipPointers ptrs( waveTrack->SortedClipArray());
76 for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
77 WaveClip * pClip = *it;
78 bool bFound =
79 !bHasT || (
80 ( pClip->GetPlayStartTime() <= mT) &&
81 ( pClip->GetPlayEndTime() >= mT )
82 );
83 if( bFound )
84 {
85 // Inside this IF is where we actually apply the command
86 Envelope* pEnv = pClip->GetEnvelope();
87 bool didSomething = false;
88 if( bHasDelete && mbDelete )
89 pEnv->Clear(), didSomething = true;
90 if( bHasT && bHasV )
91 pEnv->InsertOrReplace( mT, pEnv->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
98 XO("Edited Envelope"), XO("Envelope"),
100 }
101 }
102 } );
103
104 return true;
105}
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
Declarations of SetEnvelopeCommand class.
#define S(N)
Definition: ToChars.cpp:64
std::vector< WaveClip * > WaveClipPointers
Definition: WaveTrack.h:46
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:170
int InsertOrReplace(double when, double value)
Add a point at a particular absolute time coordinate.
Definition: Envelope.h:173
double ClampValue(double value)
Definition: Envelope.h:102
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 ...
Definition: Shuttle.h:115
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
Definition: Track.h:832
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:898
double GetPlayEndTime() const
Definition: WaveClip.cpp:908
Envelope * GetEnvelope()
Definition: WaveClip.h:205
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2723
BuiltinCommandsModule::Registration< SetEnvelopeCommand > reg