From 0d6eb0995823320ce28840bf7f84a445079bf387 Mon Sep 17 00:00:00 2001 From: xenakios Date: Fri, 2 Mar 2018 22:49:32 +0200 Subject: [PATCH] Attempt implementing mousewheel zoom into waveform. Badly. --- Source/PluginEditor.cpp | 23 +++++++++++++++++++++++ Source/PluginEditor.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index fe1f74d..312cc9f 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -104,6 +104,10 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau }; m_zs.setRange(processor.m_wave_view_range, true); + m_wavecomponent.ViewRangeChangedCallback = [this](Range rng) + { + m_zs.setRange(rng, false); + }; m_wavecomponent.TimeSelectionChangedCallback = [this](Range range, int which) { *processor.getFloatParameter(cpi_soundstart) = range.getStart(); @@ -745,6 +749,25 @@ void WaveformComponent::mouseDoubleClick(const MouseEvent & e) repaint(); } +void WaveformComponent::mouseWheelMove(const MouseEvent & e, const MouseWheelDetails & wd) +{ + double factor = 0.9; + if (wd.deltaY < 0.0) + factor = 1.11111; + double normt = viewXToNormalized(e.x); + double curlen = m_view_range.getLength(); + double newlen = curlen * factor; + double t0 = jlimit(0.0,1.0, normt - newlen / 2.0); + double t1 = jlimit(0.0,1.0, normt + newlen / 2.0); + m_view_range = { t0,t1 }; + //m_view_range = m_view_range.constrainRange({ 0.0, 1.0 }); + jassert(m_view_range.getStart() >= 0.0 && m_view_range.getEnd() <= 1.0); + if (ViewRangeChangedCallback) + ViewRangeChangedCallback(m_view_range); + m_image_dirty = true; + repaint(); +} + Range WaveformComponent::getTimeSelection() { if (m_time_sel_start >= 0.0 && m_time_sel_end>m_time_sel_start + 0.001) diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 521ec94..e8c55a7 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -134,11 +134,13 @@ public: std::function SeekCallback; std::function, int)> TimeSelectionChangedCallback; std::function GetFileCallback; + std::function)> ViewRangeChangedCallback; void mouseDown(const MouseEvent& e) override; void mouseUp(const MouseEvent& e) override; void mouseDrag(const MouseEvent& e) override; void mouseMove(const MouseEvent& e) override; void mouseDoubleClick(const MouseEvent& e) override; + void mouseWheelMove(const MouseEvent& e, const MouseWheelDetails& wd) override; Range getTimeSelection(); void setTimeSelection(Range rng); void setFileCachedRange(std::pair, Range> rng);