| @@ -10,7 +10,7 @@ OBJCOPY ?= objcopy | |||||
| FLAGS += -MMD -MP | FLAGS += -MMD -MP | ||||
| FLAGS += -g | FLAGS += -g | ||||
| # Optimization | # Optimization | ||||
| FLAGS += -O3 -march=nocona -ffast-math -fno-finite-math-only | |||||
| FLAGS += -O0 -march=nocona -ffast-math -fno-finite-math-only | |||||
| FLAGS += -Wall -Wextra -Wno-unused-parameter | FLAGS += -Wall -Wextra -Wno-unused-parameter | ||||
| ifneq ($(ARCH), mac) | ifneq ($(ARCH), mac) | ||||
| @@ -42,6 +42,7 @@ struct RackWidget : OpaqueWidget { | |||||
| void pastePresetClipboard(); | void pastePresetClipboard(); | ||||
| void addModule(ModuleWidget *m); | void addModule(ModuleWidget *m); | ||||
| void addModuleAtMouse(ModuleWidget *m); | |||||
| /** Removes the module and transfers ownership to the caller */ | /** Removes the module and transfers ownership to the caller */ | ||||
| void deleteModule(ModuleWidget *m); | void deleteModule(ModuleWidget *m); | ||||
| void cloneModule(ModuleWidget *m); | void cloneModule(ModuleWidget *m); | ||||
| @@ -11,10 +11,9 @@ namespace rack { | |||||
| struct Scene : OpaqueWidget { | struct Scene : OpaqueWidget { | ||||
| // Convenience variables for accessing important widgets | |||||
| ScrollWidget *scrollWidget; | ScrollWidget *scrollWidget; | ||||
| ZoomWidget *zoomWidget; | ZoomWidget *zoomWidget; | ||||
| // Convenience variables for accessing important widgets | |||||
| RackWidget *rackWidget; | RackWidget *rackWidget; | ||||
| Toolbar *toolbar; | Toolbar *toolbar; | ||||
| @@ -25,6 +24,7 @@ struct Scene : OpaqueWidget { | |||||
| std::string latestVersion; | std::string latestVersion; | ||||
| Scene(); | Scene(); | ||||
| ~Scene(); | |||||
| void step() override; | void step() override; | ||||
| void draw(NVGcontext *vg) override; | void draw(NVGcontext *vg) override; | ||||
| void onHoverKey(const event::HoverKey &e) override; | void onHoverKey(const event::HoverKey &e) override; | ||||
| @@ -33,10 +33,7 @@ struct ModuleWidgetWrapper : ObstructWidget { | |||||
| // Create module | // Create module | ||||
| ModuleWidget *moduleWidget = model->createModuleWidget(); | ModuleWidget *moduleWidget = model->createModuleWidget(); | ||||
| assert(moduleWidget); | assert(moduleWidget); | ||||
| context()->scene->rackWidget->addModule(moduleWidget); | |||||
| // Move module nearest to the mouse position | |||||
| moduleWidget->box.pos = context()->scene->rackWidget->lastMousePos.minus(moduleWidget->box.size.div(2)); | |||||
| context()->scene->rackWidget->requestModuleBoxNearest(moduleWidget, moduleWidget->box); | |||||
| context()->scene->rackWidget->addModuleAtMouse(moduleWidget); | |||||
| // Close Module Browser | // Close Module Browser | ||||
| MenuOverlay *menuOverlay = getAncestorOfType<MenuOverlay>(); | MenuOverlay *menuOverlay = getAncestorOfType<MenuOverlay>(); | ||||
| menuOverlay->requestedDelete = true; | menuOverlay->requestedDelete = true; | ||||
| @@ -62,7 +59,7 @@ struct ModuleBrowser : OpaqueWidget { | |||||
| ModuleWidget *moduleWidget = model->createModuleWidgetNull(); | ModuleWidget *moduleWidget = model->createModuleWidgetNull(); | ||||
| zoomWidget->addChild(moduleWidget); | zoomWidget->addChild(moduleWidget); | ||||
| wrapper->box.size = moduleWidget->box.size.mult(zoomWidget->zoom); | wrapper->box.size = moduleWidget->box.size.mult(zoomWidget->zoom); | ||||
| p = wrapper->box.getTopRight(); | |||||
| p = wrapper->box.getTopRight().plus(math::Vec(20, 0)); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -22,8 +22,11 @@ ModuleWidget::ModuleWidget(Module *module) { | |||||
| } | } | ||||
| ModuleWidget::~ModuleWidget() { | ModuleWidget::~ModuleWidget() { | ||||
| // Make sure WireWidget destructors are called *before* removing `module` from the rack. | |||||
| disconnect(); | |||||
| // HACK | |||||
| // If we try to disconnect wires in the Module Browser (e.g. when Rack is closed while the Module Browser is open), context()->scene->rackWidget will be an invalid pointer. | |||||
| // So only attempt to disconnect if the module is not NULL. | |||||
| if (module) | |||||
| disconnect(); | |||||
| // Remove and delete the Module instance | // Remove and delete the Module instance | ||||
| if (module) { | if (module) { | ||||
| context()->engine->removeModule(module); | context()->engine->removeModule(module); | ||||
| @@ -25,7 +25,10 @@ PortWidget::PortWidget() { | |||||
| PortWidget::~PortWidget() { | PortWidget::~PortWidget() { | ||||
| // plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here | // plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here | ||||
| delete plugLight; | delete plugLight; | ||||
| context()->scene->rackWidget->wireContainer->removeAllWires(this); | |||||
| // HACK | |||||
| // See ModuleWidget::~ModuleWidget for description | |||||
| if (module) | |||||
| context()->scene->rackWidget->wireContainer->removeAllWires(this); | |||||
| } | } | ||||
| void PortWidget::step() { | void PortWidget::step() { | ||||
| @@ -458,6 +458,13 @@ void RackWidget::addModule(ModuleWidget *m) { | |||||
| moduleContainer->addChild(m); | moduleContainer->addChild(m); | ||||
| } | } | ||||
| void RackWidget::addModuleAtMouse(ModuleWidget *m) { | |||||
| addModule(m); | |||||
| // Move module nearest to the mouse position | |||||
| m->box.pos = lastMousePos.minus(m->box.size.div(2)); | |||||
| requestModuleBoxNearest(m, m->box); | |||||
| } | |||||
| void RackWidget::deleteModule(ModuleWidget *m) { | void RackWidget::deleteModule(ModuleWidget *m) { | ||||
| moduleContainer->removeChild(m); | moduleContainer->removeChild(m); | ||||
| } | } | ||||
| @@ -28,6 +28,9 @@ Scene::Scene() { | |||||
| scrollWidget->box.pos.y = toolbar->box.size.y; | scrollWidget->box.pos.y = toolbar->box.size.y; | ||||
| } | } | ||||
| Scene::~Scene() { | |||||
| } | |||||
| void Scene::step() { | void Scene::step() { | ||||
| // Resize owned descendants | // Resize owned descendants | ||||
| toolbar->box.size.x = box.size.x; | toolbar->box.size.x = box.size.x; | ||||