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

Zoom Toggle

Added preferences for Zoom-Toggle and put into menus.
New helper functions for determining zoom scaling.

Optional EXPERIMENTAL_ZOOM_TOGGLE_BUTTON added, and Light theme updated.
Not enabled for 2.2.2.
This commit is contained in:
James Crook 2018-01-04 15:56:15 +00:00
parent f57fdc99d7
commit 0cc9c6bc3b
13 changed files with 3680 additions and 3555 deletions

View File

@ -91,6 +91,9 @@
// This turns on the Theme panel in Prefs dialog. It is independent of EXPERIMENTAL_THEMING.
//#define EXPERIMENTAL_THEME_PREFS
// This shows the zoom toggle button on the edit toolbar.
//#define EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
//Next line enables Mic monitoring at times when it was previously off.
//More work is needed as after recording or playing it results in an
//unwanted record-cursor on the wave track.

File diff suppressed because it is too large Load Diff

View File

@ -719,7 +719,12 @@ void AudacityProject::CreateMenusAndCommands()
c->AddItem(wxT("ZoomOut"), _("Zoom &Out"), FN(OnZoomOut), wxT("Ctrl+3"),
ZoomOutAvailableFlag,
ZoomOutAvailableFlag);
c->AddItem(wxT("ZoomSel"), _("&Zoom to Selection"), FN(OnZoomSel), wxT("Ctrl+E"), TimeSelectedFlag, TimeSelectedFlag);
c->AddItem(wxT("ZoomSel"), _("&Zoom to Selection"), FN(OnZoomSel), wxT("Ctrl+E"),
TimeSelectedFlag,
TimeSelectedFlag);
c->AddItem(wxT("ZoomToggle"), _("Zoom &Toggle"), FN(OnZoomToggle), wxT(""),
TracksExistFlag,
TracksExistFlag);
c->EndSubMenu();
c->BeginSubMenu(_("T&rack Size"));
@ -6530,29 +6535,25 @@ void AudacityProject::ZoomOutByFactor( double ZoomFactor )
TP_ScrollWindow(newh);
}
// this is unused:
#if 0
static double OldZooms[2]={ 44100.0/512.0, 4410.0/512.0 };
void AudacityProject::OnZoomToggle()
void AudacityProject::OnZoomToggle(const CommandContext &)
{
double origLeft = mViewInfo.h;
double origWidth = mViewInfo.screen;
// const double origLeft = mViewInfo.h;
// const double origWidth = GetScreenEndTime() - origLeft;
float f;
// look at percentage difference. We add a small fudge factor
// to avoid testing for zero divisor.
f = mViewInfo.zoom / (OldZooms[0] + 0.0001f);
// If old zoom is more than 10 percent different, use it.
if( (0.90f > f) || (f >1.10) ){
OldZooms[1]=OldZooms[0];
OldZooms[0]=mViewInfo.zoom;
}
Zoom( OldZooms[1] );
double newh = origLeft + (origWidth - mViewInfo.screen) / 2;
TP_ScrollWindow(newh);
// Choose the zoom that is most different to the current zoom.
double Zoom1 = GetZoomOfPref(
wxT("/GUI/ZoomPreset1"), WaveTrack::kZoomDefault );
double Zoom2 = GetZoomOfPref(
wxT("/GUI/ZoomPreset2"), WaveTrack::kZoom4To1 );
double Z = mViewInfo.GetZoom();// Current Zoom.
double ChosenZoom = abs(log(Zoom1 / Z)) > abs(log( Z / Zoom2)) ? Zoom1:Zoom2;
Zoom(ChosenZoom);
mTrackPanel->Refresh(false);
// const double newWidth = GetScreenEndTime() - mViewInfo.h;
// const double newh = origLeft + (origWidth - newWidth) / 2;
// TP_ScrollWindow(newh);
}
#endif
void AudacityProject::OnZoomNormal(const CommandContext &)
@ -6563,20 +6564,11 @@ void AudacityProject::OnZoomNormal(const CommandContext &)
void AudacityProject::OnZoomFit(const CommandContext &)
{
const double end = mTracks->GetEndTime();
const double start = mViewInfo.bScrollBeyondZero
? std::min(mTracks->GetStartTime(), 0.0)
: 0;
const double len = end - start;
if (len <= 0.0)
return;
int w;
mTrackPanel->GetTracksUsableArea(&w, NULL);
w -= 10;
Zoom(w / len);
Zoom( GetZoomOfToFit() );
TP_ScrollWindow(start);
}
@ -6628,26 +6620,7 @@ void AudacityProject::OnZoomFitV(const CommandContext &)
void AudacityProject::OnZoomSel(const CommandContext &)
{
const double lowerBound =
std::max(mViewInfo.selectedRegion.t0(), ScrollingLowerBoundTime());
const double denom =
mViewInfo.selectedRegion.t1() - lowerBound;
if (denom <= 0.0)
return;
// LL: The "-1" is just a hack to get around an issue where zooming to
// selection doesn't actually get the entire selected region within the
// visible area. This causes a problem with scrolling at end of playback
// where the selected region may be scrolled off the left of the screen.
// I know this isn't right, but until the real rounding or 1-off issue is
// found, this will have to work.
// PRL: Did I fix this? I am not sure, so I leave the hack in place.
// Fixes might have resulted from commits
// 1b8f44d0537d987c59653b11ed75a842b48896ea and
// e7c7bb84a966c3b3cc4b3a9717d5f247f25e7296
int width;
mTrackPanel->GetTracksUsableArea(&width, NULL);
Zoom((width - 1) / denom);
Zoom( GetZoomOfSelection() );
TP_ScrollWindow(mViewInfo.selectedRegion.t0());
}

View File

@ -331,11 +331,9 @@ void OnSelectClip(bool next);
void OnSelectCursorStoredCursor(const CommandContext &);
void OnSelectSyncLockSel(const CommandContext &);
// View Menu
void OnZoomIn(const CommandContext &);
void OnZoomOut(const CommandContext &);
// void OnZoomToggle(const CommandContext &);
void OnZoomToggle(const CommandContext &);
void OnZoomNormal(const CommandContext &);
void OnZoomFit(const CommandContext &);
void OnZoomFitV(const CommandContext &);

View File

@ -5863,6 +5863,96 @@ int AudacityProject::GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels)
return iRecMins;
}
double AudacityProject::GetZoomOfToFit(){
const double end = mTracks->GetEndTime();
const double start = mViewInfo.bScrollBeyondZero
? std::min(mTracks->GetStartTime(), 0.0)
: 0;
const double len = end - start;
if (len <= 0.0)
return mViewInfo.GetZoom();
int w;
mTrackPanel->GetTracksUsableArea(&w, NULL);
w -= 10;
return w/len;
}
double AudacityProject::GetZoomOfSelection(){
const double lowerBound =
std::max(mViewInfo.selectedRegion.t0(), ScrollingLowerBoundTime());
const double denom =
mViewInfo.selectedRegion.t1() - lowerBound;
if (denom <= 0.0)
return mViewInfo.GetZoom();
// LL: The "-1" is just a hack to get around an issue where zooming to
// selection doesn't actually get the entire selected region within the
// visible area. This causes a problem with scrolling at end of playback
// where the selected region may be scrolled off the left of the screen.
// I know this isn't right, but until the real rounding or 1-off issue is
// found, this will have to work.
// PRL: Did I fix this? I am not sure, so I leave the hack in place.
// Fixes might have resulted from commits
// 1b8f44d0537d987c59653b11ed75a842b48896ea and
// e7c7bb84a966c3b3cc4b3a9717d5f247f25e7296
int width;
mTrackPanel->GetTracksUsableArea(&width, NULL);
return (width - 1) / denom;
}
double AudacityProject::GetZoomOfPreset( int preset ){
// Sets a limit on how far we will zoom out as a factor over zoom to fit.
const double maxZoomOutFactor = 4.0;
// Sets how many pixels we allow for one uint, such as seconds.
const double pixelsPerUnit = 5.0;
double result = 1.0;
double zoomToFit = GetZoomOfToFit();
switch( preset ){
default:
case WaveTrack::kZoomDefault:
result = ZoomInfo::GetDefaultZoom();
break;
case WaveTrack::kZoomToFit:
result = zoomToFit;
break;
case WaveTrack::kZoomToSelection:
result = GetZoomOfSelection();
break;
case WaveTrack::kZoomMinutes:
result = pixelsPerUnit * 1.0/60;
break;
case WaveTrack::kZoomSeconds:
result = pixelsPerUnit * 1.0;
break;
case WaveTrack::kZoomMilliSeconds:
result = pixelsPerUnit * 1000.0;
break;
case WaveTrack::kZoomSamples:
result = 44100.0;
break;
case WaveTrack::kZoom4To1:
result = 44100.0 * 4;
break;
case WaveTrack::kMaxZoom:
result = ZoomInfo::GetMaxZoom();
break;
};
if( result < (zoomToFit/maxZoomOutFactor) )
result = zoomToFit / maxZoomOutFactor;
return result;
}
double AudacityProject::GetZoomOfPref( const wxString & PresetPrefName, int defaultPreset ){
int preset=defaultPreset;
gPrefs->Read( PresetPrefName, &preset, defaultPreset );
return GetZoomOfPreset( preset );
}
AudacityProject::PlaybackScroller::PlaybackScroller(AudacityProject *project)
: mProject(project)
{

View File

@ -576,6 +576,11 @@ public:
void AutoSave();
void DeleteCurrentAutoSaveFile();
double GetZoomOfToFit();
double GetZoomOfSelection();
double GetZoomOfPreset(int preset );
double GetZoomOfPref( const wxString & PresetPrefName, int defaultPreset );
public:
bool IsSoloSimple() const { return mSoloPref == wxT("Simple"); }
bool IsSoloNone() const { return mSoloPref == wxT("None"); }

View File

@ -87,6 +87,10 @@ bool ZoomInfo::ZoomOutAvailable() const
return zoom > gMinZoom;
}
double ZoomInfo::GetZoom( ){ return zoom;};
double ZoomInfo::GetMaxZoom( ){ return gMaxZoom;};
double ZoomInfo::GetMinZoom( ){ return gMinZoom;};
void ZoomInfo::SetZoom(double pixelsPerSecond)
{
zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));

View File

@ -90,6 +90,9 @@ public:
// Limits zoom to certain bounds
void SetZoom(double pixelsPerSecond);
double GetZoom();
static double GetMaxZoom( );
static double GetMinZoom( );
// Limits zoom to certain bounds
// multipliers above 1.0 zoom in, below out

View File

@ -577,10 +577,23 @@ class AUDACITY_DLL_API WaveTrack final : public PlayableTrack {
// Only two types of sample display for now, but
// others (eg sinc interpolation) may be added later.
enum SampleDisplay {
LinarInterpolate = 0,
LinearInterpolate = 0,
StemPlot
};
// Various preset zooming levels.
enum ZoomPresets {
kZoomToFit = 0,
kZoomToSelection,
kZoomDefault,
kZoomMinutes,
kZoomSeconds,
kZoomMilliSeconds,
kZoomSamples,
kZoom4To1,
kMaxZoom,
};
// Read appropriate value from preferences
static WaveTrackDisplay FindDefaultViewMode();

View File

@ -80,12 +80,33 @@ void TracksPrefs::Populate()
// How samples are displayed when zoomed in:
mSampleDisplayChoice.Add(_("Connect dots"));
mSampleDisplayCodes.Add((int) WaveTrack::LinarInterpolate);
mSampleDisplayChoices.Add(_("Connect dots"));
mSampleDisplayCodes.Add((int) WaveTrack::LinearInterpolate);
mSampleDisplayChoice.Add(_("Stem plot"));
mSampleDisplayChoices.Add(_("Stem plot"));
mSampleDisplayCodes.Add((int) WaveTrack::StemPlot);
mZoomChoices.Add( _("Zoom to Fit") );
mZoomCodes.Add( WaveTrack::kZoomToFit );
mZoomChoices.Add( _("Zoom to Selection") );
mZoomCodes.Add( WaveTrack::kZoomToSelection );
mZoomChoices.Add( _("Zoom Default") );
mZoomCodes.Add( WaveTrack::kZoomDefault );
mZoomChoices.Add( _("Minutes") );
mZoomCodes.Add( WaveTrack::kZoomMinutes );
mZoomChoices.Add( _("Seconds") );
mZoomCodes.Add( WaveTrack::kZoomSeconds );
mZoomChoices.Add( _("MilliSeconds") );
mZoomCodes.Add( WaveTrack::kZoomMilliSeconds );
mZoomChoices.Add( _("Samples") );
mZoomCodes.Add( WaveTrack::kZoomSamples );
mZoomChoices.Add( _("4 Pixels per Sample") );
mZoomCodes.Add( WaveTrack::kZoom4To1 );
mZoomChoices.Add( _("Max Zoom") );
mZoomCodes.Add( WaveTrack::kMaxZoom );
//------------------------- Main section --------------------
// Now construct the GUI itself.
// Use 'eIsCreatingFromPrefs' so that the GUI is
@ -125,9 +146,9 @@ void TracksPrefs::PopulateOrExchange(ShuttleGui & S)
S.TieChoice(_("Display &samples:"),
wxT("/GUI/SampleView"),
1,
mSampleDisplayChoice,
mSampleDisplayChoices,
mSampleDisplayCodes);
S.SetSizeHints(mSampleDisplayChoice);
S.SetSizeHints(mSampleDisplayChoices);
S.TieTextBox(_("Default audio track &name:"),
wxT("/GUI/TrackNames/DefaultTrackName"),
@ -141,6 +162,27 @@ void TracksPrefs::PopulateOrExchange(ShuttleGui & S)
false);
}
S.EndStatic();
S.StartStatic(_("Zoom-Toggle"));
{
S.StartMultiColumn(4);
{
S.TieChoice(_("Preset 1:"),
wxT("/GUI/ZoomPreset1"),
WaveTrack::kZoomDefault,
mZoomChoices,
mZoomCodes);
S.SetSizeHints(mZoomChoices);
S.TieChoice(_("Preset 2:"),
wxT("/GUI/ZoomPreset2"),
WaveTrack::kZoom4To1,
mZoomChoices,
mZoomCodes);
S.SetSizeHints(mZoomChoices);
}
}
S.EndStatic();
}
bool TracksPrefs::GetPinnedHeadPreference()

View File

@ -44,7 +44,9 @@ class TracksPrefs final : public PrefsPanel
wxArrayInt mViewCodes;
wxArrayString mViewChoices;
wxArrayInt mSampleDisplayCodes;
wxArrayString mSampleDisplayChoice;
wxArrayString mSampleDisplayChoices;
wxArrayInt mZoomCodes;
wxArrayString mZoomChoices;
};
class TracksPrefsFactory final : public PrefsPanelFactory

View File

@ -160,6 +160,11 @@ void EditToolBar::Populate()
AddButton(bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
_("Zoom Out"));
#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
AddButton(bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
_("Zoom Toggle"));
#endif
AddButton(bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
_("Fit selection in window"));
AddButton(bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
@ -167,6 +172,9 @@ void EditToolBar::Populate()
mButtons[ETBZoomInID]->SetEnabled(false);
mButtons[ETBZoomOutID]->SetEnabled(false);
#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
mButtons[ETBZoomToggleID]->SetEnabled(false);
#endif
mButtons[ETBZoomSelID]->SetEnabled(false);
mButtons[ETBZoomFitID]->SetEnabled(false);
@ -226,6 +234,9 @@ static const struct Entry {
{ ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
{ ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
{ ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
#endif
{ ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection in window") },
{ ETBZoomFitID, wxT("FitInWindow"), XO("Fit project in window") },

View File

@ -48,10 +48,9 @@ enum {
ETBZoomInID,
ETBZoomOutID,
#if 0 // Disabled for version 1.2.0 since it doesn't work quite right...
#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
ETBZoomToggleID,
#endif
#endif
ETBZoomSelID,
ETBZoomFitID,