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 "LoadCommands.h"
23 #include "../WaveClip.h"
24 #include "../WaveTrack.h"
25 #include "../Envelope.h"
26 #include "../Shuttle.h"
27 #include "../ShuttleGui.h"
28 
30 { XO("Set Envelope") };
31 
33 
34 
36 {
37 }
38 
39 
41  S.OptionalY( bHasT ).Define( mT, wxT("Time"), 0.0, 0.0, 100000.0);
42  S.OptionalY( bHasV ).Define( mV, wxT("Value"), 1.0, 0.0, 2.0);
43  S.OptionalN( bHasDelete ).Define( mbDelete, wxT("Delete"), false );
44  return true;
45 };
46 
48 {
49  S.AddSpace(0, 5);
50 
51  S.StartMultiColumn(3, wxALIGN_CENTER);
52  {
53  S.Optional( bHasT ).TieNumericTextBox( XXO("Time:"), mT );
54  S.Optional( bHasV ).TieNumericTextBox( XXO("Value:"), mV );
55  S.Optional( bHasDelete ).TieCheckBox( XXO("Delete"), mbDelete );
56  }
57  S.EndMultiColumn();
58 }
59 
61 {
62  // if no time is specified, then
63  // - delete deletes any envelope in selected tracks.
64  // - value is not set for any clip
65  t->TypeSwitch([&](WaveTrack *waveTrack) {
66  WaveClipPointers ptrs( waveTrack->SortedClipArray());
67  for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
68  WaveClip * pClip = *it;
69  bool bFound =
70  !bHasT || (
71  ( pClip->GetStartTime() <= mT) &&
72  ( pClip->GetEndTime() >= mT )
73  );
74  if( bFound )
75  {
76  // Inside this IF is where we actually apply the command
77  Envelope* pEnv = pClip->GetEnvelope();
78  if( bHasDelete && mbDelete )
79  pEnv->Clear();
80  if( bHasT && bHasV )
81  pEnv->InsertOrReplace( mT, pEnv->ClampValue( mV ) );
82  }
83  }
84  } );
85 
86  return true;
87 }
SetEnvelopeCommand::bHasDelete
bool bHasDelete
Definition: SetEnvelopeCommand.h:44
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:68
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:242
ShuttleGuiBase::TieCheckBox
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
Definition: ShuttleGui.cpp:1603
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:2421
WaveClip::GetEndTime
double GetEndTime() const
Definition: WaveClip.cpp:253
XO
#define XO(s)
Definition: Internat.h:32
Envelope::ClampValue
double ClampValue(double value)
Definition: Envelope.h:110
anonymous_namespace{SetEnvelopeCommand.cpp}::reg
BuiltinCommandsModule::Registration< SetEnvelopeCommand > reg
Definition: SetEnvelopeCommand.cpp:32
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:61
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1212
WaveClipPointers
std::vector< WaveClip * > WaveClipPointers
Definition: WaveTrack.h:40
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:71
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
WaveTrack::SortedClipArray
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2502
WaveClip::GetStartTime
double GetStartTime() const
Definition: WaveClip.cpp:247
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:172
XXO
#define XXO(s)
Definition: Internat.h:45
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:22
SetEnvelopeCommand::mT
double mT
Definition: SetEnvelopeCommand.h:38
SetEnvelopeCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: SetEnvelopeCommand.cpp:40
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1203
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:70
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
ShuttleGuiBase::TieNumericTextBox
wxTextCtrl * TieNumericTextBox(const TranslatableString &Prompt, int &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1647
Track::TypeSwitch
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
Definition: Track.h:692
SetEnvelopeCommand::SetEnvelopeCommand
SetEnvelopeCommand()
Definition: SetEnvelopeCommand.cpp:35
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:238
SetEnvelopeCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: SetEnvelopeCommand.cpp:47
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:2254
SetEnvelopeCommand::ApplyInner
bool ApplyInner(const CommandContext &context, Track *t) override
Definition: SetEnvelopeCommand.cpp:60
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638
SetEnvelopeCommand::bHasV
bool bHasV
Definition: SetEnvelopeCommand.h:43