Browse Source

Refactoring method names, build system

tags/v0.3.0
Andrew Belt 7 years ago
parent
commit
630a46e8fa
6 changed files with 76 additions and 52 deletions
  1. +11
    -8
      Makefile
  2. +3
    -6
      Makefile-plugin.inc
  3. +9
    -7
      Makefile.inc
  4. +9
    -3
      include/app.hpp
  5. +8
    -3
      include/engine.hpp
  6. +36
    -25
      src/app/ModuleWidget.cpp

+ 11
- 8
Makefile View File

@@ -1,7 +1,7 @@
ARCH ?= lin
FLAGS += -g -Wall -O3 -march=core2 -ffast-math \
include Makefile-arch.inc

FLAGS += \
-I./ext -I./include -I./ext -I./include
CXXFLAGS += -std=c++11 -fno-exceptions


SOURCES = $(wildcard src/*.cpp src/*/*.cpp) \ SOURCES = $(wildcard src/*.cpp src/*/*.cpp) \
ext/nanovg/src/nanovg.c ext/nanovg/src/nanovg.c
@@ -11,7 +11,9 @@ ifeq ($(ARCH), lin)
SOURCES += ext/noc/noc_file_dialog.c SOURCES += ext/noc/noc_file_dialog.c
CFLAGS += -DNOC_FILE_DIALOG_GTK $(shell pkg-config --cflags gtk+-2.0) CFLAGS += -DNOC_FILE_DIALOG_GTK $(shell pkg-config --cflags gtk+-2.0)
LDFLAGS += -rdynamic \ LDFLAGS += -rdynamic \
-lpthread -lGL -lGLEW -lglfw -ldl -ljansson -lportaudio -lportmidi -lsamplerate -lcurl -lzip \
-lpthread -lGL -ldl \
-lportaudio -lportmidi \
-Ldep/lib -lGLEW -lglfw -ljansson -lsamplerate -lcurl -lzip \
$(shell pkg-config --libs gtk+-2.0) $(shell pkg-config --libs gtk+-2.0)
TARGET = Rack TARGET = Rack
endif endif
@@ -40,9 +42,6 @@ LDFLAGS += \
-Wl,--export-all-symbols,--out-implib,libRack.a -mwindows -Wl,--export-all-symbols,--out-implib,libRack.a -mwindows
TARGET = Rack.exe TARGET = Rack.exe
# OBJECTS = Rack.res # OBJECTS = Rack.res

%.res: %.rc
windres $^ -O coff -o $@
endif endif




@@ -51,4 +50,8 @@ all: $(TARGET)
clean: clean:
rm -rf $(TARGET) build rm -rf $(TARGET) build


include Makefile.inc
# For Windows resources
%.res: %.rc
windres $^ -O coff -o $@

include Makefile.inc

+ 3
- 6
Makefile-plugin.inc View File

@@ -1,10 +1,9 @@
ARCH ?= lin
# All paths here assume the PWD is plugin/something


include ../../Makefile-arch.inc


FLAGS += -fPIC -g -Wall -O3 -march=core2 -ffast-math \
FLAGS += -fPIC \
-I../../include -I../../include
CXXFLAGS += -std=c++11 -fno-exceptions
LDFLAGS +=




ifeq ($(ARCH), lin) ifeq ($(ARCH), lin)
@@ -23,11 +22,9 @@ TARGET = plugin.dll
endif endif





all: $(TARGET) all: $(TARGET)


clean: clean:
rm -rfv build $(TARGET) rm -rfv build $(TARGET)



include ../../Makefile.inc include ../../Makefile.inc

+ 9
- 7
Makefile.inc View File

@@ -1,4 +1,9 @@
# Generate dependency files build/*.d
FLAGS += -MMD FLAGS += -MMD
# Optimization
FLAGS += -O3 -march=core2 -ffast-math
FLAGS += -g -Wall
CXXFLAGS += -std=c++11




ifeq ($(ARCH), lin) ifeq ($(ARCH), lin)
@@ -22,9 +27,6 @@ FLAGS += -DARCH_WIN -D_USE_MATH_DEFINES
endif endif





CFLAGS := $(FLAGS) $(CFLAGS)
CXXFLAGS := $(FLAGS) $(CXXFLAGS)
OBJECTS += $(patsubst %, build/%.o, $(SOURCES)) OBJECTS += $(patsubst %, build/%.o, $(SOURCES))
DEPS = $(patsubst %, build/%.d, $(SOURCES)) DEPS = $(patsubst %, build/%.d, $(SOURCES))


@@ -40,16 +42,16 @@ $(TARGET): $(OBJECTS)


build/%.c.o: %.c build/%.c.o: %.c
@mkdir -p $(@D) @mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(FLAGS) $(CFLAGS) -c -o $@ $<


build/%.cpp.o: %.cpp build/%.cpp.o: %.cpp
@mkdir -p $(@D) @mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(CXX) $(FLAGS) $(CXXFLAGS) -c -o $@ $<


build/%.cc.o: %.cc build/%.cc.o: %.cc
@mkdir -p $(@D) @mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(CXX) $(FLAGS) $(CXXFLAGS) -c -o $@ $<


build/%.m.o: %.m build/%.m.o: %.m
@mkdir -p $(@D) @mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(FLAGS) $(CFLAGS) -c -o $@ $<

+ 9
- 3
include/app.hpp View File

@@ -39,9 +39,15 @@ struct ModuleWidget : OpaqueWidget {


json_t *toJson(); json_t *toJson();
void fromJson(json_t *root); void fromJson(json_t *root);
void disconnectPorts();
void resetParams();
void randomizeParams();

/** Disconnects cables from all ports */
void disconnect();
/** Resets the state of the module */
void initialize();
/** Randomizes the state of the module
This method just randomizes parameters. Override and call this function if your module contains other state information that you wish to randomize.
*/
void randomize();


void draw(NVGcontext *vg); void draw(NVGcontext *vg);




+ 8
- 3
include/engine.hpp View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <jansson.h>
#include "util.hpp" #include "util.hpp"
#include <jansson.h>




namespace rack { namespace rack {
@@ -21,8 +21,13 @@ struct Module {


/** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */ /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */
virtual void step() {} virtual void step() {}
virtual json_t *toJsonData() { return NULL; }
virtual void fromJsonData(json_t *root) {}

/** Override these to store extra internal data in the "data" property */
virtual json_t *toJson() { return NULL; }
virtual void fromJson(json_t *root) {}

virtual void initialize() {}
virtual void randomize() {}
}; };


struct Wire { struct Wire {


+ 36
- 25
src/app/ModuleWidget.cpp View File

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


ModuleWidget::~ModuleWidget() { ModuleWidget::~ModuleWidget() {
// Make sure WireWidget destructors are called *before* removing `module` from the rack. // Make sure WireWidget destructors are called *before* removing `module` from the rack.
disconnectPorts();
disconnect();
setModule(NULL); setModule(NULL);
} }


@@ -57,15 +57,19 @@ json_t *ModuleWidget::toJson() {
} }
json_object_set_new(rootJ, "params", paramsJ); json_object_set_new(rootJ, "params", paramsJ);
// data // data
json_t *dataJ = module ? module->toJsonData() : NULL;
if (dataJ) {
json_object_set_new(rootJ, "data", dataJ);
if (module) {
json_t *dataJ = module->toJson();
if (dataJ) {
json_object_set_new(rootJ, "data", dataJ);
}
} }


return rootJ; return rootJ;
} }


void ModuleWidget::fromJson(json_t *rootJ) { void ModuleWidget::fromJson(json_t *rootJ) {
initialize();

// pos // pos
json_t *pos = json_object_get(rootJ, "pos"); json_t *pos = json_object_get(rootJ, "pos");
double x, y; double x, y;
@@ -85,11 +89,11 @@ void ModuleWidget::fromJson(json_t *rootJ) {
// data // data
json_t *dataJ = json_object_get(rootJ, "data"); json_t *dataJ = json_object_get(rootJ, "data");
if (dataJ && module) { if (dataJ && module) {
module->fromJsonData(dataJ);
module->fromJson(dataJ);
} }
} }


void ModuleWidget::disconnectPorts() {
void ModuleWidget::disconnect() {
for (Port *input : inputs) { for (Port *input : inputs) {
input->disconnect(); input->disconnect();
} }
@@ -98,16 +102,22 @@ void ModuleWidget::disconnectPorts() {
} }
} }


void ModuleWidget::resetParams() {
void ModuleWidget::initialize() {
for (ParamWidget *param : params) { for (ParamWidget *param : params) {
param->setValue(param->defaultValue); param->setValue(param->defaultValue);
} }
if (module) {
module->initialize();
}
} }


void ModuleWidget::randomizeParams() {
void ModuleWidget::randomize() {
for (ParamWidget *param : params) { for (ParamWidget *param : params) {
param->setValue(rescalef(randomf(), 0.0, 1.0, param->minValue, param->maxValue)); param->setValue(rescalef(randomf(), 0.0, 1.0, param->minValue, param->maxValue));
} }
if (module) {
module->randomize();
}
} }


void ModuleWidget::draw(NVGcontext *vg) { void ModuleWidget::draw(NVGcontext *vg) {
@@ -117,7 +127,7 @@ void ModuleWidget::draw(NVGcontext *vg) {
bndBevel(vg, 0.0, 0.0, box.size.x, box.size.y); bndBevel(vg, 0.0, 0.0, box.size.x, box.size.y);


// CPU usage text // CPU usage text
if (dynamic_cast<RackScene*>(gScene)->toolbar->cpuUsageButton->value != 0.0) {
if (dynamic_cast<RackScene*>(gScene)->toolbar->cpuUsageButton->value > 0.0) {
float cpuTime = module ? module->cpuTime : 0.0; float cpuTime = module ? module->cpuTime : 0.0;
std::string text = stringf("%.1f%%", cpuTime * 100.0); std::string text = stringf("%.1f%%", cpuTime * 100.0);


@@ -152,32 +162,33 @@ void ModuleWidget::onDragMove(Vec mouseRel) {
void ModuleWidget::onDragEnd() { void ModuleWidget::onDragEnd() {
} }


struct DisconnectPortsMenuItem : MenuItem {
struct DisconnectMenuItem : MenuItem {
ModuleWidget *moduleWidget; ModuleWidget *moduleWidget;
void onAction() { void onAction() {
moduleWidget->disconnectPorts();
moduleWidget->disconnect();
} }
}; };


struct ResetParamsMenuItem : MenuItem {
struct InitializeMenuItem : MenuItem {
ModuleWidget *moduleWidget; ModuleWidget *moduleWidget;
void onAction() { void onAction() {
moduleWidget->resetParams();
moduleWidget->initialize();
} }
}; };


struct RandomizeParamsMenuItem : MenuItem {
struct RandomizeMenuItem : MenuItem {
ModuleWidget *moduleWidget; ModuleWidget *moduleWidget;
void onAction() { void onAction() {
moduleWidget->randomizeParams();
moduleWidget->randomize();
} }
}; };


struct CloneModuleMenuItem : MenuItem {
struct CloneMenuItem : MenuItem {
ModuleWidget *moduleWidget; ModuleWidget *moduleWidget;
void onAction() { void onAction() {
// Create new module from model // Create new module from model
ModuleWidget *clonedModuleWidget = moduleWidget->model->createModuleWidget(); ModuleWidget *clonedModuleWidget = moduleWidget->model->createModuleWidget();
// JSON serialization is the most straightforward way to do this
json_t *moduleJ = moduleWidget->toJson(); json_t *moduleJ = moduleWidget->toJson();
clonedModuleWidget->fromJson(moduleJ); clonedModuleWidget->fromJson(moduleJ);
json_decref(moduleJ); json_decref(moduleJ);
@@ -187,7 +198,7 @@ struct CloneModuleMenuItem : MenuItem {
} }
}; };


struct DeleteModuleMenuItem : MenuItem {
struct DeleteMenuItem : MenuItem {
ModuleWidget *moduleWidget; ModuleWidget *moduleWidget;
void onAction() { void onAction() {
gRackWidget->moduleContainer->removeChild(moduleWidget); gRackWidget->moduleContainer->removeChild(moduleWidget);
@@ -203,27 +214,27 @@ void ModuleWidget::onMouseDown(int button) {
menuLabel->text = model->plugin->name + ": " + model->name; menuLabel->text = model->plugin->name + ": " + model->name;
menu->pushChild(menuLabel); menu->pushChild(menuLabel);


ResetParamsMenuItem *resetItem = new ResetParamsMenuItem();
InitializeMenuItem *resetItem = new InitializeMenuItem();
resetItem->text = "Initialize"; resetItem->text = "Initialize";
resetItem->moduleWidget = this; resetItem->moduleWidget = this;
menu->pushChild(resetItem); menu->pushChild(resetItem);


RandomizeParamsMenuItem *randomizeParams = new RandomizeParamsMenuItem();
randomizeParams->text = "Randomize";
randomizeParams->moduleWidget = this;
menu->pushChild(randomizeParams);
RandomizeMenuItem *randomizeItem = new RandomizeMenuItem();
randomizeItem->text = "Randomize";
randomizeItem->moduleWidget = this;
menu->pushChild(randomizeItem);


DisconnectPortsMenuItem *disconnectItem = new DisconnectPortsMenuItem();
DisconnectMenuItem *disconnectItem = new DisconnectMenuItem();
disconnectItem->text = "Disconnect cables"; disconnectItem->text = "Disconnect cables";
disconnectItem->moduleWidget = this; disconnectItem->moduleWidget = this;
menu->pushChild(disconnectItem); menu->pushChild(disconnectItem);


CloneModuleMenuItem *cloneItem = new CloneModuleMenuItem();
CloneMenuItem *cloneItem = new CloneMenuItem();
cloneItem->text = "Clone"; cloneItem->text = "Clone";
cloneItem->moduleWidget = this; cloneItem->moduleWidget = this;
menu->pushChild(cloneItem); menu->pushChild(cloneItem);


DeleteModuleMenuItem *deleteItem = new DeleteModuleMenuItem();
DeleteMenuItem *deleteItem = new DeleteMenuItem();
deleteItem->text = "Delete"; deleteItem->text = "Delete";
deleteItem->moduleWidget = this; deleteItem->moduleWidget = this;
menu->pushChild(deleteItem); menu->pushChild(deleteItem);


Loading…
Cancel
Save