Merge pull request #599 from jpcima/adjustable-tuning-frequency

Make tuning frequency editable by wheel
This commit is contained in:
JP Cimalando 2021-01-21 22:09:52 +01:00 committed by GitHub
commit ea3c43ca39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 0 deletions

View file

@ -35,5 +35,6 @@ struct EditRange {
constexpr EditRange() = default; constexpr EditRange() = default;
constexpr EditRange(float def, float min, float max) constexpr EditRange(float def, float min, float max)
: def(def), min(min), max(max) {} : def(def), min(min), max(max) {}
float extent() const noexcept { return max - min; }
static EditRange get(EditId id); static EditRange get(EditId id);
}; };

View file

@ -636,6 +636,7 @@ void Editor::Impl::createFrameContents()
static_cast<int>(EditRange::get(EditId::ScalaRootKey).def) / 12); static_cast<int>(EditRange::get(EditId::ScalaRootKey).def) / 12);
} }
adjustMinMaxToEditRange(tuningFrequencySlider_, EditId::TuningFrequency); adjustMinMaxToEditRange(tuningFrequencySlider_, EditId::TuningFrequency);
tuningFrequencySlider_->setWheelInc(0.1f / EditRange::get(EditId::TuningFrequency).extent());
adjustMinMaxToEditRange(stretchedTuningSlider_, EditId::StretchTuning); adjustMinMaxToEditRange(stretchedTuningSlider_, EditId::StretchTuning);
for (int value : {1, 2, 4, 8, 16, 32, 64, 96, 128, 160, 192, 224, 256}) for (int value : {1, 2, 4, 8, 16, 32, 64, 96, 128, 160, 192, 224, 256})

View file

@ -160,6 +160,7 @@ SValueMenu::SValueMenu(const CRect& bounds, IControlListener* listener, int32_t
{ {
setListener(listener); setListener(listener);
setTag(tag); setTag(tag);
setWheelInc(0.0f);
} }
CMenuItem* SValueMenu::addEntry(CMenuItem* item, float value, int32_t index) CMenuItem* SValueMenu::addEntry(CMenuItem* item, float value, int32_t index)
@ -226,6 +227,24 @@ CMouseEventResult SValueMenu::onMouseDown(CPoint& where, const CButtonState& but
return kMouseEventNotHandled; return kMouseEventNotHandled;
} }
bool SValueMenu::onWheel(const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons)
{
(void)where;
(void)buttons;
if (axis != kMouseWheelAxisY)
return false;
float wheelInc = getWheelInc();
if (wheelInc != 0) {
float oldValue = getValue();
setValueNormalized(getValueNormalized() + distance * wheelInc);
if (getValue() != oldValue)
valueChanged();
}
return true;
}
void SValueMenu::onItemClicked(int32_t index) void SValueMenu::onItemClicked(int32_t index)
{ {
float oldValue = getValue(); float oldValue = getValue();

View file

@ -94,6 +94,7 @@ public:
protected: protected:
CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
bool onWheel(const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override;
private: private:
class MenuListener; class MenuListener;