1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

Use TypeSwitch and track_cast

This commit is contained in:
Paul Licameli
2017-04-11 18:16:03 -04:00
parent fd10ed26cd
commit 51842fc78b
13 changed files with 806 additions and 872 deletions

View File

@@ -248,10 +248,8 @@ bool GetInfoCommand::SendBoxes(const CommandContext &context)
bool GetInfoCommand::SendTracks(const CommandContext & context)
{
TrackList *projTracks = context.GetProject()->GetTracks();
TrackListIterator iter(projTracks);
Track *trk = iter.First();
context.StartArray();
while (trk)
for (auto trk : projTracks->Leaders())
{
TrackPanel *panel = context.GetProject()->GetTrackPanel();
@@ -264,9 +262,7 @@ bool GetInfoCommand::SendTracks(const CommandContext & context)
//JKC: Possibly add these two later...
//context.AddItem( trk->GetKind(), "kind" );
//context.AddItem( trk->GetHeight(), "height" );
auto t = dynamic_cast<WaveTrack*>( trk );
if( t )
{
trk->TypeSwitch( [&] (const WaveTrack* t ) {
context.AddItem( t->GetStartTime(), "start" );
context.AddItem( t->GetEndTime(), "end" );
context.AddItem( t->GetPan() , "pan");
@@ -274,13 +270,8 @@ bool GetInfoCommand::SendTracks(const CommandContext & context)
context.AddItem( t->GetLinked() ? 2:1, "channels");
context.AddBool( t->GetSolo(), "solo" );
context.AddBool( t->GetMute(), "mute");
}
} );
context.EndStruct();
// Skip second tracks of stereo...
if( trk->GetLinked() )
trk= iter.Next();
if( trk )
trk=iter.Next();
}
context.EndArray();
return true;
@@ -368,48 +359,35 @@ bool GetInfoCommand::SendEnvelopes(const CommandContext &context)
bool GetInfoCommand::SendLabels(const CommandContext &context)
{
TrackList *tracks = context.GetProject()->GetTracks();
TrackListIterator iter(tracks);
Track *t = iter.First();
int i=0;
context.StartArray();
while (t) {
if (t->GetKind() == Track::Label) {
LabelTrack *labelTrack = static_cast<LabelTrack*>(t);
if( labelTrack )
{
for (auto t : tracks->Leaders()) {
t->TypeSwitch( [&](LabelTrack *labelTrack) {
#ifdef VERBOSE_LABELS_FORMATTING
for (int nn = 0; nn< (int)labelTrack->mLabels.size(); nn++) {
const auto &label = labelTrack->mLabels[nn];
context.StartStruct();
context.AddItem( (double)i, "track" );
context.AddItem( label.getT0(), "start" );
context.AddItem( label.getT1(), "end" );
context.AddItem( label.title, "text" );
context.EndStruct();
}
#else
context.AddItem( (double)i ); // Track number.
context.StartArray();
for (int nn = 0; nn< (int)labelTrack->mLabels.size(); nn++) {
const auto &label = labelTrack->mLabels[nn];
context.StartArray();
context.AddItem( label.getT0() ); // start
context.AddItem( label.getT1() ); // end
context.AddItem( label.title ); //text.
context.EndArray();
}
context.EndArray();
#endif
for (int nn = 0; nn< (int)labelTrack->mLabels.size(); nn++) {
const auto &label = labelTrack->mLabels[nn];
context.StartStruct();
context.AddItem( (double)i, "track" );
context.AddItem( label.getT0(), "start" );
context.AddItem( label.getT1(), "end" );
context.AddItem( label.title, "text" );
context.EndStruct();
}
}
// Skip second tracks of stereo...
// This has no effect on label tracks themselves, which are never stereo
// but is needed for per track rather than per channel numbering.
if( t->GetLinked() )
t= iter.Next();
if( t )
t=iter.Next();
#else
context.AddItem( (double)i ); // Track number.
context.StartArray();
for (int nn = 0; nn< (int)labelTrack->mLabels.size(); nn++) {
const auto &label = labelTrack->mLabels[nn];
context.StartArray();
context.AddItem( label.getT0() ); // start
context.AddItem( label.getT1() ); // end
context.AddItem( label.title ); //text.
context.EndArray();
}
context.EndArray();
#endif
} );
// Per track numbering counts all tracks
i++;
}
context.EndArray();

View File

@@ -21,6 +21,7 @@
#include "../Project.h"
#include "../Track.h"
#include "../TrackPanel.h"
#include "../NoteTrack.h"
#include "../WaveTrack.h"
#include "../ShuttleGui.h"
#include "CommandContext.h"

View File

@@ -74,33 +74,29 @@ void SetClipCommand::PopulateOrExchange(ShuttleGui & S)
bool SetClipCommand::ApplyInner( const CommandContext & context, Track * t )
{
static_cast<void>(context);
if( t->GetKind() != Track::Wave)
return true;
// if no 'At' is specified, then any clip in any selected track will be set.
t->TypeSwitch([&](WaveTrack *waveTrack) {
WaveClipPointers ptrs( waveTrack->SortedClipArray());
for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
WaveClip * pClip = *it;
bool bFound =
!bHasContainsTime || (
( pClip->GetStartTime() <= mContainsTime ) &&
( pClip->GetEndTime() >= mContainsTime )
);
if( bFound )
{
// Inside this IF is where we actually apply the command
WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
wxASSERT( waveTrack );
WaveClipPointers ptrs( waveTrack->SortedClipArray());
for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
WaveClip * pClip = *it;
bool bFound =
!bHasContainsTime || (
( pClip->GetStartTime() <= mContainsTime ) &&
( pClip->GetEndTime() >= mContainsTime )
);
if( bFound )
{
// Inside this IF is where we actually apply the command
if( bHasColour )
pClip->SetColourIndex(mColour);
// No validation of overlap yet. We assume the user is sensible!
if( bHasT0 )
pClip->SetOffset(mT0);
// \todo Use SetClip to move a clip between tracks too.
if( bHasColour )
pClip->SetColourIndex(mColour);
// No validation of overlap yet. We assume the user is sensible!
if( bHasT0 )
pClip->SetOffset(mT0);
// \todo Use SetClip to move a clip between tracks too.
}
}
}
} );
return true;
}

View File

@@ -54,32 +54,29 @@ void SetEnvelopeCommand::PopulateOrExchange(ShuttleGui & S)
bool SetEnvelopeCommand::ApplyInner( const CommandContext & context, Track * t )
{
static_cast<void>(context);
if( (t->GetKind() != Track::Wave))
return true;
// if no time is specified, then
// if no time is specified, then
// - delete deletes any envelope in selected tracks.
// - value is not set for any clip
WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
WaveClipPointers ptrs( waveTrack->SortedClipArray());
for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
WaveClip * pClip = *it;
bool bFound =
!bHasT || (
( pClip->GetStartTime() <= mT) &&
( pClip->GetEndTime() >= mT )
);
if( bFound )
{
// Inside this IF is where we actually apply the command
Envelope* pEnv = pClip->GetEnvelope();
if( bHasDelete && mbDelete )
pEnv->mEnv.clear();
if( bHasT && bHasV )
pEnv->InsertOrReplace( mT, mV );
t->TypeSwitch([&](WaveTrack *waveTrack) {
WaveClipPointers ptrs( waveTrack->SortedClipArray());
for(auto it = ptrs.begin(); (it != ptrs.end()); it++ ){
WaveClip * pClip = *it;
bool bFound =
!bHasT || (
( pClip->GetStartTime() <= mT) &&
( pClip->GetEndTime() >= mT )
);
if( bFound )
{
// Inside this IF is where we actually apply the command
Envelope* pEnv = pClip->GetEnvelope();
if( bHasDelete && mbDelete )
pEnv->mEnv.clear();
if( bHasT && bHasV )
pEnv->InsertOrReplace( mT, mV );
}
}
}
} );
return true;
}