Browse Source

Add Knob::smooth variable for disabling param smoothing. Clean up various code.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
ad69fc648a
8 changed files with 48 additions and 20 deletions
  1. +1
    -0
      include/app/Knob.hpp
  2. +4
    -2
      include/app/ParamWidget.hpp
  3. +1
    -0
      include/event.hpp
  4. +1
    -1
      src/app/CableWidget.cpp
  5. +7
    -4
      src/app/Knob.cpp
  6. +16
    -0
      src/app/ParamWidget.cpp
  7. +1
    -1
      src/app/SVGSwitch.cpp
  8. +17
    -12
      src/main.cpp

+ 1
- 0
include/app/Knob.hpp View File

@@ -12,6 +12,7 @@ struct Knob : ParamWidget {
/** Multiplier for mouse movement to adjust knob value */
float speed = 1.0;
float oldValue = 0.f;
bool smooth = true;
/** Enable snapping at integer values */
bool snap = false;
float snapValue = NAN;


+ 4
- 2
include/app/ParamWidget.hpp View File

@@ -16,11 +16,13 @@ struct ParamWidget : OpaqueWidget {

~ParamWidget();
void step() override;
/** For legacy patch loading */
void fromJson(json_t *rootJ);
void draw(NVGcontext *vg) override;
void onButton(const event::Button &e) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;

/** For legacy patch loading */
void fromJson(json_t *rootJ);
};




+ 1
- 0
include/event.hpp View File

@@ -52,6 +52,7 @@ struct Key {
int mods;
};

// Events

struct Text {
/** Unicode code point of the character */


+ 1
- 1
src/app/CableWidget.cpp View File

@@ -183,7 +183,7 @@ void CableWidget::draw(NVGcontext *vg) {
if (cable && cable->outputModule) {
Output *output = &cable->outputModule->outputs[cable->outputId];
if (output->numChannels != 1) {
thickness = 9;
thickness = 7;
}
}



+ 7
- 4
src/app/Knob.cpp View File

@@ -28,9 +28,9 @@ void Knob::onButton(const event::Button &e) {

void Knob::onDragStart(const event::DragStart &e) {
if (paramQuantity) {
oldValue = paramQuantity->getValue();
oldValue = paramQuantity->getSmoothValue();
if (snap) {
snapValue = oldValue;
snapValue = paramQuantity->getValue();
}
}

@@ -41,7 +41,7 @@ void Knob::onDragEnd(const event::DragEnd &e) {
app()->window->cursorUnlock();

if (paramQuantity) {
float newValue = paramQuantity->getValue();
float newValue = paramQuantity->getSmoothValue();
if (oldValue != newValue) {
// Push ParamChange history action
history::ParamChange *h = new history::ParamChange;
@@ -75,9 +75,12 @@ void Knob::onDragMove(const event::DragMove &e) {
snapValue = math::clamp(snapValue, paramQuantity->getMinValue(), paramQuantity->getMaxValue());
paramQuantity->setValue(std::round(snapValue));
}
else {
else if (smooth) {
paramQuantity->setSmoothValue(paramQuantity->getSmoothValue() + delta);
}
else {
paramQuantity->setValue(paramQuantity->getValue() + delta);
}
}

ParamWidget::onDragMove(e);


+ 16
- 0
src/app/ParamWidget.cpp View File

@@ -93,6 +93,22 @@ void ParamWidget::step() {
OpaqueWidget::step();
}

void ParamWidget::draw(NVGcontext *vg) {
Widget::draw(vg);

if (paramQuantity) {
nvgBeginPath(vg);
nvgRect(vg,
box.size.x - 12, box.size.y - 12,
12, 12);
nvgFillColor(vg, nvgRGBAf(1, 0, 1, 0.9));
nvgFill(vg);

std::string mapText = string::f("%d", paramQuantity->paramId);
bndLabel(vg, box.size.x - 17.0, box.size.y - 16.0, INFINITY, INFINITY, -1, mapText.c_str());
}
}

void ParamWidget::fromJson(json_t *rootJ) {
json_t *valueJ = json_object_get(rootJ, "value");
if (valueJ) {


+ 1
- 1
src/app/SVGSwitch.cpp View File

@@ -24,7 +24,7 @@ void SVGSwitch::addFrame(std::shared_ptr<SVG> svg) {

void SVGSwitch::onChange(const event::Change &e) {
if (!frames.empty() && paramQuantity) {
int index = (int) paramQuantity->getValue();
int index = (int) std::round(paramQuantity->getValue());
index = math::clamp(index, 0, (int) frames.size() - 1);
sw->setSVG(frames[index]);
fb->dirty = true;


+ 17
- 12
src/main.cpp View File

@@ -16,23 +16,23 @@
#include <osdialog.h>

#ifdef ARCH_WIN
#include <Windows.h>
#include <Windows.h>
#endif

using namespace rack;


int main(int argc, char *argv[]) {
#ifdef ARCH_WIN
// Windows global mutex to prevent multiple instances
// Handle will be closed by Windows when the process ends
HANDLE instanceMutex = CreateMutex(NULL, true, APP_NAME.c_str());
if (GetLastError() == ERROR_ALREADY_EXISTS) {
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack is already running. Multiple Rack instances are not supported.");
exit(1);
}
(void) instanceMutex;
#endif
#ifdef ARCH_WIN
// Windows global mutex to prevent multiple instances
// Handle will be closed by Windows when the process ends
HANDLE instanceMutex = CreateMutex(NULL, true, APP_NAME.c_str());
if (GetLastError() == ERROR_ALREADY_EXISTS) {
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack is already running. Multiple Rack instances are not supported.");
exit(1);
}
(void) instanceMutex;
#endif

bool devMode = false;
std::string patchFile;
@@ -59,7 +59,6 @@ int main(int argc, char *argv[]) {
}

// Initialize environment
random::init();
asset::init(devMode);
logger::init(devMode);

@@ -70,6 +69,7 @@ int main(int argc, char *argv[]) {
INFO("System directory: %s", asset::systemDir.c_str());
INFO("User directory: %s", asset::userDir.c_str());

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

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

app()->engine->start();
app()->window->run();
INFO("Window closed");
app()->engine->stop();

// Destroy app
app()->scene->rackWidget->save(asset::user("autosave.vcv"));
settings::save(asset::user("settings.json"));
appDestroy();
INFO("Cleaned up app")

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

return 0;


Loading…
Cancel
Save