Skip to content

Commit

Permalink
Slider keyboard interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Dempsey committed Oct 5, 2023
1 parent 328b990 commit 112e8f5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Pedals/Pedals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ void PedalCore::syncAssign(Hc1Module * partner)
void PedalCore::syncValue(Hc1Module * partner)
{
auto pq = getParamQuantity(Params::P_PEDAL_VALUE);
auto value = static_cast<uint8_t>(pq->getValue());
auto value = static_cast<uint8_t>(std::round(pq->getValue()));
if (value != last_pedal_value) {
last_pedal_value = value;
if (!partner->readyToSend()) return;
PedalInfo & pedal = partner->getPedal(pedal_id);
partner->sendControlChange(0, pedal.cc, value);
}
Expand All @@ -113,11 +114,12 @@ void PedalCore::process(const ProcessArgs& args)
{
auto partner = getPartner();
if (!partner) return;
if (!partner->readyToSend()) return;

auto pedal = partner->getPedal(pedal_id);
getOutput(Outputs::O_PEDAL_VALUE).setVoltage(10.f * pedal.value / 127);

if (!partner->readyToSend()) return;
if (getOutput(Outputs::O_PEDAL_VALUE).isConnected()) {
getOutput(Outputs::O_PEDAL_VALUE).setVoltage(10.f * pedal.value / 127);
}

if (++check_cv > CV_INTERVAL) {
check_cv = 0;
Expand Down
89 changes: 89 additions & 0 deletions src/widgets/vert_slider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct VerticalSlider : SvgSlider
FillRect(args.vg, 1.5f, break_pos, box.size.x - 3.f, box.size.y - break_pos, value_bg);
}
};

VerticalSlider()
{
setBackgroundSvg(Svg::load(asset::plugin(pluginInstance, "res/VertSlider_bg.svg")));
Expand All @@ -31,6 +32,94 @@ struct VerticalSlider : SvgSlider
fb->addChildBelow(fill, handle);
handle->box.pos.y = 198.f;
}

void onHover(const HoverEvent& e) override
{
e.consume(this);
}
void onEnter(const EnterEvent& e) override {
APP->event->setSelectedWidget(this);
e.consume(this);
}
void onLeave(const LeaveEvent& e) override {
APP->event->setSelectedWidget(nullptr);
SvgSlider::onLeave(e);
}

void onSelectKey(const SelectKeyEvent& e) override
{
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT)
{
auto pq = getParamQuantity();
if (pq)
{
bool plain = (e.action != GLFW_REPEAT) && ((e.mods & RACK_MOD_MASK) == 0);
bool shift = e.mods & GLFW_MOD_SHIFT;
// bool ctrl = e.mods & GLFW_MOD_CONTROL;
switch (e.key)
{
case GLFW_KEY_0:
pq->setValue(pq->getMaxValue());
e.consume(this);
break;
case GLFW_KEY_1: case GLFW_KEY_2: case GLFW_KEY_3: case GLFW_KEY_4:
case GLFW_KEY_5: case GLFW_KEY_6: case GLFW_KEY_7: case GLFW_KEY_8: case GLFW_KEY_9:
pq->setValue(14.1f * (e.key - GLFW_KEY_1));
e.consume(this);
break;

case GLFW_KEY_HOME:
if (plain) {
pq->setValue(pq->getMaxValue());
e.consume(this);
}
break;
case GLFW_KEY_END:
if (plain) {
pq->setValue(pq->getMinValue());
e.consume(this);
}
break;
case GLFW_KEY_UP:
pq->setValue(pq->getValue() + (shift ? 10.f : 1.f));
e.consume(this);
break;
case GLFW_KEY_DOWN:
pq->setValue(pq->getValue() - (shift ? 10.f : 1.f));
e.consume(this);
break;
case GLFW_KEY_PAGE_UP:
pq->setValue(pq->getValue() + 10.f);
e.consume(this);
break;
case GLFW_KEY_PAGE_DOWN:
pq->setValue(pq->getValue() - 10.f);
e.consume(this);
break;
}
}
}
if (e.isConsumed())
return;
SvgSlider::onSelectKey(e);
}

void onHoverScroll(const HoverScrollEvent & e) override
{
auto pq = getParamQuantity();
if (pq) {
auto dx = e.scrollDelta;
auto mods = APP->window->getMods();
if (dx.y < 0.f) {
pq->setValue(pq->getValue() - ((mods & GLFW_MOD_SHIFT) ? 10.f : 1.f));
} else if (dx.y > 0.f) {
pq->setValue(pq->getValue() + ((mods & GLFW_MOD_SHIFT) ? 10.f : 1.f));
}
e.consume(this);
} else {
SvgSlider::onHoverScroll(e);
}
}
};


Expand Down

0 comments on commit 112e8f5

Please sign in to comment.