Quick question: GLFW_RELEASE code?

Hello! I have this chunk of code. GLFW_PRESS works, but GLFW_RELEASE doesn’t seem to be working.

  void onButton(const event::Button &e) override
  {
    Scalar110 *module = dynamic_cast<Scalar110*>(this->module);

    if(module)
    {
      if(e.button == GLFW_MOUSE_BUTTON_LEFT)
      {
        if(e.action == GLFW_PRESS) module->setLCDFunction(LCD_ENGINE_DISPLAY);
        if(e.action == GLFW_RELEASE) module->selectLCDFunctionSelectedParam();
      }

    }
    RoundBlackKnob::onButton(e);
  }


Here’s the entire code. Any suggestions?

struct EngineKnob : RoundBlackKnob
{
  void onButton(const event::Button &e) override
  {
    Scalar110 *module = dynamic_cast<Scalar110*>(this->module);

    if(module)
    {
      if(e.button == GLFW_MOUSE_BUTTON_LEFT)
      {
        if(e.action == GLFW_PRESS) module->setLCDFunction(LCD_ENGINE_DISPLAY);
        if(e.action == GLFW_RELEASE) module->selectLCDFunctionSelectedParam();
      }

    }
    RoundBlackKnob::onButton(e);
  }

  void onLeave(const LeaveEvent &e) override
  {
    Scalar110 *module = dynamic_cast<Scalar110*>(this->module);

    if(module)
    {
      module->selectLCDFunctionSelectedParam();
    }
  }

  void onHover(const event::Hover& e) override
  {
		RoundBlackKnob::onHover(e);
		e.consume(this);
	}
};

I’d like to bump this! I’m stuck. I’ve run further tests and it appears that OnButton is not called for mouse-release events.

Here’s what I’m trying to accomplish: I have a virtual “LCD Screen”. When the user is interacting with a knob, I want the LCD screen to show something. However, then they stop, I want the LCD screen to show something else.

image

I’m using onLeave() to detect when the user has stopped interacting with the knob, but ideally I would use a mouse-release event.

Is this simply a limitation of VCV Rack? This would seem odd since GLFW_RELEASE is mentioned as possible widget button events (VCV Rack API: rack::widget::Widget::ButtonEvent Struct Reference)

Thanks!

I’m not an expert on the API, but I put your code into a custom knob class of mine and noticed that it doesn’t work either. I would perhaps use this instead:

void onDragEnd(const DragEndEvent& e) override {
  if(e.button == GLFW_MOUSE_BUTTON_LEFT)
  {
    // put your code to handle the mouse release event here
  }
  RoundBlackKnob::onDragEnd(e);
}

That appears to be reliably called on mouse release.

1 Like

@nickfeisst Awesome work-around! Thanks!

1 Like