Skip to content

Commit

Permalink
Merge pull request #1843 from ywwg/fractional-zoom
Browse files Browse the repository at this point in the history
Allow waveform zoom levels to be fractional for smoother zooming with mouse wheel
  • Loading branch information
Be-ing authored Dec 26, 2018
2 parents db3dfc6 + 82bc3d7 commit c2102a5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/preferences/dialog/dlgprefwaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void DlgPrefWaveform::slotUpdate() {
midVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::Mid));
highVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::High));
normalizeOverviewCheckBox->setChecked(factory->isOverviewNormalized());
defaultZoomComboBox->setCurrentIndex(factory->getDefaultZoom() - 1);
// Round zoom to int to get a default zoom index.
defaultZoomComboBox->setCurrentIndex(static_cast<int>(factory->getDefaultZoom()) - 1);
playMarkerPositionSlider->setValue(factory->getPlayMarkerPosition() * 100);
beatGridAlphaSpinBox->setValue(factory->beatGridAlpha());
beatGridAlphaSlider->setValue(factory->beatGridAlpha());
Expand Down
8 changes: 4 additions & 4 deletions src/waveform/renderers/waveformwidgetrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "util/math.h"
#include "util/performancetimer.h"

const int WaveformWidgetRenderer::s_waveformMinZoom = 1;
const int WaveformWidgetRenderer::s_waveformMaxZoom = 10;
const int WaveformWidgetRenderer::s_waveformDefaultZoom = 3;
const double WaveformWidgetRenderer::s_waveformMinZoom = 1.0;
const double WaveformWidgetRenderer::s_waveformMaxZoom = 10.0;
const double WaveformWidgetRenderer::s_waveformDefaultZoom = 3.0;
const double WaveformWidgetRenderer::s_defaultPlayMarkerPosition = 0.5;

WaveformWidgetRenderer::WaveformWidgetRenderer(const char* group)
Expand Down Expand Up @@ -288,7 +288,7 @@ void WaveformWidgetRenderer::setup(
}
}

void WaveformWidgetRenderer::setZoom(int zoom) {
void WaveformWidgetRenderer::setZoom(double zoom) {
//qDebug() << "WaveformWidgetRenderer::setZoom" << zoom;
m_zoomFactor = math_clamp<double>(zoom, s_waveformMinZoom, s_waveformMaxZoom);
}
Expand Down
8 changes: 4 additions & 4 deletions src/waveform/renderers/waveformwidgetrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class VSyncThread;

class WaveformWidgetRenderer {
public:
static const int s_waveformMinZoom;
static const int s_waveformMaxZoom;
static const int s_waveformDefaultZoom;
static const double s_waveformMinZoom;
static const double s_waveformMaxZoom;
static const double s_waveformDefaultZoom;
static const double s_defaultPlayMarkerPosition;

public:
Expand All @@ -43,7 +43,7 @@ class WaveformWidgetRenderer {
double getFirstDisplayedPosition() const { return m_firstDisplayedPosition;}
double getLastDisplayedPosition() const { return m_lastDisplayedPosition;}

void setZoom(int zoom);
void setZoom(double zoom);

void setDisplayBeatGrid(bool set);
void setDisplayBeatGridAlpha(int alpha);
Expand Down
10 changes: 5 additions & 5 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ bool WaveformWidgetFactory::setConfig(UserSettingsPointer config) {
int vsync = m_config->getValue(ConfigKey("[Waveform]","VSync"), 0);
setVSyncType(vsync);

int defaultZoom = m_config->getValueString(ConfigKey("[Waveform]","DefaultZoom")).toInt(&ok);
double defaultZoom = m_config->getValueString(ConfigKey("[Waveform]","DefaultZoom")).toDouble(&ok);
if (ok) {
setDefaultZoom(defaultZoom);
} else{
Expand Down Expand Up @@ -431,7 +431,7 @@ bool WaveformWidgetFactory::setWidgetTypeFromHandle(int handleIndex) {
WaveformWidgetAbstract* previousWidget = holder.m_waveformWidget;
TrackPointer pTrack = previousWidget->getTrackInfo();
//previousWidget->hold();
int previousZoom = previousWidget->getZoomFactor();
double previousZoom = previousWidget->getZoomFactor();
double previousPlayMarkerPosition = previousWidget->getPlayMarkerPosition();
delete previousWidget;
WWaveformViewer* viewer = holder.m_waveformViewer;
Expand All @@ -455,7 +455,7 @@ bool WaveformWidgetFactory::setWidgetTypeFromHandle(int handleIndex) {
return true;
}

void WaveformWidgetFactory::setDefaultZoom(int zoom) {
void WaveformWidgetFactory::setDefaultZoom(double zoom) {
m_defaultZoom = math_clamp(zoom, WaveformWidgetRenderer::s_waveformMinZoom,
WaveformWidgetRenderer::s_waveformMaxZoom);
if (m_config) {
Expand All @@ -477,7 +477,7 @@ void WaveformWidgetFactory::setZoomSync(bool sync) {
return;
}

int refZoom = m_waveformWidgetHolders[0].m_waveformWidget->getZoomFactor();
double refZoom = m_waveformWidgetHolders[0].m_waveformWidget->getZoomFactor();
for (int i = 1; i < m_waveformWidgetHolders.size(); i++) {
m_waveformWidgetHolders[i].m_waveformViewer->setZoom(refZoom);
}
Expand Down Expand Up @@ -528,7 +528,7 @@ void WaveformWidgetFactory::notifyZoomChange(WWaveformViewer* viewer) {
WaveformWidgetAbstract* pWaveformWidget = viewer->getWaveformWidget();
if (pWaveformWidget != NULL && isZoomSync()) {
//qDebug() << "WaveformWidgetFactory::notifyZoomChange";
int refZoom = pWaveformWidget->getZoomFactor();
double refZoom = pWaveformWidget->getZoomFactor();

for (int i = 0; i < m_waveformWidgetHolders.size(); ++i) {
WaveformWidgetHolder& holder = m_waveformWidgetHolders[i];
Expand Down
6 changes: 3 additions & 3 deletions src/waveform/waveformwidgetfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac
bool setWidgetTypeFromHandle(int handleIndex);
WaveformWidgetType::Type getType() const { return m_type;}

void setDefaultZoom(int zoom);
int getDefaultZoom() const { return m_defaultZoom;}
void setDefaultZoom(double zoom);
double getDefaultZoom() const { return m_defaultZoom;}

void setZoomSync(bool sync);
int isZoomSync() const { return m_zoomSync;}
Expand Down Expand Up @@ -153,7 +153,7 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac
bool m_skipRender;
int m_frameRate;
int m_endOfTrackWarningTime;
int m_defaultZoom;
double m_defaultZoom;
bool m_zoomSync;
double m_visualGain[FilterCount];
bool m_overviewNormalized;
Expand Down
17 changes: 6 additions & 11 deletions src/widget/wwaveformviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,11 @@ void WWaveformViewer::mouseReleaseEvent(QMouseEvent* /*event*/) {

void WWaveformViewer::wheelEvent(QWheelEvent *event) {
if (m_waveformWidget) {
//NOTE: (vrince) to limit the zoom action area uncomment the following line
//if (event->x() > width() - m_zoomZoneWidth) {
if (event->delta() > 0) {
//qDebug() << "WaveformWidgetRenderer::wheelEvent +1";
onZoomChange(m_waveformWidget->getZoomFactor() + 1);
} else {
//qDebug() << "WaveformWidgetRenderer::wheelEvent -1";
onZoomChange(m_waveformWidget->getZoomFactor() - 1);
}
//}
if (event->delta() > 0) {
onZoomChange(m_waveformWidget->getZoomFactor() * 1.05);
} else {
onZoomChange(m_waveformWidget->getZoomFactor() / 1.05);
}
}
}

Expand Down Expand Up @@ -198,7 +193,7 @@ void WWaveformViewer::onZoomChange(double zoom) {
WaveformWidgetFactory::instance()->notifyZoomChange(this);
}

void WWaveformViewer::setZoom(int zoom) {
void WWaveformViewer::setZoom(double zoom) {
//qDebug() << "WaveformWidgetRenderer::setZoom" << zoom;
if (m_waveformWidget) {
m_waveformWidget->setZoom(zoom);
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wwaveformviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private slots:
return m_waveformWidget;
}
//direct access to let factory sync/set default zoom
void setZoom(int zoom);
void setZoom(double zoom);
void setDisplayBeatGridAlpha(int alpha);
void setPlayMarkerPosition(double position);

Expand Down

0 comments on commit c2102a5

Please sign in to comment.