diff --git a/src/LabelDialog.h b/src/LabelDialog.h index 29640d620..1aa46b7f2 100644 --- a/src/LabelDialog.h +++ b/src/LabelDialog.h @@ -25,7 +25,7 @@ class TrackList; class RowData; class EmptyLabelRenderer; class LabelTrack; -struct ViewInfo; +class ViewInfo; WX_DEFINE_ARRAY(RowData *, RowDataArray); diff --git a/src/Printing.cpp b/src/Printing.cpp index 0ce8710df..aa56d1960 100644 --- a/src/Printing.cpp +++ b/src/Printing.cpp @@ -15,6 +15,7 @@ #include "Audacity.h" +#include "Printing.h" #include #include @@ -29,7 +30,6 @@ #include "ViewInfo.h" #include "WaveTrack.h" #include "widgets/Ruler.h" -#include "Printing.h" // Globals, so that we remember settings from session to session static wxPrintData *gPrintData = NULL; @@ -80,13 +80,8 @@ bool AudacityPrintout::OnPrintPage(int WXUNUSED(page)) TrackArtist artist; artist.SetBackgroundBrushes(*wxWHITE_BRUSH, *wxWHITE_BRUSH, *wxWHITE_PEN, *wxWHITE_PEN); - ViewInfo viewInfo; - viewInfo.selectedRegion = SelectedRegion(); - viewInfo.vpos = 0; - viewInfo.h = 0.0; - viewInfo.screen = mTracks->GetEndTime() - viewInfo.h; - viewInfo.total = viewInfo.screen; - viewInfo.zoom = width / viewInfo.screen; + const double screenDuration = mTracks->GetEndTime(); + ViewInfo viewInfo(0.0, screenDuration, width / screenDuration); int y = rulerPageHeight; TrackListIterator iter(mTracks); diff --git a/src/Project.cpp b/src/Project.cpp index 7bd975546..ad61d1e10 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -780,6 +780,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, mTimerRecordCanceled(false), mMenuClose(false) , mbInitializingScrollbar(false) + , mViewInfo(0.0, 1.0, (44100.0 / 512.0)) { // Note that the first field of the status bar is a dummy, and it's width is set // to zero latter in the code. This field is needed for wxWidgets 2.8.12 because @@ -810,26 +811,6 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, // Initialize view info (shared with TrackPanel) // - // Selection - mViewInfo.selectedRegion = SelectedRegion(); - - // Horizontal scrollbar - mViewInfo.total = 1.0; - mViewInfo.screen = 1.0; - mViewInfo.h = 0.0; - mViewInfo.zoom = 44100.0 / 512.0; - - // Vertical scrollbar - mViewInfo.track = NULL; - mViewInfo.vpos = 0; - - mViewInfo.scrollStep = 16; - - mViewInfo.sbarH = 0; - mViewInfo.sbarScreen = 1; - mViewInfo.sbarTotal = 1; - mViewInfo.sbarScale = 1.0; - UpdatePrefs(); mLockPlayRegion = false; @@ -2902,6 +2883,12 @@ bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs) if (!value || !XMLValueChecker::IsGoodString(value)) break; + if (mViewInfo.ReadXMLAttribute(attr, value)) { + // We need to save vpos now and restore it below + longVpos = std::max(longVpos, long(mViewInfo.vpos)); + continue; + } + if (!wxStrcmp(attr, wxT("datadir"))) { // @@ -2995,20 +2982,6 @@ bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs) requiredTags++; } - else if (mViewInfo.selectedRegion - .HandleXMLAttribute(attr, value, wxT("sel0"), wxT("sel1"))) { - } - - else if (!wxStrcmp(attr, wxT("vpos"))) - // Just assign a variable, put the value in its place later - wxString(value).ToLong(&longVpos); - - else if (!wxStrcmp(attr, wxT("h"))) - Internat::CompatibleToDouble(value, &mViewInfo.h); - - else if (!wxStrcmp(attr, wxT("zoom"))) - Internat::CompatibleToDouble(value, &mViewInfo.zoom); - else if (!wxStrcmp(attr, wxT("rate"))) { Internat::CompatibleToDouble(value, &mRate); GetSelectionBar()->SetRate(mRate); @@ -3202,12 +3175,8 @@ void AudacityProject::WriteXML(XMLWriter &xmlFile) xmlFile.WriteAttr(wxT("projname"), projName); xmlFile.WriteAttr(wxT("version"), wxT(AUDACITY_FILE_FORMAT_VERSION)); xmlFile.WriteAttr(wxT("audacityversion"), AUDACITY_VERSION_STRING); - mViewInfo.selectedRegion - .WriteXMLAttributes(xmlFile, wxT("sel0"), wxT("sel1")); - // PRL: to do: persistence of other fields of the selection - xmlFile.WriteAttr(wxT("vpos"), mViewInfo.vpos); - xmlFile.WriteAttr(wxT("h"), mViewInfo.h, 10); - xmlFile.WriteAttr(wxT("zoom"), mViewInfo.zoom, 10); + + mViewInfo.WriteXMLAttributes(xmlFile); xmlFile.WriteAttr(wxT("rate"), mRate); xmlFile.WriteAttr(wxT("snapto"), GetSnapTo() ? wxT("on") : wxT("off")); xmlFile.WriteAttr(wxT("selectionformat"), GetSelectionFormat()); diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index 4885b64c5..3839c7ab0 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -325,7 +325,7 @@ class GuiWaveTrack; class AdornedRulerPanel; class RulerPanel; class AttachableScrollBar; -struct ViewInfo; +class ViewInfo; #include // to get wxSB_HORIZONTAL // CreateStdButtonSizer defs...should probably move to widgets subdir diff --git a/src/TrackArtist.h b/src/TrackArtist.h index 9173a2f04..49d4e347d 100644 --- a/src/TrackArtist.h +++ b/src/TrackArtist.h @@ -37,7 +37,7 @@ class LabelTrack; class TimeTrack; class TrackList; class Ruler; -struct ViewInfo; +class ViewInfo; #ifndef uchar typedef unsigned char uchar; diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 80800b03c..1918142c4 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -45,7 +45,7 @@ class AudacityProject; class TrackPanelAx; -struct ViewInfo; +class ViewInfo; WX_DEFINE_ARRAY(LWSlider *, LWSliderArray); diff --git a/src/ViewInfo.cpp b/src/ViewInfo.cpp index e69de29bb..041570665 100644 --- a/src/ViewInfo.cpp +++ b/src/ViewInfo.cpp @@ -0,0 +1,66 @@ +/********************************************************************** + +Audacity: A Digital Audio Editor + +ViewInfo.cpp + +Paul Licameli + +**********************************************************************/ + +#include "ViewInfo.h" + +#include "Internat.h" +#include "xml/XMLWriter.h" + +ViewInfo::ViewInfo(double start, double screenDuration, double pixelsPerSecond) + : selectedRegion() + , track(0) + , vpos(0) + , h(start) + , screen(screenDuration) + , total(screen) + , zoom(pixelsPerSecond) + + , sbarH(0) + , sbarScreen(1) + , sbarTotal(1) + , sbarScale(1.0) + , scrollStep(16) + + , bUpdateTrackIndicator(true) +{ +} + +void ViewInfo::WriteXMLAttributes(XMLWriter &xmlFile) +{ + selectedRegion.WriteXMLAttributes(xmlFile, wxT("sel0"), wxT("sel1")); + xmlFile.WriteAttr(wxT("vpos"), vpos); + xmlFile.WriteAttr(wxT("h"), h, 10); + xmlFile.WriteAttr(wxT("zoom"), zoom, 10); +} + +bool ViewInfo::ReadXMLAttribute(const wxChar *attr, const wxChar *value) +{ + if (selectedRegion.HandleXMLAttribute(attr, value, wxT("sel0"), wxT("sel1"))) + return true; + + if (!wxStrcmp(attr, wxT("vpos"))) { + long longVpos; + wxString(value).ToLong(&longVpos); + vpos = int(longVpos); + return true; + } + + if (!wxStrcmp(attr, wxT("h"))) { + Internat::CompatibleToDouble(value, &h); + return true; + } + + if (!wxStrcmp(attr, wxT("zoom"))) { + Internat::CompatibleToDouble(value, &zoom); + return true; + } + + return false; +} diff --git a/src/ViewInfo.h b/src/ViewInfo.h index d27965aa3..a39cd296c 100644 --- a/src/ViewInfo.h +++ b/src/ViewInfo.h @@ -18,7 +18,11 @@ const double gMaxZoom = 6000000, class Track; -struct ViewInfo { +class AUDACITY_DLL_API ViewInfo +{ +public: + + ViewInfo(double start, double screenDuration, double pixelsPerSecond); // Current selection @@ -52,6 +56,9 @@ struct ViewInfo { // drawing the waveform. Maybe this should be put somewhere else? bool bUpdateTrackIndicator; + + void WriteXMLAttributes(XMLWriter &xmlFile); + bool ReadXMLAttribute(const wxChar *attr, const wxChar *value); }; #endif diff --git a/src/widgets/AttachableScrollBar.h b/src/widgets/AttachableScrollBar.h index a05f180bd..eb20ea575 100644 --- a/src/widgets/AttachableScrollBar.h +++ b/src/widgets/AttachableScrollBar.h @@ -19,7 +19,7 @@ #include -struct ViewInfo; +class ViewInfo; class AUDACITY_DLL_API AttachableScrollBar : public wxScrollBar diff --git a/src/widgets/Ruler.h b/src/widgets/Ruler.h index d1133f22d..d5b542af3 100644 --- a/src/widgets/Ruler.h +++ b/src/widgets/Ruler.h @@ -19,7 +19,7 @@ #include "../Envelope.h" #include "../Experimental.h" -struct ViewInfo; +class ViewInfo; class AudacityProject; class TimeTrack; class SnapManager;