Minimized state moved into TrackView

This commit is contained in:
Paul Licameli 2019-06-18 11:29:38 -04:00
parent 7a91cc8e8d
commit 3797a5227a
14 changed files with 108 additions and 83 deletions

View File

@ -61,8 +61,6 @@ Track::Track(const std::shared_ptr<DirManager> &projDirManager)
mHeight = DefaultHeight;
mIndex = 0;
mMinimized = false;
mOffset = 0.0;
mChannel = MonoChannel;
@ -90,7 +88,6 @@ void Track::Init(const Track &orig)
mSelected = orig.mSelected;
mLinked = orig.mLinked;
mHeight = orig.mHeight;
mMinimized = orig.mMinimized;
mChannel = orig.mChannel;
}
@ -195,9 +192,10 @@ void Track::DoSetY(int y)
mY = y;
}
#include "tracks/ui/TrackView.h"
int Track::GetHeight() const
{
if (mMinimized) {
if ( TrackView::Get( *this ).GetMinimized() ) {
return GetMinimizedHeight();
}
@ -229,36 +227,6 @@ void Track::DoSetHeight(int h)
mHeight = h;
}
bool Track::GetMinimized() const
{
return mMinimized;
}
void Track::SetMinimized(bool isMinimized)
{
auto pList = mList.lock();
if (pList && !pList->mPendingUpdates.empty()) {
auto orig = pList->FindById( GetId() );
if (orig && orig != this) {
// delegate, and rely on RecalcPositions to copy back
orig->SetMinimized(isMinimized);
return;
}
}
DoSetMinimized(isMinimized);
if (pList) {
pList->RecalcPositions(mNode);
pList->ResizingEvent(mNode);
}
}
void Track::DoSetMinimized(bool isMinimized)
{
mMinimized = isMinimized;
}
void Track::SetLinked(bool l)
{
auto pList = mList.lock();
@ -1162,7 +1130,6 @@ void TrackList::UpdatePendingTracks()
updater( *pendingTrack, *src );
pendingTrack->DoSetY(src->GetY());
pendingTrack->DoSetHeight(src->GetActualHeight());
pendingTrack->DoSetMinimized(src->GetMinimized());
pendingTrack->DoSetLinked(src->GetLinked());
}
++pUpdater;
@ -1306,7 +1273,7 @@ void Track::WriteCommonXMLAttributes(
xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
}
xmlFile.WriteAttr(wxT("height"), this->GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), this->GetMinimized());
xmlFile.WriteAttr(wxT("minimized"), TrackView::Get( *this ).GetMinimized());
}
// Return true iff the attribute is recognized.
@ -1326,7 +1293,7 @@ bool Track::HandleCommonXMLAttribute(const wxChar *attr, const wxChar *value)
}
else if (!wxStrcmp(attr, wxT("minimized")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) {
SetMinimized(nValue != 0);
TrackView::Get( *this ).SetMinimized(nValue != 0);
return true;
}
else if (!wxStrcmp(attr, wxT("isSelected")) &&

View File

@ -206,7 +206,6 @@ class AUDACITY_DLL_API Track /* not final */
protected:
bool mLinked;
bool mMinimized;
public:
@ -297,12 +296,6 @@ public:
void SetHeight(int h);
protected:
virtual void DoSetHeight(int h);
public:
bool GetMinimized() const;
void SetMinimized(bool isMinimized);
protected:
virtual void DoSetMinimized(bool isMinimized);
public:
static void FinishCopy (const Track *n, Track *dest);

View File

@ -1448,7 +1448,8 @@ void TrackInfo::MinimizeSyncLockDrawFunction
auto dc = &context.dc;
bool selected = pTrack ? pTrack->GetSelected() : true;
bool syncLockSelected = pTrack ? pTrack->IsSyncLockSelected() : true;
bool minimized = pTrack ? pTrack->GetMinimized() : false;
bool minimized =
pTrack ? TrackView::Get( *pTrack ).GetMinimized() : false;
{
wxRect bev = rect;
GetMinimizeHorizontalBounds(rect, bev);

View File

@ -19,6 +19,7 @@ Paul Licameli split from TrackPanel.cpp
#include "RefreshCode.h"
#include "Track.h"
#include "TrackPanelMouseEvent.h"
#include "tracks/ui/TrackView.h"
HitTestPreview TrackPanelResizeHandle::HitPreview(bool bLinked)
{
@ -68,7 +69,7 @@ TrackPanelResizeHandle::TrackPanelResizeHandle
auto last = *channels.rbegin();
mInitialTrackHeight = last->GetHeight();
mInitialActualHeight = last->GetActualHeight();
mInitialMinimized = last->GetMinimized();
mInitialMinimized = TrackView::Get( *last ).GetMinimized();
if (channels.size() > 1) {
auto first = *channels.begin();
@ -104,11 +105,12 @@ UIHandle::Result TrackPanelResizeHandle::Drag
//
// This used to be in HandleResizeClick(), but simply clicking
// on a resize border would switch the minimized state.
if (pTrack->GetMinimized()) {
auto &data = TrackView::Get( *pTrack );
if (data.GetMinimized()) {
auto channels = TrackList::Channels( pTrack.get() );
for (auto channel : channels) {
channel->SetHeight(channel->GetHeight());
channel->SetMinimized(false);
TrackView::Get( *channel ).SetMinimized( false );
}
if (channels.size() > 1) {
@ -234,25 +236,25 @@ UIHandle::Result TrackPanelResizeHandle::Cancel(AudacityProject *pProject)
case IsResizing:
{
pTrack->SetHeight(mInitialActualHeight);
pTrack->SetMinimized(mInitialMinimized);
TrackView::Get( *pTrack ).SetMinimized( mInitialMinimized );
}
break;
case IsResizingBetweenLinkedTracks:
{
Track *const next = * ++ tracks.Find(pTrack.get());
pTrack->SetHeight(mInitialUpperActualHeight);
pTrack->SetMinimized(mInitialMinimized);
TrackView::Get( *pTrack ).SetMinimized( mInitialMinimized );
next->SetHeight(mInitialActualHeight);
next->SetMinimized(mInitialMinimized);
TrackView::Get( *next ).SetMinimized( mInitialMinimized );
}
break;
case IsResizingBelowLinkedTracks:
{
Track *const prev = * -- tracks.Find(pTrack.get());
pTrack->SetHeight(mInitialActualHeight);
pTrack->SetMinimized(mInitialMinimized);
TrackView::Get( *pTrack ).SetMinimized( mInitialMinimized );
prev->SetHeight(mInitialUpperActualHeight);
prev->SetMinimized(mInitialMinimized);
TrackView::Get( *prev ).SetMinimized( mInitialMinimized );
}
break;
}

View File

@ -482,20 +482,6 @@ void WaveTrack::SetOldChannelGain(int channel, float gain)
void WaveTrack::DoSetMinimized(bool isMinimized){
#ifdef EXPERIMENTAL_HALF_WAVE
bool bHalfWave;
gPrefs->Read(wxT("/GUI/CollapseToHalfWave"), &bHalfWave, false);
if( bHalfWave )
{
DoZoomPreset( isMinimized ? 1:0);
}
#endif
PlayableTrack::DoSetMinimized( isMinimized );
}
void WaveTrack::SetWaveColorIndex(int colorIndex)
// STRONG-GUARANTEE
{

View File

@ -148,8 +148,6 @@ private:
float GetOldChannelGain(int channel) const;
void SetOldChannelGain(int channel, float gain);
void DoSetMinimized(bool isMinimized) override;
int GetWaveColorIndex() const { return mWaveColorIndex; };
void SetWaveColorIndex(int colorIndex);

View File

@ -18,6 +18,7 @@
#include "../commands/CommandManager.h"
#include "../prefs/GUIPrefs.h"
#include "../prefs/TracksPrefs.h"
#include "../tracks/ui/TrackView.h"
#ifdef EXPERIMENTAL_EFFECTS_RACK
#include "../effects/EffectManager.h"
@ -189,7 +190,9 @@ void DoZoomFitV(AudacityProject &project)
auto &tracks = TrackList::Get( project );
// Only nonminimized audio tracks will be resized
auto range = tracks.Any<AudioTrack>() - &Track::GetMinimized;
auto range = tracks.Any<AudioTrack>()
- [](const Track *pTrack){
return TrackView::Get( *pTrack ).GetMinimized(); };
auto count = range.size();
if (count == 0)
return;
@ -315,7 +318,7 @@ void OnCollapseAllTracks(const CommandContext &context)
auto &window = ProjectWindow::Get( project );
for (auto t : tracks.Any())
t->SetMinimized(true);
TrackView::Get( *t ).SetMinimized(true);
ProjectHistory::Get( project ).ModifyState(true);
window.RedrawProject();
@ -328,7 +331,7 @@ void OnExpandAllTracks(const CommandContext &context)
auto &window = ProjectWindow::Get( project );
for (auto t : tracks.Any())
t->SetMinimized(false);
TrackView::Get( *t ).SetMinimized(false);
ProjectHistory::Get( project ).ModifyState(true);
window.RedrawProject();

View File

@ -80,6 +80,7 @@
#include "../prefs/TracksPrefs.h"
#include "../toolbars/ToolManager.h"
#include "../TrackPanel.h"
#include "../tracks/ui/TrackView.h"
IMPLEMENT_CLASS(ControlToolBar, ToolBar);
@ -1239,7 +1240,7 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
if ((recordingChannels > 2) &&
!(ProjectSettings::Get(*p).GetTracksFitVerticallyZoomed())) {
newTrack->SetMinimized(true);
TrackView::Get( *newTrack ).SetMinimized(true);
}
TrackList::Get( *p ).RegisterPendingNewTrack( newTrack );

View File

@ -16,6 +16,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../ui/PlayableTrackButtonHandles.h"
#include "WaveTrackSliderHandles.h"
#include "../../../ui/TrackView.h"
#include "../../../../AudioIOBase.h"
#include "../../../../Menus.h"
#include "../../../../Project.h"
@ -857,6 +858,10 @@ void WaveTrackMenuTable::OnMergeStereo(wxCommandEvent &)
auto partner = static_cast< WaveTrack * >
( *tracks.Find( pTrack ).advance( 1 ) );
bool bBothMinimizedp =
((TrackView::Get( *pTrack ).GetMinimized()) &&
(TrackView::Get( *partner ).GetMinimized()));
tracks.GroupChannels( *pTrack, 2 );
// Set partner's parameters to match target.
@ -866,14 +871,13 @@ void WaveTrackMenuTable::OnMergeStereo(wxCommandEvent &)
partner->SetPan( 0.0f );
// Set NEW track heights and minimized state
bool bBothMinimizedp = ((pTrack->GetMinimized()) && (partner->GetMinimized()));
pTrack->SetMinimized(false);
partner->SetMinimized(false);
TrackView::Get( *pTrack ).SetMinimized(false);
TrackView::Get( *partner ).SetMinimized(false);
int AverageHeight = (pTrack->GetHeight() + partner->GetHeight()) / 2;
pTrack->SetHeight(AverageHeight);
partner->SetHeight(AverageHeight);
pTrack->SetMinimized(bBothMinimizedp);
partner->SetMinimized(bBothMinimizedp);
TrackView::Get( *pTrack ).SetMinimized(bBothMinimizedp);
TrackView::Get( *partner ).SetMinimized(bBothMinimizedp);
//On Demand - join the queues together.
if (ODManager::IsInstanceCreated())

View File

@ -16,6 +16,7 @@ Paul Licameli split from TrackPanel.cpp
#include "WaveTrackVRulerControls.h"
#include "../../../../HitTestResult.h"
#include "../../../../prefs/SpectrogramSettings.h"
#include "../../../../TrackPanelMouseEvent.h"
#include "CutlineHandle.h"
@ -108,6 +109,43 @@ std::vector<UIHandlePtr> WaveTrackView::DetailedHitTest
return results;
}
void WaveTrackView::DoSetMinimized( bool minimized )
{
auto wt = static_cast<WaveTrack*>( FindTrack().get() );
#ifdef EXPERIMENTAL_HALF_WAVE
bool bHalfWave;
gPrefs->Read(wxT("/GUI/CollapseToHalfWave"), &bHalfWave, false);
if( bHalfWave )
{
const bool spectral =
(wt->GetDisplay() == WaveTrack::Spectrum);
if ( spectral ) {
// It is all right to set the top of scale to a huge number,
// not knowing the track rate here -- because when retrieving the
// value, then we pass in a sample rate and clamp it above to the
// Nyquist frequency.
constexpr auto max = std::numeric_limits<float>::max();
const bool spectrumLinear =
(wt->GetSpectrogramSettings().scaleType ==
SpectrogramSettings::stLinear);
// Zoom out full
wt->SetSpectrumBounds( spectrumLinear ? 0.0f : 1.0f, max );
}
else {
if (minimized)
// Zoom to show fractionally more than the top half of the wave.
wt->SetDisplayBounds( -0.01f, 1.0f );
else
// Zoom out full
wt->SetDisplayBounds( -1.0f, 1.0f );
}
}
#endif
TrackView::DoSetMinimized( minimized );
}
std::shared_ptr<TrackView> WaveTrack::DoGetView()
{
return std::make_shared<WaveTrackView>( SharedPointer() );

View File

@ -30,6 +30,7 @@ public:
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
private:
std::vector<UIHandlePtr> DetailedHitTest
(const TrackPanelMouseState &state,
@ -39,6 +40,9 @@ private:
std::weak_ptr<CutlineHandle> mCutlineHandle;
std::weak_ptr<SampleHandle> mSampleHandle;
std::weak_ptr<EnvelopeHandle> mEnvelopeHandle;
protected:
void DoSetMinimized( bool minimized ) override;
};
#endif

View File

@ -19,6 +19,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Track.h"
#include "../../TrackPanel.h"
#include "../../commands/CommandManager.h"
#include "../../tracks/ui/TrackView.h"
MinimizeButtonHandle::MinimizeButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
@ -37,9 +38,10 @@ UIHandle::Result MinimizeButtonHandle::CommitChanges
auto pTrack = mpTrack.lock();
if (pTrack)
{
bool wasMinimized = pTrack->GetMinimized();
for (auto channel : TrackList::Channels(pTrack.get()))
channel->SetMinimized(!wasMinimized);
auto channels = TrackList::Channels(pTrack.get());
bool wasMinimized = TrackView::Get( **channels.begin() ).GetMinimized();
for (auto channel : channels)
TrackView::Get( *channel ).SetMinimized( !wasMinimized );
ProjectHistory::Get( *pProject ).ModifyState(true);
// Redraw all tracks when any one of them expands or contracts
@ -54,7 +56,8 @@ UIHandle::Result MinimizeButtonHandle::CommitChanges
wxString MinimizeButtonHandle::Tip(const wxMouseState &) const
{
auto pTrack = GetTrack();
return pTrack->GetMinimized() ? _("Expand") : _("Collapse");
return TrackView::Get( *pTrack ).GetMinimized()
? _("Expand") : _("Collapse");
}
UIHandlePtr MinimizeButtonHandle::HitTest

View File

@ -18,8 +18,9 @@ TrackView::~TrackView()
{
}
void TrackView::Copy( const TrackView & )
void TrackView::Copy( const TrackView &other )
{
mMinimized = other.mMinimized;
}
TrackView &TrackView::Get( Track &track )
@ -32,6 +33,22 @@ const TrackView &TrackView::Get( const Track &track )
return *track.GetTrackView();
}
void TrackView::SetMinimized(bool isMinimized)
{
// Do special changes appropriate to subclass
DoSetMinimized(isMinimized);
// Update positions and heights starting from the first track in the group
auto leader = *TrackList::Channels( FindTrack().get() ).begin();
if ( leader )
leader->AdjustPositions();
}
void TrackView::DoSetMinimized(bool isMinimized)
{
mMinimized = isMinimized;
}
std::shared_ptr<TrackView> Track::GetTrackView()
{
if (!mpView)

View File

@ -36,6 +36,9 @@ public:
static TrackView &Get( Track & );
static const TrackView &Get( const Track & );
bool GetMinimized() const { return mMinimized; }
void SetMinimized( bool minimized );
// Return another, associated TrackPanelCell object that implements the
// mouse actions for the vertical ruler
std::shared_ptr<TrackVRulerControls> GetVRulerControls();
@ -48,12 +51,17 @@ public:
std::shared_ptr<const TrackPanelCell> GetResizer() const;
protected:
virtual void DoSetMinimized( bool isMinimized );
// Private factory to make appropriate object; class TrackView handles
// memory management thereafter
virtual std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() = 0;
std::shared_ptr<TrackVRulerControls> mpVRulerControls;
std::shared_ptr<TrackPanelResizerCell> mpResizer;
private:
bool mMinimized{ false };
};
#endif