1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Move an array definition to Snap.h, use std::vector

This commit is contained in:
Paul Licameli 2015-07-09 00:38:42 -04:00
parent 54740c348b
commit d8ce9f0d7d
4 changed files with 42 additions and 46 deletions

View File

@ -82,7 +82,7 @@ SnapManager::SnapManager(TrackList *tracks, TrackClipArray *exclusions,
WaveClip *clip = it->GetData(); WaveClip *clip = it->GetData();
if (exclusions) { if (exclusions) {
bool skip = false; bool skip = false;
for(int j=0; j<(int)exclusions->GetCount(); j++) { for(int j=0; j<(int)exclusions->size(); j++) {
if ((*exclusions)[j].track == waveTrack && if ((*exclusions)[j].track == waveTrack &&
(*exclusions)[j].clip == clip) (*exclusions)[j].clip == clip)
skip = true; skip = true;

View File

@ -15,16 +15,27 @@
#ifndef __AUDACITY_SNAP__ #ifndef __AUDACITY_SNAP__
#define __AUDACITY_SNAP__ #define __AUDACITY_SNAP__
#include <vector>
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/dynarray.h>
#include "widgets/NumericTextCtrl.h" #include "widgets/NumericTextCtrl.h"
class Track; class Track;
class WaveClip;
class TrackList; class TrackList;
class TrackClipArray;
class ZoomInfo; class ZoomInfo;
class TrackClip
{
public:
TrackClip(Track *t, WaveClip *c) { track = t; clip = c; }
Track *track;
WaveClip *clip;
};
typedef std::vector<TrackClip> TrackClipArray;
enum enum
{ {
SNAP_OFF, SNAP_OFF,

View File

@ -230,12 +230,8 @@ is time to refresh some aspect of the screen.
#include "widgets/Ruler.h" #include "widgets/Ruler.h"
#include "widgets/NumericTextCtrl.h" #include "widgets/NumericTextCtrl.h"
#include <wx/arrimpl.cpp>
#define ZOOMLIMIT 0.001f #define ZOOMLIMIT 0.001f
WX_DEFINE_OBJARRAY(TrackClipArray);
//This loads the appropriate set of cursors, depending on platform. //This loads the appropriate set of cursors, depending on platform.
#include "../images/Cursors.h" #include "../images/Cursors.h"
#include <iostream> #include <iostream>
@ -2235,7 +2231,7 @@ void TrackPanel::HandleSelect(wxMouseEvent & event)
selectedClip->GetOffset(), selectedClip->GetEndTime()); selectedClip->GetOffset(), selectedClip->GetEndTime());
} }
//Also, capture this track for dragging until we up-click. //Also, capture this track for dragging until we up-click.
mCapturedClipArray.Add(TrackClip(w, selectedClip)); mCapturedClipArray.push_back(TrackClip(w, selectedClip));
mMouseCapture = IsSliding; mMouseCapture = IsSliding;
@ -3887,7 +3883,7 @@ void TrackPanel::HandleSlide(wxMouseEvent & event)
if (mDidSlideVertically && mCapturedTrack) if (mDidSlideVertically && mCapturedTrack)
// Now that user has dropped the clip into a different track, // Now that user has dropped the clip into a different track,
// make sure the sample rate matches the destination track (mCapturedTrack). // make sure the sample rate matches the destination track (mCapturedTrack).
for (size_t i = 0; i < mCapturedClipArray.GetCount(); i++) for (size_t i = 0; i < mCapturedClipArray.size(); i++)
if (mCapturedTrack->GetKind() == Track::Wave) // Should always be true here, but make sure. if (mCapturedTrack->GetKind() == Track::Wave) // Should always be true here, but make sure.
{ {
WaveClip* pWaveClip = mCapturedClipArray[i].clip; WaveClip* pWaveClip = mCapturedClipArray[i].clip;
@ -3975,7 +3971,7 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
// The captured clip is the focus, but we need to create a list // The captured clip is the focus, but we need to create a list
// of all clips that have to move, also... // of all clips that have to move, also...
mCapturedClipArray.Clear(); mCapturedClipArray.clear();
double clickTime = double clickTime =
mViewInfo->PositionToTime(event.m_x, GetLeftOffset()); mViewInfo->PositionToTime(event.m_x, GetLeftOffset());
@ -3998,7 +3994,7 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
} }
else { else {
mCapturedClipIsSelection = false; mCapturedClipIsSelection = false;
mCapturedClipArray.Add(TrackClip(vt, mCapturedClip)); mCapturedClipArray.push_back(TrackClip(vt, mCapturedClip));
// Check for stereo partner // Check for stereo partner
Track *partner = mTracks->GetLink(vt); Track *partner = mTracks->GetLink(vt);
@ -4012,7 +4008,7 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
if (s0 >= 0) { if (s0 >= 0) {
WaveClip *clip = ((WaveTrack *)partner)->GetClipAtSample(s0); WaveClip *clip = ((WaveTrack *)partner)->GetClipAtSample(s0);
if (clip) { if (clip) {
mCapturedClipArray.Add(TrackClip(partner, clip)); mCapturedClipArray.push_back(TrackClip(partner, clip));
} }
} }
} }
@ -4025,7 +4021,7 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
// clips are considered (the effect is like recursion and terminates // clips are considered (the effect is like recursion and terminates
// because AddClipsToCaptured doesn't add duplicate clips); to remove // because AddClipsToCaptured doesn't add duplicate clips); to remove
// this behavior just store the array size beforehand. // this behavior just store the array size beforehand.
for (unsigned int i = 0; i < mCapturedClipArray.GetCount(); ++i) { for (unsigned int i = 0; i < mCapturedClipArray.size(); ++i) {
// Capture based on tracks that have clips -- that means we // Capture based on tracks that have clips -- that means we
// don't capture based on links to label tracks for now (until // don't capture based on links to label tracks for now (until
// we can treat individual labels as clips) // we can treat individual labels as clips)
@ -4057,7 +4053,7 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
} else { } else {
mCapturedClip = NULL; mCapturedClip = NULL;
mCapturedClipArray.Clear(); mCapturedClipArray.clear();
} }
mSlideUpDownOnly = event.CmdDown() && !multiToolModeActive; mSlideUpDownOnly = event.CmdDown() && !multiToolModeActive;
@ -4116,7 +4112,7 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
{ {
// Avoid getting clips that were already captured // Avoid getting clips that were already captured
bool newClip = true; bool newClip = true;
for (unsigned int i = 0; i < mCapturedClipArray.GetCount(); ++i) { for (unsigned int i = 0; i < mCapturedClipArray.size(); ++i) {
if (mCapturedClipArray[i].clip == clip) { if (mCapturedClipArray[i].clip == clip) {
newClip = false; newClip = false;
break; break;
@ -4124,7 +4120,7 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
} }
if (newClip) if (newClip)
mCapturedClipArray.Add(TrackClip(t, clip)); mCapturedClipArray.push_back(TrackClip(t, clip));
} }
it = it->GetNext(); it = it->GetNext();
} }
@ -4136,7 +4132,7 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
// Avoid adding a track twice // Avoid adding a track twice
bool newClip = true; bool newClip = true;
for (unsigned int i = 0; i < mCapturedClipArray.GetCount(); ++i) { for (unsigned int i = 0; i < mCapturedClipArray.size(); ++i) {
if (mCapturedClipArray[i].track == t) { if (mCapturedClipArray[i].track == t) {
newClip = false; newClip = false;
break; break;
@ -4151,7 +4147,7 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
return; return;
} }
#endif #endif
mCapturedClipArray.Add(TrackClip(t, NULL)); mCapturedClipArray.push_back(TrackClip(t, NULL));
} }
} }
} }
@ -4183,11 +4179,11 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
// happens relative to the original horizontal position of // happens relative to the original horizontal position of
// each clip... // each clip...
#ifdef USE_MIDI #ifdef USE_MIDI
if (mCapturedClipArray.GetCount()) { if (mCapturedClipArray.size()) {
#else #else
if (mCapturedClip) { if (mCapturedClip) {
#endif #endif
for(i=0; i<mCapturedClipArray.GetCount(); i++) { for(i=0; i<mCapturedClipArray.size(); i++) {
if (mCapturedClipArray[i].clip) if (mCapturedClipArray[i].clip)
mCapturedClipArray[i].clip->Offset(-mHSlideAmount); mCapturedClipArray[i].clip->Offset(-mHSlideAmount);
else else
@ -4217,7 +4213,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
mtw->GetRate(); // set it to a sample point mtw->GetRate(); // set it to a sample point
} }
// Adjust desiredSlideAmount using SnapManager // Adjust desiredSlideAmount using SnapManager
if (mSnapManager && mCapturedClipArray.GetCount()) { if (mSnapManager && mCapturedClipArray.size()) {
double clipLeft; double clipLeft;
double clipRight; double clipRight;
if (mCapturedClip) { if (mCapturedClip) {
@ -4291,7 +4287,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
// Temporary apply the offset because we want to see if the // Temporary apply the offset because we want to see if the
// track fits with the desired offset // track fits with the desired offset
for(i=0; i<mCapturedClipArray.GetCount(); i++) for(i=0; i<mCapturedClipArray.size(); i++)
if (mCapturedClipArray[i].clip) if (mCapturedClipArray[i].clip)
mCapturedClipArray[i].clip->Offset(desiredSlideAmount); mCapturedClipArray[i].clip->Offset(desiredSlideAmount);
// See if it can be moved // See if it can be moved
@ -4312,7 +4308,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
} }
else { else {
// Undo the offset // Undo the offset
for(i=0; i<mCapturedClipArray.GetCount(); i++) for(i=0; i<mCapturedClipArray.size(); i++)
if (mCapturedClipArray[i].clip) if (mCapturedClipArray[i].clip)
mCapturedClipArray[i].clip->Offset(-desiredSlideAmount); mCapturedClipArray[i].clip->Offset(-desiredSlideAmount);
} }
@ -4333,7 +4329,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
} }
#ifdef USE_MIDI #ifdef USE_MIDI
if (mCapturedClipArray.GetCount()) { if (mCapturedClipArray.size()) {
#else #else
if (mCapturedClip) { if (mCapturedClip) {
#endif #endif
@ -4346,7 +4342,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
initialAllowed = mHSlideAmount; initialAllowed = mHSlideAmount;
unsigned int i, j; unsigned int i, j;
for(i=0; i<mCapturedClipArray.GetCount(); i++) { for(i=0; i<mCapturedClipArray.size(); i++) {
WaveTrack *track = (WaveTrack *)mCapturedClipArray[i].track; WaveTrack *track = (WaveTrack *)mCapturedClipArray[i].track;
WaveClip *clip = mCapturedClipArray[i].clip; WaveClip *clip = mCapturedClipArray[i].clip;
@ -4355,7 +4351,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
// temporarily because they're all moving together and // temporarily because they're all moving together and
// we want to find out if OTHER clips are in the way, // we want to find out if OTHER clips are in the way,
// not one of the moving ones // not one of the moving ones
for(j=0; j<mCapturedClipArray.GetCount(); j++) { for(j=0; j<mCapturedClipArray.size(); j++) {
WaveClip *clip2 = mCapturedClipArray[j].clip; WaveClip *clip2 = mCapturedClipArray[j].clip;
if (clip2 && clip2 != clip) if (clip2 && clip2 != clip)
clip2->Offset(-safeBigDistance); clip2->Offset(-safeBigDistance);
@ -4367,7 +4363,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
else else
mHSlideAmount = 0.0; mHSlideAmount = 0.0;
for(j=0; j<mCapturedClipArray.GetCount(); j++) { for(j=0; j<mCapturedClipArray.size(); j++) {
WaveClip *clip2 = mCapturedClipArray[j].clip; WaveClip *clip2 = mCapturedClipArray[j].clip;
if (clip2 && clip2 != clip) if (clip2 && clip2 != clip)
clip2->Offset(safeBigDistance); clip2->Offset(safeBigDistance);
@ -4378,7 +4374,7 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
if (mHSlideAmount != 0.0) { // finally, here is where clips are moved if (mHSlideAmount != 0.0) { // finally, here is where clips are moved
unsigned int i; unsigned int i;
for(i=0; i<mCapturedClipArray.GetCount(); i++) { for(i=0; i<mCapturedClipArray.size(); i++) {
Track *track = mCapturedClipArray[i].track; Track *track = mCapturedClipArray[i].track;
WaveClip *clip = mCapturedClipArray[i].clip; WaveClip *clip = mCapturedClipArray[i].clip;
if (clip) if (clip)
@ -9794,7 +9790,7 @@ bool TrackPanel::MoveClipToTrack(WaveClip *clip, WaveTrack* dst)
if (dst->GetKind() != Track::Wave) return false; if (dst->GetKind() != Track::Wave) return false;
#endif #endif
for (i = 0; i < mCapturedClipArray.GetCount(); i++) { for (i = 0; i < mCapturedClipArray.size(); i++) {
if (clip == mCapturedClipArray[i].clip) { if (clip == mCapturedClipArray[i].clip) {
src = (WaveTrack*)mCapturedClipArray[i].track; src = (WaveTrack*)mCapturedClipArray[i].track;
break; break;
@ -9812,7 +9808,7 @@ bool TrackPanel::MoveClipToTrack(WaveClip *clip, WaveTrack* dst)
// find the first track by getting the linked track from src // find the first track by getting the linked track from src
// assumes that mCapturedArray[i].clip and .track is not NULL. // assumes that mCapturedArray[i].clip and .track is not NULL.
for (i = 0; i < mCapturedClipArray.GetCount(); i++) { for (i = 0; i < mCapturedClipArray.size(); i++) {
if (mTracks->GetLink(src) == mCapturedClipArray[i].track) { if (mTracks->GetLink(src) == mCapturedClipArray[i].track) {
clip = mCapturedClipArray[i].clip; clip = mCapturedClipArray[i].clip;
break; break;
@ -9828,7 +9824,7 @@ bool TrackPanel::MoveClipToTrack(WaveClip *clip, WaveTrack* dst)
src2 = (WaveTrack*)mTracks->GetLink(src); src2 = (WaveTrack*)mTracks->GetLink(src);
dst2 = (WaveTrack*)mTracks->GetLink(dst); dst2 = (WaveTrack*)mTracks->GetLink(dst);
for (i = 0; i < mCapturedClipArray.GetCount(); i++) { for (i = 0; i < mCapturedClipArray.size(); i++) {
if (mCapturedClipArray[i].track == src2) { if (mCapturedClipArray[i].track == src2) {
clip2 = mCapturedClipArray[i].clip; clip2 = mCapturedClipArray[i].clip;
break; break;
@ -9864,7 +9860,7 @@ bool TrackPanel::MoveClipToTrack(WaveClip *clip, WaveTrack* dst)
src2->MoveClipToTrack(clip2, dst2); src2->MoveClipToTrack(clip2, dst2);
// update the captured clip array. // update the captured clip array.
for (i = 0; i < mCapturedClipArray.GetCount(); i++) { for (i = 0; i < mCapturedClipArray.size(); i++) {
if (clip && mCapturedClipArray[i].clip == clip) { if (clip && mCapturedClipArray[i].clip == clip) {
mCapturedClipArray[i].track = dst; mCapturedClipArray[i].track = dst;
} else if (clip2 && mCapturedClipArray[i].clip == clip2) { } else if (clip2 && mCapturedClipArray[i].clip == clip2) {

View File

@ -15,7 +15,6 @@
#include <vector> #include <vector>
#include <wx/dcmemory.h> #include <wx/dcmemory.h>
#include <wx/dynarray.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/timer.h> #include <wx/timer.h>
#include <wx/window.h> #include <wx/window.h>
@ -27,6 +26,8 @@
#include "WaveTrackLocation.h" #include "WaveTrackLocation.h"
#include "Snap.h"
class wxMenu; class wxMenu;
class wxRect; class wxRect;
@ -51,24 +52,12 @@ class WaveTrack;
class WaveClip; class WaveClip;
class Envelope; class Envelope;
WX_DEFINE_ARRAY(LWSlider *, LWSliderArray);
class AUDACITY_DLL_API TrackClip
{
public:
TrackClip(Track *t, WaveClip *c) { track = t; clip = c; }
Track *track;
WaveClip *clip;
};
WX_DECLARE_OBJARRAY(TrackClip, TrackClipArray);
// Declared elsewhere, to reduce compilation dependencies // Declared elsewhere, to reduce compilation dependencies
class TrackPanelListener; class TrackPanelListener;
// JKC Nov 2011: Disabled warning C4251 which is to do with DLL linkage // JKC Nov 2011: Disabled warning C4251 which is to do with DLL linkage
// and only a worry when there are DLLs using the structures. // and only a worry when there are DLLs using the structures.
// LWSliderArray and TrackClipArray are private in TrackInfo, so we will not // Array classes are private in TrackInfo, so we will not
// access them directly from the DLL. // access them directly from the DLL.
// TrackClipArray in TrackPanel needs to be handled with care in the derived // TrackClipArray in TrackPanel needs to be handled with care in the derived
// class, but the C4251 warning is no worry in core Audacity. // class, but the C4251 warning is no worry in core Audacity.