mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-21 14:02:57 +02:00
Add envelope commands
- Added SetEnvelope (which can also delete/clear an envelope.) - Added GetInfo: Type=Envelope
This commit is contained in:
committed by
Paul Licameli
parent
5d36890cb0
commit
edf90d6e2c
@@ -294,6 +294,7 @@ bool CommandImplementation::Apply(const CommandContext & WXUNUSED(context))
|
||||
#include "SetClipCommand.cpp"
|
||||
#include "SetLabelCommand.cpp"
|
||||
#include "SetProjectCommand.cpp"
|
||||
#include "SetEnvelopeCommand.cpp"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@@ -118,6 +118,16 @@ void CommandContext::EndStruct() const
|
||||
if( pOutput )
|
||||
pOutput->EndStruct();
|
||||
}
|
||||
void CommandContext::StartField(const wxString &name) const
|
||||
{
|
||||
if( pOutput )
|
||||
pOutput->StartField(name);
|
||||
}
|
||||
void CommandContext::EndField() const
|
||||
{
|
||||
if( pOutput )
|
||||
pOutput->EndField();
|
||||
}
|
||||
void CommandContext::AddItem(const wxString &value , const wxString &name ) const
|
||||
{
|
||||
if( pOutput )
|
||||
|
@@ -44,6 +44,8 @@ public:
|
||||
void EndArray() const;
|
||||
void StartStruct() const;
|
||||
void EndStruct() const;
|
||||
void StartField(const wxString &name) const;
|
||||
void EndField() const;
|
||||
void AddItem(const wxString &value , const wxString &name="" ) const;
|
||||
void AddBool(const bool value , const wxString &name="" ) const;
|
||||
void AddItem(const double value , const wxString &name="" ) const;
|
||||
|
@@ -349,6 +349,16 @@ public:
|
||||
if (mStatusTarget)
|
||||
mStatusTarget->EndStruct();
|
||||
}
|
||||
void StartField(const wxString &name)
|
||||
{
|
||||
if (mStatusTarget)
|
||||
mStatusTarget->StartField(name);
|
||||
}
|
||||
void EndField()
|
||||
{
|
||||
if (mStatusTarget)
|
||||
mStatusTarget->EndField();
|
||||
}
|
||||
void AddItem(const wxString &value , const wxString &name="" )
|
||||
{
|
||||
if (mStatusTarget)
|
||||
|
@@ -27,15 +27,15 @@ This class now lists
|
||||
#include "../effects/EffectManager.h"
|
||||
#include "../widgets/Overlay.h"
|
||||
#include "../widgets/OverlayPanel.h"
|
||||
#include "../Track.h"
|
||||
#include "../TrackPanel.h"
|
||||
#include "../Track.h"
|
||||
#include "../WaveTrack.h"
|
||||
#include "../LabelTrack.h"
|
||||
#include "../Envelope.h"
|
||||
#include "CommandContext.h"
|
||||
|
||||
#include "SelectCommand.h"
|
||||
#include "../Project.h"
|
||||
#include "../Track.h"
|
||||
#include "../LabelTrack.h"
|
||||
#include "../ShuttleGui.h"
|
||||
#include "CommandContext.h"
|
||||
|
||||
@@ -45,6 +45,7 @@ enum {
|
||||
kMenus,
|
||||
kTracks,
|
||||
kClips,
|
||||
kEnvelopes,
|
||||
kLabels,
|
||||
kBoxes,
|
||||
nTypes
|
||||
@@ -57,6 +58,7 @@ static const wxString kTypes[nTypes] =
|
||||
XO("Menus"),
|
||||
XO("Tracks"),
|
||||
XO("Clips"),
|
||||
XO("Envelopes"),
|
||||
XO("Labels"),
|
||||
XO("Boxes")
|
||||
};
|
||||
@@ -133,6 +135,7 @@ bool GetInfoCommand::ApplyInner(const CommandContext &context)
|
||||
case kMenus : return SendMenus( context );
|
||||
case kTracks : return SendTracks( context );
|
||||
case kClips : return SendClips( context );
|
||||
case kEnvelopes : return SendEnvelopes( context );
|
||||
case kLabels : return SendLabels( context );
|
||||
case kBoxes : return SendBoxes( context );
|
||||
default:
|
||||
@@ -277,6 +280,50 @@ bool GetInfoCommand::SendClips(const CommandContext &context)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetInfoCommand::SendEnvelopes(const CommandContext &context)
|
||||
{
|
||||
TrackList *tracks = context.GetProject()->GetTracks();
|
||||
TrackListIterator iter(tracks);
|
||||
Track *t = iter.First();
|
||||
int i=0;
|
||||
int j=0;
|
||||
context.StartArray();
|
||||
while (t) {
|
||||
if (t->GetKind() == Track::Wave) {
|
||||
WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
|
||||
WaveClipPointers ptrs( waveTrack->SortedClipArray());
|
||||
for(WaveClip * pClip : ptrs ) {
|
||||
context.StartStruct();
|
||||
context.AddItem( (double)i, "track" );
|
||||
context.AddItem( (double)j, "clip" );
|
||||
context.AddItem( pClip->GetStartTime(), "start" );
|
||||
Envelope * pEnv = pClip->GetEnvelope();
|
||||
context.StartField( "points" );
|
||||
context.StartArray();
|
||||
double offset = pEnv->mOffset;
|
||||
for( int k=0;k<pEnv->mEnv.size(); k++)
|
||||
{
|
||||
context.StartStruct( );
|
||||
context.AddItem( pEnv->mEnv[k].GetT()+offset, "t" );
|
||||
context.AddItem( pEnv->mEnv[k].GetVal(), "y" );
|
||||
context.EndStruct();
|
||||
}
|
||||
context.EndArray();
|
||||
context.EndField();
|
||||
context.AddItem( pClip->GetEndTime(), "end" );
|
||||
context.EndStruct();
|
||||
j++;
|
||||
}
|
||||
}
|
||||
t = iter.Next();
|
||||
i++;
|
||||
}
|
||||
context.EndArray();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool GetInfoCommand::SendLabels(const CommandContext &context)
|
||||
{
|
||||
TrackList *tracks = context.GetProject()->GetTracks();
|
||||
|
@@ -52,6 +52,7 @@ private:
|
||||
bool SendTracks(const CommandContext & context);
|
||||
bool SendLabels(const CommandContext & context);
|
||||
bool SendClips(const CommandContext & context);
|
||||
bool SendEnvelopes(const CommandContext & context);
|
||||
bool SendBoxes(const CommandContext & context);
|
||||
|
||||
void ExploreMenu( const CommandContext &context, wxMenu * pMenu, int Id, int depth );
|
||||
|
@@ -33,6 +33,7 @@ modelled on BuiltinEffectsModule
|
||||
#include "../commands/ImportExportCommands.h"
|
||||
#include "../commands/OpenSaveCommands.h"
|
||||
#include "../commands/SetLabelCommand.h"
|
||||
#include "../commands/SetEnvelopeCommand.h"
|
||||
#include "../commands/SetClipCommand.h"
|
||||
#include "../commands/SetProjectCommand.h"
|
||||
|
||||
@@ -45,6 +46,7 @@ modelled on BuiltinEffectsModule
|
||||
COMMAND( SCREENSHOT, ScreenshotCommand, () ) \
|
||||
COMMAND( COMPARE_AUDIO, CompareAudioCommand, () ) \
|
||||
COMMAND( SET_TRACK, SetTrackCommand, () ) \
|
||||
COMMAND( SET_ENVELOPE, SetEnvelopeCommand, () ) \
|
||||
COMMAND( SET_CLIP, SetClipCommand, () ) \
|
||||
COMMAND( SET_LABEL, SetLabelCommand, () ) \
|
||||
COMMAND( SET_PROJECT, SetProjectCommand, () ) \
|
||||
|
104
src/commands/SetEnvelopeCommand.cpp
Normal file
104
src/commands/SetEnvelopeCommand.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/**********************************************************************
|
||||
|
||||
Audacity - A Digital Audio Editor
|
||||
Copyright 1999-2009 Audacity Team
|
||||
License: wxwidgets
|
||||
|
||||
James Crook
|
||||
|
||||
******************************************************************//**
|
||||
|
||||
\file SetEnvelopeCommand.cpp
|
||||
\brief Definitions for SetEnvelopeCommand
|
||||
|
||||
\class SetEnvelopeCommand
|
||||
\brief Command that sets envelope information
|
||||
|
||||
*//*******************************************************************/
|
||||
|
||||
#include "../Audacity.h"
|
||||
#include "SetEnvelopeCommand.h"
|
||||
#include "../Project.h"
|
||||
#include "../Track.h"
|
||||
#include "../TrackPanel.h"
|
||||
#include "../WaveTrack.h"
|
||||
#include "../Envelope.h"
|
||||
#include "../ShuttleGui.h"
|
||||
#include "CommandContext.h"
|
||||
|
||||
SetEnvelopeCommand::SetEnvelopeCommand()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool SetEnvelopeCommand::DefineParams( ShuttleParams & S ){
|
||||
S.Define( mTrackIndex, wxT("Track"), 0, 0, 100 );
|
||||
S.Define( mT, wxT("Time"), 0.0, 0.0, 100000.0);
|
||||
S.Define( mV, wxT("Value"), 0.0, 0.0, 2.0);
|
||||
S.Define( mbDelete, wxT("Delete"), false );
|
||||
return true;
|
||||
};
|
||||
|
||||
void SetEnvelopeCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
S.StartMultiColumn(2, wxALIGN_CENTER);
|
||||
{
|
||||
S.TieNumericTextBox( _("Track Index:"), mTrackIndex );
|
||||
S.TieNumericTextBox( _("Time:"), mT );
|
||||
S.TieNumericTextBox( _("Value:"), mV );
|
||||
S.TieCheckBox( _("Delete:"), mbDelete );
|
||||
}
|
||||
S.EndMultiColumn();
|
||||
}
|
||||
|
||||
bool SetEnvelopeCommand::Apply(const CommandContext & context)
|
||||
{
|
||||
// \todo we have similar code for finding the nth Label, Clip, Track etc.
|
||||
// this code could be put in subroutines/reduced.
|
||||
|
||||
TrackList *tracks = context.GetProject()->GetTracks();
|
||||
TrackListIterator iter(tracks);
|
||||
Track *t = iter.First();
|
||||
WaveClip * pClip = NULL;
|
||||
int i=0;
|
||||
|
||||
bool bFound = false;
|
||||
|
||||
while (t && !bFound) {
|
||||
if (t->GetKind() == Track::Wave) {
|
||||
WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
|
||||
WaveClipPointers ptrs( waveTrack->SortedClipArray());
|
||||
for(auto it = ptrs.begin(); (it != ptrs.end()) && !bFound; it++,i++ ){
|
||||
pClip = *it;
|
||||
bFound =
|
||||
( pClip->GetStartTime() <= mT ) &&
|
||||
( pClip->GetEndTime() >= mT );
|
||||
}
|
||||
}
|
||||
t = iter.Next();
|
||||
}
|
||||
if( !bFound )
|
||||
return false;
|
||||
Envelope* pEnv = pClip->GetEnvelope();
|
||||
if( mbDelete ){
|
||||
pEnv->mEnv.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
pEnv->InsertOrReplace( mT, mV );
|
||||
/*
|
||||
double tFind = mT - 0.000001 - pEnv->mOffset; // 100,000th of a second before.
|
||||
|
||||
bFound = false;
|
||||
for( i=0;i<pEnv->mEnv.size() && !bFound;i++ ){
|
||||
bFound = tFind > pEnv->mEnv[i].GetT();
|
||||
}
|
||||
i -= bFound ? 1 :0;
|
||||
|
||||
pEnv->Insert( i, EnvPoint( mT, mV ) );
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
47
src/commands/SetEnvelopeCommand.h
Normal file
47
src/commands/SetEnvelopeCommand.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/**********************************************************************
|
||||
|
||||
Audacity - A Digital Audio Editor
|
||||
Copyright 1999-2009 Audacity Team
|
||||
License: wxwidgets
|
||||
|
||||
James Crook
|
||||
|
||||
******************************************************************//**
|
||||
|
||||
\file SetEnvelopeCommand.h
|
||||
\brief Declarations of SetEnvelopeCommand class
|
||||
|
||||
*//*******************************************************************/
|
||||
|
||||
#ifndef __SET_ENVELOPE_COMMAND__
|
||||
#define __SET_ENVELOPE_COMMAND__
|
||||
|
||||
#include "Command.h"
|
||||
#include "CommandType.h"
|
||||
|
||||
#define SET_ENVELOPE_PLUGIN_SYMBOL XO("Set Envelope")
|
||||
|
||||
class SetEnvelopeCommand : public AudacityCommand
|
||||
{
|
||||
public:
|
||||
SetEnvelopeCommand();
|
||||
// CommandDefinitionInterface overrides
|
||||
wxString GetSymbol() override {return SET_ENVELOPE_PLUGIN_SYMBOL;};
|
||||
wxString GetDescription() override {return _("Sets an envelope point position.");};
|
||||
bool DefineParams( ShuttleParams & S ) override;
|
||||
void PopulateOrExchange(ShuttleGui & S) override;
|
||||
|
||||
// AudacityCommand overrides
|
||||
wxString ManualPage() override {return wxT("Extra_Menu:_Tools#set_label");};
|
||||
|
||||
bool Apply(const CommandContext & context) override;
|
||||
|
||||
public:
|
||||
int mTrackIndex;
|
||||
double mT;
|
||||
double mV;
|
||||
bool mbDelete;
|
||||
};
|
||||
|
||||
|
||||
#endif /* End of include guard: __SETTRACKINFOCOMMAND__ */
|
Reference in New Issue
Block a user