@@ -117,7 +117,7 @@ Plugin *pluginInstance; | |||||
void init(Plugin *p) { | void init(Plugin *p) { | ||||
pluginInstance = p; | pluginInstance = p; | ||||
// Add modules here, e.g. | |||||
// Add modules here | |||||
// p->addModel(modelMyModule); | // p->addModel(modelMyModule); | ||||
// Any other plugin initialization may go here. | // Any other plugin initialization may go here. | ||||
@@ -397,6 +397,7 @@ struct {identifier} : Module {{""" | |||||
source += f""" | source += f""" | ||||
struct {identifier}Widget : ModuleWidget {{ | struct {identifier}Widget : ModuleWidget {{ | ||||
{identifier}Widget({identifier} *module) {{ | {identifier}Widget({identifier} *module) {{ | ||||
setModule(module); | setModule(module); | ||||
@@ -176,16 +176,16 @@ struct EditButton : MenuButton { | |||||
struct ZoomQuantity : Quantity { | struct ZoomQuantity : Quantity { | ||||
void setValue(float value) override { | void setValue(float value) override { | ||||
settings::zoom = math::clamp(value, getMinValue(), getMaxValue()); | |||||
settings::zoom = value; | |||||
} | } | ||||
float getValue() override { | float getValue() override { | ||||
return settings::zoom; | return settings::zoom; | ||||
} | } | ||||
float getMinValue() override {return 0.25;} | |||||
float getMinValue() override {return -2.0;} | |||||
float getMaxValue() override {return 2.0;} | float getMaxValue() override {return 2.0;} | ||||
float getDefaultValue() override {return 1.0;} | |||||
float getDisplayValue() override {return std::round(getValue() * 100);} | |||||
void setDisplayValue(float displayValue) override {setValue(displayValue / 100);} | |||||
float getDefaultValue() override {return 0.0;} | |||||
float getDisplayValue() override {return std::round(std::pow(2.f, getValue()) * 100);} | |||||
void setDisplayValue(float displayValue) override {setValue(std::log2(displayValue / 100));} | |||||
std::string getLabel() override {return "Zoom";} | std::string getLabel() override {return "Zoom";} | ||||
std::string getUnit() override {return "%";} | std::string getUnit() override {return "%";} | ||||
}; | }; | ||||
@@ -22,9 +22,9 @@ RackScrollWidget::RackScrollWidget() { | |||||
void RackScrollWidget::step() { | void RackScrollWidget::step() { | ||||
// Clamp zoom | // Clamp zoom | ||||
settings::zoom = math::clamp(settings::zoom, 0.25f, 2.f); | |||||
// Round zoom to nearest percent | |||||
float zoom = std::round(settings::zoom / 0.01) * 0.01; | |||||
settings::zoom = math::clamp(settings::zoom, -2.f, 2.f); | |||||
// Compute zoom from exponential zoom | |||||
float zoom = std::pow(2.f, settings::zoom); | |||||
if (zoom != zoomWidget->zoom) { | if (zoom != zoomWidget->zoom) { | ||||
// Set offset based on zoomPos | // Set offset based on zoomPos | ||||
offset = offset.plus(zoomPos).div(zoomWidget->zoom).mult(zoom).minus(zoomPos); | offset = offset.plus(zoomPos).div(zoomWidget->zoom).mult(zoom).minus(zoomPos); | ||||
@@ -123,7 +123,7 @@ void RackScrollWidget::onHoverScroll(const event::HoverScroll &e) { | |||||
float zoomDelta = e.scrollDelta.y / 50 / 4; | float zoomDelta = e.scrollDelta.y / 50 / 4; | ||||
if (settings::invertZoom) | if (settings::invertZoom) | ||||
zoomDelta *= -1; | zoomDelta *= -1; | ||||
settings::zoom *= std::pow(2, zoomDelta); | |||||
settings::zoom += zoomDelta; | |||||
zoomPos = e.pos; | zoomPos = e.pos; | ||||
e.consume(this); | e.consume(this); | ||||
return; | return; | ||||
@@ -122,21 +122,21 @@ void Scene::onHoverKey(const event::HoverKey &e) { | |||||
} break; | } break; | ||||
case GLFW_KEY_MINUS: { | case GLFW_KEY_MINUS: { | ||||
if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | ||||
float z = std::log2(settings::zoom); | |||||
z *= 2; | |||||
z = std::ceil(z - 0.01) - 1; | |||||
z /= 2; | |||||
settings::zoom = std::pow(2, z); | |||||
float zoom = settings::zoom; | |||||
zoom *= 2; | |||||
zoom = std::ceil(zoom - 0.01) - 1; | |||||
zoom /= 2; | |||||
settings::zoom = zoom; | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} break; | } break; | ||||
case GLFW_KEY_EQUAL: { | case GLFW_KEY_EQUAL: { | ||||
if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | ||||
float z = std::log2(settings::zoom); | |||||
z *= 2; | |||||
z = std::floor(z + 0.01) + 1; | |||||
z /= 2; | |||||
settings::zoom = std::pow(2, z); | |||||
float zoom = settings::zoom; | |||||
zoom *= 2; | |||||
zoom = std::floor(zoom + 0.01) + 1; | |||||
zoom /= 2; | |||||
settings::zoom = zoom; | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} break; | } break; | ||||