Browse Source

Add hysteresis to Switch in momentary mode

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
0ab5152030
3 changed files with 25 additions and 8 deletions
  1. +4
    -0
      include/app/Switch.hpp
  2. +17
    -4
      src/app/Switch.cpp
  3. +4
    -4
      src/main.cpp

+ 4
- 0
include/app/Switch.hpp View File

@@ -10,7 +10,11 @@ namespace rack {
struct Switch : ParamWidget {
/** Return to original position when released */
bool momentary = false;
/** Hysteresis state for momentary switch */
bool momentaryPressed = false;
bool momentaryReleased = false;

void step() override;
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
};


+ 17
- 4
src/app/Switch.cpp View File

@@ -7,11 +7,27 @@
namespace rack {


void Switch::step() {
if (momentaryPressed) {
momentaryPressed = false;
// Wait another frame.
}
else if (momentaryReleased) {
momentaryReleased = false;
if (paramQuantity) {
// Set to minimum value
paramQuantity->setMin();
}
}
ParamWidget::step();
}

void Switch::onDragStart(const event::DragStart &e) {
if (momentary) {
if (paramQuantity) {
// Set to maximum value
paramQuantity->setMax();
momentaryPressed = true;
}
}
else {
@@ -41,10 +57,7 @@ void Switch::onDragStart(const event::DragStart &e) {

void Switch::onDragEnd(const event::DragEnd &e) {
if (momentary) {
if (paramQuantity) {
// Set to minimum value
paramQuantity->setMin();
}
momentaryReleased = true;
}
}



+ 4
- 4
src/main.cpp View File

@@ -77,7 +77,7 @@ int main(int argc, char *argv[]) {
gamepad::init();
ui::init();
plugin::init(devMode);
INFO("Initialized environment")
INFO("Initialized environment");

// Initialize app
appInit();
@@ -105,7 +105,7 @@ int main(int argc, char *argv[]) {
app()->scene->rackWidget->load(patchFile);
app()->scene->rackWidget->lastPath = patchFile;
}
INFO("Initialized app")
INFO("Initialized app");

app()->engine->start();
app()->window->run();
@@ -116,14 +116,14 @@ int main(int argc, char *argv[]) {
app()->scene->rackWidget->save(asset::user("autosave.vcv"));
settings::save(asset::user("settings.json"));
appDestroy();
INFO("Cleaned up app")
INFO("Cleaned up app");

// Destroy environment
plugin::destroy();
ui::destroy();
bridgeDestroy();
midi::destroy();
INFO("Cleaned up environment")
INFO("Cleaned up environment");
logger::destroy();

return 0;


Loading…
Cancel
Save