mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-16 08:34:10 +02:00
Group some member variables into ClipMoveState
This commit is contained in:
parent
282abfce7f
commit
227850f9cd
@ -1881,7 +1881,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.push_back(TrackClip(w, selectedClip));
|
mClipMoveState.capturedClipArray.push_back(TrackClip(w, selectedClip));
|
||||||
|
|
||||||
mMouseCapture = IsSliding;
|
mMouseCapture = IsSliding;
|
||||||
|
|
||||||
@ -3325,7 +3325,7 @@ void TrackPanel::ForwardEventToEnvelope(wxMouseEvent & event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackPanel::HandleSlide(wxMouseEvent & event)
|
void TrackPanel::HandleSlide( wxMouseEvent & event )
|
||||||
{
|
{
|
||||||
if (event.LeftDown())
|
if (event.LeftDown())
|
||||||
StartSlide(event);
|
StartSlide(event);
|
||||||
@ -3343,17 +3343,17 @@ void TrackPanel::HandleSlide(wxMouseEvent & event)
|
|||||||
mSnapManager.reset();
|
mSnapManager.reset();
|
||||||
|
|
||||||
// Do not draw yellow lines
|
// Do not draw yellow lines
|
||||||
if (mSnapLeft != -1 || mSnapRight != -1) {
|
if ( mClipMoveState.snapLeft != -1 || mClipMoveState.snapRight != -1) {
|
||||||
mSnapLeft = mSnapRight = -1;
|
mClipMoveState.snapLeft = mClipMoveState.snapRight = -1;
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mDidSlideVertically && mHSlideAmount==0)
|
if (!mDidSlideVertically && mClipMoveState.hSlideAmount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (size_t i = 0; i < mCapturedClipArray.size(); i++)
|
for (size_t i = 0; i < mClipMoveState.capturedClipArray.size(); i++)
|
||||||
{
|
{
|
||||||
TrackClip &trackClip = mCapturedClipArray[i];
|
TrackClip &trackClip = mClipMoveState.capturedClipArray[i];
|
||||||
WaveClip* pWaveClip = trackClip.clip;
|
WaveClip* pWaveClip = trackClip.clip;
|
||||||
// Note that per TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1),
|
// Note that per TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1),
|
||||||
// in the non-WaveTrack case, the code adds a NULL clip to mCapturedClipArray,
|
// in the non-WaveTrack case, the code adds a NULL clip to mCapturedClipArray,
|
||||||
@ -3380,14 +3380,14 @@ void TrackPanel::HandleSlide(wxMouseEvent & event)
|
|||||||
consolidate = false;
|
consolidate = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
wxString direction = mHSlideAmount>0 ?
|
wxString direction = mClipMoveState.hSlideAmount > 0 ?
|
||||||
/* i18n-hint: a direction as in left or right.*/
|
/* i18n-hint: a direction as in left or right.*/
|
||||||
_("right") :
|
_("right") :
|
||||||
/* i18n-hint: a direction as in left or right.*/
|
/* i18n-hint: a direction as in left or right.*/
|
||||||
_("left");
|
_("left");
|
||||||
/* i18n-hint: %s is a direction like left or right */
|
/* i18n-hint: %s is a direction like left or right */
|
||||||
msg.Printf(_("Time shifted tracks/clips %s %.02f seconds"),
|
msg.Printf(_("Time shifted tracks/clips %s %.02f seconds"),
|
||||||
direction.c_str(), fabs(mHSlideAmount));
|
direction.c_str(), fabs( mClipMoveState.hSlideAmount ));
|
||||||
consolidate = true;
|
consolidate = true;
|
||||||
}
|
}
|
||||||
MakeParentPushState(msg, _("Time-Shift"),
|
MakeParentPushState(msg, _("Time-Shift"),
|
||||||
@ -3443,10 +3443,9 @@ namespace {
|
|||||||
/// Prepare for sliding.
|
/// Prepare for sliding.
|
||||||
void TrackPanel::StartSlide(wxMouseEvent & event)
|
void TrackPanel::StartSlide(wxMouseEvent & event)
|
||||||
{
|
{
|
||||||
mHSlideAmount = 0.0;
|
mClipMoveState = ClipMoveState{};
|
||||||
mDidSlideVertically = false;
|
|
||||||
|
|
||||||
mTrackExclusions.clear();
|
mDidSlideVertically = false;
|
||||||
|
|
||||||
const auto foundCell = FindCell(event.m_x, event.m_y);
|
const auto foundCell = FindCell(event.m_x, event.m_y);
|
||||||
auto &vt = foundCell.pTrack;
|
auto &vt = foundCell.pTrack;
|
||||||
@ -3459,7 +3458,7 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
|
|||||||
|
|
||||||
double clickTime =
|
double clickTime =
|
||||||
mViewInfo->PositionToTime(event.m_x, GetLeftOffset());
|
mViewInfo->PositionToTime(event.m_x, GetLeftOffset());
|
||||||
mCapturedClipIsSelection =
|
mClipMoveState.capturedClipIsSelection =
|
||||||
(vt->GetSelected() &&
|
(vt->GetSelected() &&
|
||||||
clickTime > mViewInfo->selectedRegion.t0() &&
|
clickTime > mViewInfo->selectedRegion.t0() &&
|
||||||
clickTime < mViewInfo->selectedRegion.t1());
|
clickTime < mViewInfo->selectedRegion.t1());
|
||||||
@ -3475,12 +3474,12 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
|
|||||||
{
|
{
|
||||||
#ifdef USE_MIDI
|
#ifdef USE_MIDI
|
||||||
if (!wt)
|
if (!wt)
|
||||||
mCapturedClip = NULL;
|
mClipMoveState.capturedClip = NULL;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
mCapturedClip = wt->GetClipAtX(event.m_x);
|
mClipMoveState.capturedClip = wt->GetClipAtX(event.m_x);
|
||||||
if (mCapturedClip == NULL)
|
if (mClipMoveState.capturedClip == NULL)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3488,8 +3487,8 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
|
|||||||
CreateListOfCapturedClips(clickTime);
|
CreateListOfCapturedClips(clickTime);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mCapturedClip = NULL;
|
mClipMoveState.capturedClip = NULL;
|
||||||
mCapturedClipArray.clear();
|
mClipMoveState.capturedClipArray.clear();
|
||||||
mCapturedTrack = vt;
|
mCapturedTrack = vt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3505,15 +3504,15 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
|
|||||||
|
|
||||||
mSnapManager = std::make_unique<SnapManager>(GetTracks(),
|
mSnapManager = std::make_unique<SnapManager>(GetTracks(),
|
||||||
mViewInfo,
|
mViewInfo,
|
||||||
&mCapturedClipArray,
|
&mClipMoveState.capturedClipArray,
|
||||||
&mTrackExclusions,
|
&mClipMoveState.trackExclusions,
|
||||||
true); // don't snap to time
|
true); // don't snap to time
|
||||||
mSnapLeft = -1;
|
mClipMoveState.snapLeft = -1;
|
||||||
mSnapRight = -1;
|
mClipMoveState.snapRight = -1;
|
||||||
mSnapPreferRightEdge = false;
|
mSnapPreferRightEdge = false;
|
||||||
if (mCapturedClip) {
|
if (mClipMoveState.capturedClip) {
|
||||||
if (fabs(mSelStart - mCapturedClip->GetEndTime()) <
|
if (fabs(mSelStart - mClipMoveState.capturedClip->GetEndTime()) <
|
||||||
fabs(mSelStart - mCapturedClip->GetStartTime()))
|
fabs(mSelStart - mClipMoveState.capturedClip->GetStartTime()))
|
||||||
mSnapPreferRightEdge = true;
|
mSnapPreferRightEdge = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3522,36 +3521,41 @@ void TrackPanel::StartSlide(wxMouseEvent & event)
|
|||||||
|
|
||||||
void TrackPanel::CreateListOfCapturedClips(double clickTime)
|
void TrackPanel::CreateListOfCapturedClips(double clickTime)
|
||||||
{
|
{
|
||||||
|
auto &state = mClipMoveState;
|
||||||
|
auto &trackList = *GetTracks();
|
||||||
|
auto &capturedTrack = *mCapturedTrack;
|
||||||
|
|
||||||
// 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();
|
state.capturedClipArray.clear();
|
||||||
|
|
||||||
// First, if click was in selection, capture selected clips; otherwise
|
// First, if click was in selection, capture selected clips; otherwise
|
||||||
// just the clicked-on clip
|
// just the clicked-on clip
|
||||||
if (mCapturedClipIsSelection) {
|
if ( state.capturedClipIsSelection ) {
|
||||||
TrackListIterator iter(GetTracks());
|
TrackListIterator iter( &trackList );
|
||||||
for (Track *t = iter.First(); t; t = iter.Next()) {
|
for (Track *t = iter.First(); t; t = iter.Next()) {
|
||||||
if (t->GetSelected()) {
|
if (t->GetSelected()) {
|
||||||
AddClipsToCaptured(t, true);
|
AddClipsToCaptured(t, true);
|
||||||
if (t->GetKind() != Track::Wave)
|
if (t->GetKind() != Track::Wave)
|
||||||
mTrackExclusions.push_back(t);
|
state.trackExclusions.push_back(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mCapturedClipArray.push_back(TrackClip(mCapturedTrack, mCapturedClip));
|
state.capturedClipArray.push_back
|
||||||
|
(TrackClip( &capturedTrack, state.capturedClip ));
|
||||||
|
|
||||||
// Check for stereo partner
|
// Check for stereo partner
|
||||||
Track *partner = mCapturedTrack->GetLink();
|
Track *partner = capturedTrack.GetLink();
|
||||||
WaveTrack *wt;
|
WaveTrack *wt;
|
||||||
if (mCapturedClip &&
|
if (state.capturedClip &&
|
||||||
// Assume linked track is wave or null
|
// Assume linked track is wave or null
|
||||||
nullptr != (wt = static_cast<WaveTrack*>(partner))) {
|
nullptr != (wt = static_cast<WaveTrack*>(partner))) {
|
||||||
WaveClip *const clip = FindClipAtTime(wt, clickTime);
|
WaveClip *const clip = FindClipAtTime(wt, clickTime);
|
||||||
|
|
||||||
if (clip)
|
if (clip)
|
||||||
mCapturedClipArray.push_back(TrackClip(partner, clip));
|
state.capturedClipArray.push_back(TrackClip(partner, clip));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3562,34 +3566,34 @@ void TrackPanel::CreateListOfCapturedClips(double clickTime)
|
|||||||
// 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.size(); ++i) {
|
for (unsigned int i = 0; i < state.capturedClipArray.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)
|
||||||
if (mCapturedClipArray[i].clip) {
|
if ( state.capturedClipArray[i].clip ) {
|
||||||
// Iterate over sync-lock group tracks.
|
// Iterate over sync-lock group tracks.
|
||||||
SyncLockedTracksIterator git(GetTracks());
|
SyncLockedTracksIterator git( &trackList );
|
||||||
for (Track *t = git.StartWith(mCapturedClipArray[i].track);
|
for (Track *t = git.StartWith( state.capturedClipArray[i].track );
|
||||||
t; t = git.Next() )
|
t; t = git.Next() )
|
||||||
{
|
{
|
||||||
AddClipsToCaptured(t,
|
AddClipsToCaptured(t,
|
||||||
mCapturedClipArray[i].clip->GetStartTime(),
|
state.capturedClipArray[i].clip->GetStartTime(),
|
||||||
mCapturedClipArray[i].clip->GetEndTime() );
|
state.capturedClipArray[i].clip->GetEndTime() );
|
||||||
if (t->GetKind() != Track::Wave)
|
if (t->GetKind() != Track::Wave)
|
||||||
mTrackExclusions.push_back(t);
|
state.trackExclusions.push_back(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef USE_MIDI
|
#ifdef USE_MIDI
|
||||||
// Capture additional clips from NoteTracks
|
// Capture additional clips from NoteTracks
|
||||||
Track *nt = mCapturedClipArray[i].track;
|
Track *nt = state.capturedClipArray[i].track;
|
||||||
if (nt->GetKind() == Track::Note) {
|
if (nt->GetKind() == Track::Note) {
|
||||||
// Iterate over sync-lock group tracks.
|
// Iterate over sync-lock group tracks.
|
||||||
SyncLockedTracksIterator git(GetTracks());
|
SyncLockedTracksIterator git( &trackList );
|
||||||
for (Track *t = git.StartWith(nt); t; t = git.Next())
|
for (Track *t = git.StartWith(nt); t; t = git.Next())
|
||||||
{
|
{
|
||||||
AddClipsToCaptured(t, nt->GetStartTime(), nt->GetEndTime());
|
AddClipsToCaptured(t, nt->GetStartTime(), nt->GetEndTime());
|
||||||
if (t->GetKind() != Track::Wave)
|
if (t->GetKind() != Track::Wave)
|
||||||
mTrackExclusions.push_back(t);
|
state.trackExclusions.push_back(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -3611,6 +3615,8 @@ void TrackPanel::AddClipsToCaptured(Track *t, bool withinSelection)
|
|||||||
// Adds a track's clips to mCapturedClipArray within a specified time
|
// Adds a track's clips to mCapturedClipArray within a specified time
|
||||||
void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
|
void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
|
||||||
{
|
{
|
||||||
|
auto &state = mClipMoveState;
|
||||||
|
|
||||||
if (t->GetKind() == Track::Wave)
|
if (t->GetKind() == Track::Wave)
|
||||||
{
|
{
|
||||||
for(const auto &clip: static_cast<WaveTrack*>(t)->GetClips())
|
for(const auto &clip: static_cast<WaveTrack*>(t)->GetClips())
|
||||||
@ -3619,15 +3625,15 @@ 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.size(); ++i) {
|
for (unsigned int i = 0; i < state.capturedClipArray.size(); ++i) {
|
||||||
if (mCapturedClipArray[i].clip == clip.get()) {
|
if ( state.capturedClipArray[i].clip == clip.get() ) {
|
||||||
newClip = false;
|
newClip = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newClip)
|
if (newClip)
|
||||||
mCapturedClipArray.push_back(TrackClip(t, clip.get()));
|
state.capturedClipArray.push_back( TrackClip(t, clip.get()) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3638,8 +3644,8 @@ 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.size(); ++i) {
|
for ( unsigned int i = 0; i < state.capturedClipArray.size(); ++i ) {
|
||||||
if (mCapturedClipArray[i].track == t) {
|
if ( state.capturedClipArray[i].track == t ) {
|
||||||
newClip = false;
|
newClip = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3653,7 +3659,7 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
mCapturedClipArray.push_back(TrackClip(t, NULL));
|
state.capturedClipArray.push_back(TrackClip(t, NULL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3686,30 +3692,32 @@ 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.size())
|
if ( mClipMoveState.capturedClipArray.size() )
|
||||||
#else
|
#else
|
||||||
if (mCapturedClip)
|
if ( mClipMoveState.capturedClip )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
for(i=0; i<mCapturedClipArray.size(); i++) {
|
for ( i = 0; i < mClipMoveState.capturedClipArray.size(); ++i ) {
|
||||||
if (mCapturedClipArray[i].clip)
|
if ( mClipMoveState.capturedClipArray[i].clip )
|
||||||
mCapturedClipArray[i].clip->Offset(-mHSlideAmount);
|
mClipMoveState.capturedClipArray[i].clip->Offset
|
||||||
|
( -mClipMoveState.hSlideAmount );
|
||||||
else
|
else
|
||||||
mCapturedClipArray[i].track->Offset(-mHSlideAmount);
|
mClipMoveState.capturedClipArray[i].track->Offset
|
||||||
|
( -mClipMoveState.hSlideAmount );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mCapturedTrack->Offset(-mHSlideAmount);
|
mCapturedTrack->Offset( -mClipMoveState.hSlideAmount );
|
||||||
Track* link = mCapturedTrack->GetLink();
|
Track* link = mCapturedTrack->GetLink();
|
||||||
if (link)
|
if (link)
|
||||||
link->Offset(-mHSlideAmount);
|
link->Offset( -mClipMoveState.hSlideAmount );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mCapturedClipIsSelection) {
|
if ( mClipMoveState.capturedClipIsSelection ) {
|
||||||
// Slide the selection, too
|
// Slide the selection, too
|
||||||
mViewInfo->selectedRegion.move(-mHSlideAmount);
|
mViewInfo->selectedRegion.move( -mClipMoveState.hSlideAmount );
|
||||||
}
|
}
|
||||||
mHSlideAmount = 0.0;
|
mClipMoveState.hSlideAmount = 0.0;
|
||||||
|
|
||||||
// Implement sliding within the track(s)
|
// Implement sliding within the track(s)
|
||||||
double desiredSlideAmount;
|
double desiredSlideAmount;
|
||||||
@ -3729,11 +3737,13 @@ 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.size()) {
|
if (mSnapManager && mClipMoveState.capturedClipArray.size()) {
|
||||||
trySnap = true;
|
trySnap = true;
|
||||||
if (mCapturedClip) {
|
if ( mClipMoveState.capturedClip ) {
|
||||||
clipLeft = mCapturedClip->GetStartTime() + desiredSlideAmount;
|
clipLeft = mClipMoveState.capturedClip->GetStartTime()
|
||||||
clipRight = mCapturedClip->GetEndTime() + desiredSlideAmount;
|
+ desiredSlideAmount;
|
||||||
|
clipRight = mClipMoveState.capturedClip->GetEndTime()
|
||||||
|
+ desiredSlideAmount;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
clipLeft = mCapturedTrack->GetStartTime() + desiredSlideAmount;
|
clipLeft = mCapturedTrack->GetStartTime() + desiredSlideAmount;
|
||||||
@ -3748,9 +3758,9 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
desiredSlideAmount = rint(mtw->GetRate() * desiredSlideAmount) /
|
desiredSlideAmount = rint(mtw->GetRate() * desiredSlideAmount) /
|
||||||
mtw->GetRate(); // set it to a sample point
|
mtw->GetRate(); // set it to a sample point
|
||||||
}
|
}
|
||||||
if (mSnapManager && mCapturedClip) {
|
if (mSnapManager && mClipMoveState.capturedClip) {
|
||||||
clipLeft = mCapturedClip->GetStartTime() + desiredSlideAmount;
|
clipLeft = mClipMoveState.capturedClip->GetStartTime() + desiredSlideAmount;
|
||||||
clipRight = mCapturedClip->GetEndTime() + desiredSlideAmount;
|
clipRight = mClipMoveState.capturedClip->GetEndTime() + desiredSlideAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -3773,17 +3783,19 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Take whichever one snapped (if any) and compute the NEW desiredSlideAmount
|
// Take whichever one snapped (if any) and compute the NEW desiredSlideAmount
|
||||||
mSnapLeft = -1;
|
mClipMoveState.snapLeft = -1;
|
||||||
mSnapRight = -1;
|
mClipMoveState.snapRight = -1;
|
||||||
if (newClipLeft != clipLeft) {
|
if (newClipLeft != clipLeft) {
|
||||||
double difference = (newClipLeft - clipLeft);
|
double difference = (newClipLeft - clipLeft);
|
||||||
desiredSlideAmount += difference;
|
desiredSlideAmount += difference;
|
||||||
mSnapLeft = mViewInfo->TimeToPosition(newClipLeft, GetLeftOffset());
|
mClipMoveState.snapLeft =
|
||||||
|
mViewInfo->TimeToPosition(newClipLeft, GetLeftOffset());
|
||||||
}
|
}
|
||||||
else if (newClipRight != clipRight) {
|
else if (newClipRight != clipRight) {
|
||||||
double difference = (newClipRight - clipRight);
|
double difference = (newClipRight - clipRight);
|
||||||
desiredSlideAmount += difference;
|
desiredSlideAmount += difference;
|
||||||
mSnapRight = mViewInfo->TimeToPosition(newClipRight, GetLeftOffset());
|
mClipMoveState.snapRight =
|
||||||
|
mViewInfo->TimeToPosition(newClipRight, GetLeftOffset());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3794,14 +3806,14 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
|
|
||||||
// If the mouse is over a track that isn't the captured track,
|
// If the mouse is over a track that isn't the captured track,
|
||||||
// decide which tracks the captured clips should go to.
|
// decide which tracks the captured clips should go to.
|
||||||
if (mCapturedClip && mouseTrack != mCapturedTrack /*&&
|
if ( mClipMoveState.capturedClip && mouseTrack != mCapturedTrack /*&&
|
||||||
!mCapturedClipIsSelection*/)
|
!mCapturedClipIsSelection*/ )
|
||||||
{
|
{
|
||||||
const int diff =
|
const int diff =
|
||||||
TrackPosition(*mTracks, mouseTrack) -
|
TrackPosition(*mTracks, mouseTrack) -
|
||||||
TrackPosition(*mTracks, mCapturedTrack);
|
TrackPosition(*mTracks, mCapturedTrack);
|
||||||
for (unsigned ii = 0, nn = mCapturedClipArray.size(); ii < nn; ++ii) {
|
for ( unsigned ii = 0, nn = mClipMoveState.capturedClipArray.size(); ii < nn; ++ii ) {
|
||||||
TrackClip &trackClip = mCapturedClipArray[ii];
|
TrackClip &trackClip = mClipMoveState.capturedClipArray[ii];
|
||||||
if (trackClip.clip) {
|
if (trackClip.clip) {
|
||||||
// Move all clips up or down by an equal count of audio tracks.
|
// Move all clips up or down by an equal count of audio tracks.
|
||||||
Track *const pSrcTrack = trackClip.track;
|
Track *const pSrcTrack = trackClip.track;
|
||||||
@ -3826,8 +3838,9 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
// Having passed that test, remove clips temporarily from their
|
// Having passed that test, remove clips temporarily from their
|
||||||
// tracks, so moving clips don't interfere with each other
|
// tracks, so moving clips don't interfere with each other
|
||||||
// when we call CanInsertClip()
|
// when we call CanInsertClip()
|
||||||
for (unsigned ii = 0, nn = mCapturedClipArray.size(); ii < nn; ++ii) {
|
for ( unsigned ii = 0,
|
||||||
TrackClip &trackClip = mCapturedClipArray[ii];
|
nn = mClipMoveState.capturedClipArray.size(); ii < nn; ++ii ) {
|
||||||
|
TrackClip &trackClip = mClipMoveState.capturedClipArray[ii];
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
WaveClip *const pSrcClip = trackClip.clip;
|
||||||
if (pSrcClip)
|
if (pSrcClip)
|
||||||
trackClip.holder =
|
trackClip.holder =
|
||||||
@ -3838,8 +3851,9 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
|
|
||||||
// Now check that the move is possible
|
// Now check that the move is possible
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
for (unsigned ii = 0, nn = mCapturedClipArray.size(); ok && ii < nn; ++ii) {
|
for ( unsigned ii = 0,
|
||||||
TrackClip &trackClip = mCapturedClipArray[ii];
|
nn = mClipMoveState.capturedClipArray.size(); ok && ii < nn; ++ii) {
|
||||||
|
TrackClip &trackClip = mClipMoveState.capturedClipArray[ii];
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
WaveClip *const pSrcClip = trackClip.clip;
|
||||||
if (pSrcClip)
|
if (pSrcClip)
|
||||||
ok = trackClip.dstTrack->CanInsertClip(pSrcClip);
|
ok = trackClip.dstTrack->CanInsertClip(pSrcClip);
|
||||||
@ -3847,8 +3861,9 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// Failure -- put clips back where they were
|
// Failure -- put clips back where they were
|
||||||
for (unsigned ii = 0, nn = mCapturedClipArray.size(); ii < nn; ++ii) {
|
for ( unsigned ii = 0,
|
||||||
TrackClip &trackClip = mCapturedClipArray[ii];
|
nn = mClipMoveState.capturedClipArray.size(); ii < nn; ++ii) {
|
||||||
|
TrackClip &trackClip = mClipMoveState.capturedClipArray[ii];
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
WaveClip *const pSrcClip = trackClip.clip;
|
||||||
if (pSrcClip)
|
if (pSrcClip)
|
||||||
// Assume track is wave because it has a clip
|
// Assume track is wave because it has a clip
|
||||||
@ -3859,8 +3874,9 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Do the vertical moves of clips
|
// Do the vertical moves of clips
|
||||||
for (unsigned ii = 0, nn = mCapturedClipArray.size(); ii < nn; ++ii) {
|
for ( unsigned ii = 0,
|
||||||
TrackClip &trackClip = mCapturedClipArray[ii];
|
nn = mClipMoveState.capturedClipArray.size(); ii < nn; ++ii) {
|
||||||
|
TrackClip &trackClip = mClipMoveState.capturedClipArray[ii];
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
WaveClip *const pSrcClip = trackClip.clip;
|
||||||
if (pSrcClip) {
|
if (pSrcClip) {
|
||||||
const auto dstTrack = trackClip.dstTrack;
|
const auto dstTrack = trackClip.dstTrack;
|
||||||
@ -3885,19 +3901,19 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mHSlideAmount = desiredSlideAmount;
|
mClipMoveState.hSlideAmount = desiredSlideAmount;
|
||||||
|
|
||||||
DoSlideHorizontal();
|
DoSlideHorizontal();
|
||||||
|
|
||||||
|
|
||||||
if (mCapturedClipIsSelection) {
|
if ( mClipMoveState.capturedClipIsSelection ) {
|
||||||
// Slide the selection, too
|
// Slide the selection, too
|
||||||
mViewInfo->selectedRegion.move(mHSlideAmount);
|
mViewInfo->selectedRegion.move( mClipMoveState.hSlideAmount );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slidVertically) {
|
if (slidVertically) {
|
||||||
// NEW origin
|
// NEW origin
|
||||||
mHSlideAmount = 0;
|
mClipMoveState.hSlideAmount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
@ -3905,98 +3921,106 @@ void TrackPanel::DoSlide(wxMouseEvent & event)
|
|||||||
|
|
||||||
void TrackPanel::DoSlideHorizontal()
|
void TrackPanel::DoSlideHorizontal()
|
||||||
{
|
{
|
||||||
|
auto &state = mClipMoveState;
|
||||||
|
auto &trackList = *GetTracks();
|
||||||
|
auto &capturedTrack = *mCapturedTrack;
|
||||||
|
|
||||||
#ifdef USE_MIDI
|
#ifdef USE_MIDI
|
||||||
if (mCapturedClipArray.size())
|
if ( state.capturedClipArray.size() )
|
||||||
#else
|
#else
|
||||||
if (mCapturedClip)
|
if ( state.capturedClip )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
double allowed;
|
double allowed;
|
||||||
double initialAllowed;
|
double initialAllowed;
|
||||||
double safeBigDistance = 1000 + 2.0 * (mTracks->GetEndTime() -
|
double safeBigDistance = 1000 + 2.0 * ( trackList.GetEndTime() -
|
||||||
mTracks->GetStartTime());
|
trackList.GetStartTime() );
|
||||||
|
|
||||||
do { // loop to compute allowed, does not actually move anything yet
|
do { // loop to compute allowed, does not actually move anything yet
|
||||||
initialAllowed = mHSlideAmount;
|
initialAllowed = state.hSlideAmount;
|
||||||
|
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
for(i=0; i<mCapturedClipArray.size(); i++) {
|
for ( i = 0; i < state.capturedClipArray.size(); ++i ) {
|
||||||
WaveTrack *track = (WaveTrack *)mCapturedClipArray[i].track;
|
WaveTrack *track = (WaveTrack *)state.capturedClipArray[i].track;
|
||||||
WaveClip *clip = mCapturedClipArray[i].clip;
|
WaveClip *clip = state. capturedClipArray[i].clip;
|
||||||
|
|
||||||
if (clip) { // only audio clips are used to compute allowed
|
if (clip) { // only audio clips are used to compute allowed
|
||||||
// Move all other selected clips totally out of the way
|
// Move all other selected clips totally out of the way
|
||||||
// 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.size(); j++) {
|
for ( j = 0; j < state.capturedClipArray.size(); j++ ) {
|
||||||
WaveClip *clip2 = mCapturedClipArray[j].clip;
|
WaveClip *clip2 = state.capturedClipArray[j].clip;
|
||||||
if (clip2 && clip2 != clip)
|
if (clip2 && clip2 != clip)
|
||||||
clip2->Offset(-safeBigDistance);
|
clip2->Offset(-safeBigDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (track->CanOffsetClip(clip, mHSlideAmount, &allowed)) {
|
if ( track->CanOffsetClip(clip, state.hSlideAmount, &allowed) ) {
|
||||||
if (mHSlideAmount != allowed) {
|
if ( state.hSlideAmount != allowed ) {
|
||||||
mHSlideAmount = allowed;
|
state.hSlideAmount = allowed;
|
||||||
mSnapLeft = mSnapRight = -1; // see bug 1067
|
state.snapLeft = state.snapRight = -1; // see bug 1067
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mHSlideAmount = 0.0;
|
state.hSlideAmount = 0.0;
|
||||||
mSnapLeft = mSnapRight = -1; // see bug 1067
|
state.snapLeft = state.snapRight = -1; // see bug 1067
|
||||||
}
|
}
|
||||||
|
|
||||||
for(j=0; j<mCapturedClipArray.size(); j++) {
|
for ( j = 0; j < state.capturedClipArray.size(); ++j ) {
|
||||||
WaveClip *clip2 = mCapturedClipArray[j].clip;
|
WaveClip *clip2 = state.capturedClipArray[j].clip;
|
||||||
if (clip2 && clip2 != clip)
|
if (clip2 && clip2 != clip)
|
||||||
clip2->Offset(safeBigDistance);
|
clip2->Offset(safeBigDistance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (mHSlideAmount != initialAllowed);
|
} while ( state.hSlideAmount != initialAllowed );
|
||||||
|
|
||||||
if (mHSlideAmount != 0.0) { // finally, here is where clips are moved
|
if ( state.hSlideAmount != 0.0 ) { // finally, here is where clips are moved
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for(i=0; i<mCapturedClipArray.size(); i++) {
|
for ( i = 0; i < state.capturedClipArray.size(); ++i ) {
|
||||||
Track *track = mCapturedClipArray[i].track;
|
Track *track = state.capturedClipArray[i].track;
|
||||||
WaveClip *clip = mCapturedClipArray[i].clip;
|
WaveClip *clip = state.capturedClipArray[i].clip;
|
||||||
if (clip)
|
if (clip)
|
||||||
clip->Offset(mHSlideAmount);
|
clip->Offset( state.hSlideAmount );
|
||||||
else
|
else
|
||||||
track->Offset(mHSlideAmount);
|
track->Offset( state.hSlideAmount );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// For Shift key down, or
|
// For Shift key down, or
|
||||||
// For non wavetracks, specifically label tracks ...
|
// For non wavetracks, specifically label tracks ...
|
||||||
mCapturedTrack->Offset(mHSlideAmount);
|
capturedTrack.Offset( state.hSlideAmount );
|
||||||
Track* link = mCapturedTrack->GetLink();
|
Track* link = capturedTrack.GetLink();
|
||||||
if (link)
|
if (link)
|
||||||
link->Offset(mHSlideAmount);
|
link->Offset( state.hSlideAmount );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackPanel::OnClipMove(bool right)
|
void TrackPanel::OnClipMove(bool right)
|
||||||
{
|
{
|
||||||
|
auto &viewInfo = *mViewInfo;
|
||||||
|
auto &state = mClipMoveState;
|
||||||
auto track = GetFocusedTrack();
|
auto track = GetFocusedTrack();
|
||||||
|
|
||||||
|
|
||||||
// just dealing with clips in wave tracks for the moment. Note tracks??
|
// just dealing with clips in wave tracks for the moment. Note tracks??
|
||||||
if (track && track->GetKind() == Track::Wave) {
|
if (track && track->GetKind() == Track::Wave) {
|
||||||
auto wt = static_cast<WaveTrack*>(track);
|
auto wt = static_cast<WaveTrack*>(track);
|
||||||
mCapturedClip = wt->GetClipAtTime(mViewInfo->selectedRegion.t0());
|
auto t0 = viewInfo.selectedRegion.t0();
|
||||||
if (mCapturedClip == nullptr)
|
|
||||||
|
state.capturedClip = wt->GetClipAtTime( t0 );
|
||||||
|
if (state.capturedClip == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mCapturedTrack = track;
|
mCapturedTrack = track;
|
||||||
mCapturedClipIsSelection = track->GetSelected() && !mViewInfo->selectedRegion.isPoint();
|
state.capturedClipIsSelection =
|
||||||
mTrackExclusions.clear();
|
track->GetSelected() && !viewInfo.selectedRegion.isPoint();
|
||||||
|
state.trackExclusions.clear();
|
||||||
|
|
||||||
auto t0 = mViewInfo->selectedRegion.t0();
|
|
||||||
CreateListOfCapturedClips( t0 );
|
CreateListOfCapturedClips( t0 );
|
||||||
|
|
||||||
auto newT0 = mViewInfo->OffsetTimeByPixels( t0, ( right ? 1 : -1 ) );
|
auto newT0 = viewInfo.OffsetTimeByPixels( t0, ( right ? 1 : -1 ) );
|
||||||
auto desiredSlideAmount = newT0 - t0;
|
auto desiredSlideAmount = newT0 - t0;
|
||||||
|
|
||||||
// set it to a sample point, and minimum of 1 sample point
|
// set it to a sample point, and minimum of 1 sample point
|
||||||
@ -4008,23 +4032,23 @@ void TrackPanel::OnClipMove(bool right)
|
|||||||
if (!right)
|
if (!right)
|
||||||
desiredSlideAmount *= -1;
|
desiredSlideAmount *= -1;
|
||||||
|
|
||||||
mHSlideAmount = desiredSlideAmount;
|
state.hSlideAmount = desiredSlideAmount;
|
||||||
DoSlideHorizontal();
|
DoSlideHorizontal();
|
||||||
|
|
||||||
// update t0 and t1. There is the possibility that the updated
|
// update t0 and t1. There is the possibility that the updated
|
||||||
// t0 may no longer be within the clip due to rounding errors,
|
// t0 may no longer be within the clip due to rounding errors,
|
||||||
// so t0 is adjusted so that it is.
|
// so t0 is adjusted so that it is.
|
||||||
if (newT0 < mCapturedClip->GetStartTime())
|
if (newT0 < state.capturedClip->GetStartTime())
|
||||||
newT0 = mCapturedClip->GetStartTime();
|
newT0 = state.capturedClip->GetStartTime();
|
||||||
if (newT0 > mCapturedClip->GetEndTime())
|
if (newT0 > state.capturedClip->GetEndTime())
|
||||||
newT0 = mCapturedClip->GetEndTime();
|
newT0 = state.capturedClip->GetEndTime();
|
||||||
double diff = mViewInfo->selectedRegion.duration();
|
double diff = viewInfo.selectedRegion.duration();
|
||||||
mViewInfo->selectedRegion.setTimes(newT0, newT0 + diff);
|
viewInfo.selectedRegion.setTimes(newT0, newT0 + diff);
|
||||||
|
|
||||||
ScrollIntoView(mViewInfo->selectedRegion.t0());
|
ScrollIntoView( newT0 );
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
|
|
||||||
if (mHSlideAmount == 0.0)
|
if (state.hSlideAmount == 0.0)
|
||||||
MessageForScreenReader( _("clip not moved"));
|
MessageForScreenReader( _("clip not moved"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,15 @@ private:
|
|||||||
const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
|
const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
|
||||||
|
|
||||||
|
|
||||||
|
struct ClipMoveState {
|
||||||
|
WaveClip *capturedClip {};
|
||||||
|
bool capturedClipIsSelection {};
|
||||||
|
TrackArray trackExclusions {};
|
||||||
|
double hSlideAmount {};
|
||||||
|
TrackClipArray capturedClipArray {};
|
||||||
|
wxInt64 snapLeft { -1 }, snapRight { -1 };
|
||||||
|
};
|
||||||
|
|
||||||
class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
|
class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -658,10 +667,7 @@ protected:
|
|||||||
|
|
||||||
Track *mCapturedTrack;
|
Track *mCapturedTrack;
|
||||||
Envelope *mCapturedEnvelope;
|
Envelope *mCapturedEnvelope;
|
||||||
WaveClip *mCapturedClip;
|
ClipMoveState mClipMoveState;
|
||||||
TrackClipArray mCapturedClipArray;
|
|
||||||
TrackArray mTrackExclusions;
|
|
||||||
bool mCapturedClipIsSelection;
|
|
||||||
WaveTrackLocation mCapturedTrackLocation;
|
WaveTrackLocation mCapturedTrackLocation;
|
||||||
wxRect mCapturedTrackLocationRect;
|
wxRect mCapturedTrackLocationRect;
|
||||||
wxRect mCapturedRect;
|
wxRect mCapturedRect;
|
||||||
@ -678,10 +684,6 @@ protected:
|
|||||||
wxBaseArrayDouble mSlideSnapToPoints;
|
wxBaseArrayDouble mSlideSnapToPoints;
|
||||||
wxArrayInt mSlideSnapLinePixels;
|
wxArrayInt mSlideSnapLinePixels;
|
||||||
|
|
||||||
// The amount that clips are sliding horizontally; this allows
|
|
||||||
// us to undo the slide and then slide it by another amount
|
|
||||||
double mHSlideAmount;
|
|
||||||
|
|
||||||
bool mDidSlideVertically;
|
bool mDidSlideVertically;
|
||||||
|
|
||||||
bool mRedrawAfterStop;
|
bool mRedrawAfterStop;
|
||||||
@ -707,8 +709,20 @@ protected:
|
|||||||
bool mSnapPreferRightEdge;
|
bool mSnapPreferRightEdge;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxInt64 GetSnapLeft () const { return mSnapLeft ; }
|
wxInt64 GetSnapLeft () const
|
||||||
wxInt64 GetSnapRight() const { return mSnapRight; }
|
{
|
||||||
|
if ( mMouseCapture == IsSliding )
|
||||||
|
return mClipMoveState.snapLeft ;
|
||||||
|
else
|
||||||
|
return mSnapLeft ;
|
||||||
|
}
|
||||||
|
wxInt64 GetSnapRight() const
|
||||||
|
{
|
||||||
|
if ( mMouseCapture == IsSliding )
|
||||||
|
return mClipMoveState.snapRight;
|
||||||
|
else
|
||||||
|
return mSnapRight;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user