Browse Source

Add hysteresis to Switch in momentary mode

tags/v1.0.0
Andrew Belt 6 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 { struct Switch : ParamWidget {
/** Return to original position when released */ /** Return to original position when released */
bool momentary = false; 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 onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override; void onDragEnd(const event::DragEnd &e) override;
}; };


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

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


void Switch::onDragEnd(const event::DragEnd &e) { void Switch::onDragEnd(const event::DragEnd &e) {
if (momentary) { 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(); gamepad::init();
ui::init(); ui::init();
plugin::init(devMode); plugin::init(devMode);
INFO("Initialized environment")
INFO("Initialized environment");


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


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


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


return 0; return 0;


Loading…
Cancel
Save