Audacity  2.3.1
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 #include "../Audacity.h"
20 #include "SetEnvelopeCommand.h"
21 #include "../Project.h"
22 #include "../Track.h"
23 #include "../TrackPanel.h"
24 #include "../WaveTrack.h"
25 #include "../Envelope.h"
26 #include "../ShuttleGui.h"
27 #include "CommandContext.h"
28 
30 {
31 }
32 
33 
35  S.OptionalY( bHasT ).Define( mT, wxT("Time"), 0.0, 0.0, 100000.0);
36  S.OptionalY( bHasV ).Define( mV, wxT("Value"), 1.0, 0.0, 2.0);
37  S.OptionalN( bHasDelete ).Define( mbDelete, wxT("Delete"), false );
38  return true;
39 };
40 
42 {
43  S.AddSpace(0, 5);
44 
45  S.StartMultiColumn(3, wxALIGN_CENTER);
46  {
47  S.Optional( bHasT ).TieNumericTextBox( _("Time:"), mT );
48  S.Optional( bHasV ).TieNumericTextBox( _("Value:"), mV );
49  S.Optional( bHasDelete ).TieCheckBox( _("Delete:"), mbDelete );
50  }
51  S.EndMultiColumn();
52 }
53 
55 {
56  static_cast<void>(context);
57  // if no time is specified, then
58  // - delete deletes any envelope in selected tracks.
59  // - value is not set for any clip
60  t->TypeSwitch([&](WaveTrack *waveTrack) {
61  WaveClipPointers ptrs( waveTrack->SortedClipArray());
62  for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
63  WaveClip * pClip = *it;
64  bool bFound =
65  !bHasT || (
66  ( pClip->GetStartTime() <= mT) &&
67  ( pClip->GetEndTime() >= mT )
68  );
69  if( bFound )
70  {
71  // Inside this IF is where we actually apply the command
72  Envelope* pEnv = pClip->GetEnvelope();
73  if( bHasDelete && mbDelete )
74  pEnv->mEnv.clear();
75  if( bHasT && bHasV )
76  pEnv->InsertOrReplace( mT, pEnv->ClampValue( mV ) );
77  }
78  }
79  } );
80 
81  return true;
82 }
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
ShuttleGui & Optional(bool &bVar)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
R TypeSwitch(const Functions &...functions)
Definition: Track.h:630
double GetStartTime() const
Definition: WaveClip.cpp:421
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2597
void EndMultiColumn()
Draggable curve used in TrackPanel for varying amplification.
Definition: Envelope.h:77
bool ApplyInner(const CommandContext &context, Track *t) override
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
Envelope * GetEnvelope()
Definition: WaveClip.h:243
void PopulateOrExchange(ShuttleGui &S) override
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
Declarations of SetEnvelopeCommand class.
int InsertOrReplace(double when, double value)
Add a point at a particular absolute time coordinate.
Definition: Envelope.h:196
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:176
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:191
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:338
wxTextCtrl * TieNumericTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
double ClampValue(double value)
Definition: Envelope.h:107
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxCheckBox * TieCheckBox(const wxString &Prompt, WrappedType &WrappedRef)
double GetEndTime() const
Definition: WaveClip.cpp:427
std::vector< WaveClip * > WaveClipPointers
Definition: WaveClip.h:126
wxSizerItem * AddSpace(int width, int height)
EnvArray mEnv
Definition: Envelope.h:254
bool DefineParams(ShuttleParams &S) override