Audacity  3.0.3
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 
42 
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 {
52  S.AddSpace(0, 5);
53 
54  S.StartMultiColumn(3, wxALIGN_CENTER);
55  {
56  S.Optional( bHasT ).TieNumericTextBox( XXO("Time:"), mT );
57  S.Optional( bHasV ).TieNumericTextBox( XXO("Value:"), mV );
58  S.Optional( bHasDelete ).TieCheckBox( XXO("Delete"), mbDelete );
59  }
60  S.EndMultiColumn();
61 }
62 
64 {
65  // if no time is specified, then
66  // - delete deletes any envelope in selected tracks.
67  // - value is not set for any clip
68  t->TypeSwitch([&](WaveTrack *waveTrack) {
69  WaveClipPointers ptrs( waveTrack->SortedClipArray());
70  for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
71  WaveClip * pClip = *it;
72  bool bFound =
73  !bHasT || (
74  ( pClip->GetPlayStartTime() <= mT) &&
75  ( pClip->GetPlayEndTime() >= mT )
76  );
77  if( bFound )
78  {
79  // Inside this IF is where we actually apply the command
80  Envelope* pEnv = pClip->GetEnvelope();
81  bool didSomething = false;
82  if( bHasDelete && mbDelete )
83  pEnv->Clear(), didSomething = true;
84  if( bHasT && bHasV )
85  pEnv->InsertOrReplace( mT, pEnv->ClampValue( mV ) ),
86  didSomething = true;
87 
88  if (didSomething)
89  // Consolidate, because this ApplyInner() function may be
90  // visited multiple times in one command invocation
92  XO("Edited Envelope"), XO("Envelope"),
94  }
95  }
96  } );
97 
98  return true;
99 }
SetEnvelopeCommand::bHasDelete
bool bHasDelete
Definition: SetEnvelopeCommand.h:44
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
LoadCommands.h
SetEnvelopeCommand::mV
double mV
Definition: SetEnvelopeCommand.h:39
SetEnvelopeCommand::mbDelete
bool mbDelete
Definition: SetEnvelopeCommand.h:40
WaveClip::GetEnvelope
Envelope * GetEnvelope()
Definition: WaveClip.h:277
ShuttleGuiBase::TieCheckBox
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
Definition: ShuttleGui.cpp:1629
Envelope
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:71
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2459
XO
#define XO(s)
Definition: Internat.h:31
Envelope::ClampValue
double ClampValue(double value)
Definition: Envelope.h:110
anonymous_namespace{SetEnvelopeCommand.cpp}::reg
BuiltinCommandsModule::Registration< SetEnvelopeCommand > reg
Definition: SetEnvelopeCommand.cpp:35
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
WaveClipPointers
std::vector< WaveClip * > WaveClipPointers
Definition: WaveTrack.h:41
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
WaveTrack::SortedClipArray
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2595
SetEnvelopeCommand.h
Declarations of SetEnvelopeCommand class.
SetEnvelopeCommand::bHasT
bool bHasT
Definition: SetEnvelopeCommand.h:42
WaveClip
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:175
CommandContext.h
XXO
#define XXO(s)
Definition: Internat.h:44
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
SetEnvelopeCommand::mT
double mT
Definition: SetEnvelopeCommand.h:38
SetEnvelopeCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: SetEnvelopeCommand.cpp:43
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
Envelope::InsertOrReplace
int InsertOrReplace(double when, double value)
Add a point at a particular absolute time coordinate.
Definition: Envelope.h:181
Envelope::Clear
void Clear()
Definition: Envelope.h:178
WaveClip::GetPlayEndTime
double GetPlayEndTime() const
Definition: WaveClip.cpp:1800
ShuttleGuiBase::TieNumericTextBox
wxTextCtrl * TieNumericTextBox(const TranslatableString &Prompt, int &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1673
ProjectHistory::PushState
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
Definition: ProjectHistory.cpp:90
Track::TypeSwitch
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
Definition: Track.h:709
SetEnvelopeCommand::SetEnvelopeCommand
SetEnvelopeCommand()
Definition: SetEnvelopeCommand.cpp:38
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
SetEnvelopeCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: SetEnvelopeCommand.cpp:50
UndoPush::CONSOLIDATE
@ CONSOLIDATE
SetEnvelopeCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: SetEnvelopeCommand.h:24
ShuttleParams::Define
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:332
ShuttleGui::Optional
ShuttleGui & Optional(bool &bVar)
Definition: ShuttleGui.cpp:2280
SetEnvelopeCommand::ApplyInner
bool ApplyInner(const CommandContext &context, Track *t) override
Definition: SetEnvelopeCommand.cpp:63
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:64
WaveClip::GetPlayStartTime
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:1790
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
SetEnvelopeCommand::bHasV
bool bHasV
Definition: SetEnvelopeCommand.h:43