@@ -1,7 +1,7 @@ | |||
ARCH ?= lin | |||
FLAGS = -g -Wall -O2 -msse -mfpmath=sse -ffast-math -fno-finite-math-only \ | |||
FLAGS += -g -Wall -O3 -march=core2 -ffast-math \ | |||
-I./ext -I./include | |||
CXXFLAGS = -fno-exceptions | |||
CXXFLAGS += -std=c++11 -fno-exceptions | |||
SOURCES = $(wildcard src/*.cpp src/*/*.cpp) \ | |||
ext/nanovg/src/nanovg.c | |||
@@ -1,8 +1,9 @@ | |||
ARCH ?= lin | |||
FLAGS += -fPIC -g -Wall -O3 -msse -mfpmath=sse -ffast-math \ | |||
FLAGS += -fPIC -g -Wall -O3 -march=core2 -ffast-math \ | |||
-I../../include | |||
CXXFLAGS += -std=c++11 -fno-exceptions | |||
LDFLAGS += | |||
@@ -1,17 +1,16 @@ | |||
FLAGS += -MMD | |||
CXXFLAGS += -std=c++11 | |||
ifeq ($(ARCH), lin) | |||
CC ?= gcc | |||
CXX ?= g++ | |||
FLAGS += -DLINUX | |||
FLAGS += -DARCH_LIN | |||
endif | |||
ifeq ($(ARCH), mac) | |||
CC ?= clang | |||
CXX ?= clang++ | |||
FLAGS += -DAPPLE | |||
FLAGS += -DARCH_MAC | |||
CXXFLAGS += -stdlib=libc++ | |||
LDFLAGS += -stdlib=libc++ | |||
endif | |||
@@ -19,7 +18,7 @@ endif | |||
ifeq ($(ARCH), win) | |||
CC ?= x86_64-w64-mingw32-gcc | |||
CXX ?= x86_64-w64-mingw32-g++ | |||
FLAGS += -DWINDOWS -D_USE_MATH_DEFINES | |||
FLAGS += -DARCH_WIN -D_USE_MATH_DEFINES | |||
endif | |||
@@ -289,7 +289,6 @@ struct RackScene : Scene { | |||
extern std::string gApplicationName; | |||
extern std::string gApplicationVersion; | |||
extern Scene *gScene; | |||
extern RackWidget *gRackWidget; | |||
void sceneInit(); | |||
@@ -387,6 +387,7 @@ struct Tooltip : Widget { | |||
struct Scene : OpaqueWidget { | |||
Widget *overlay = NULL; | |||
void setOverlay(Widget *w); | |||
Menu *createMenu(); | |||
void step(); | |||
}; | |||
@@ -40,40 +40,40 @@ void ModuleWidget::addParam(ParamWidget *param) { | |||
} | |||
json_t *ModuleWidget::toJson() { | |||
json_t *root = json_object(); | |||
json_t *rootJ = json_object(); | |||
// plugin | |||
json_object_set_new(root, "plugin", json_string(model->plugin->slug.c_str())); | |||
json_object_set_new(rootJ, "plugin", json_string(model->plugin->slug.c_str())); | |||
// model | |||
json_object_set_new(root, "model", json_string(model->slug.c_str())); | |||
json_object_set_new(rootJ, "model", json_string(model->slug.c_str())); | |||
// pos | |||
json_t *pos = json_pack("[f, f]", (double) box.pos.x, (double) box.pos.y); | |||
json_object_set_new(root, "pos", pos); | |||
json_object_set_new(rootJ, "pos", pos); | |||
// params | |||
json_t *paramsJ = json_array(); | |||
for (ParamWidget *paramWidget : params) { | |||
json_t *paramJ = paramWidget->toJson(); | |||
json_array_append_new(paramsJ, paramJ); | |||
} | |||
json_object_set_new(root, "params", paramsJ); | |||
json_object_set_new(rootJ, "params", paramsJ); | |||
// data | |||
json_t *dataJ = module ? module->toJsonData() : NULL; | |||
if (dataJ) { | |||
json_object_set_new(root, "data", dataJ); | |||
json_object_set_new(rootJ, "data", dataJ); | |||
} | |||
return root; | |||
return rootJ; | |||
} | |||
void ModuleWidget::fromJson(json_t *root) { | |||
void ModuleWidget::fromJson(json_t *rootJ) { | |||
// pos | |||
json_t *pos = json_object_get(root, "pos"); | |||
json_t *pos = json_object_get(rootJ, "pos"); | |||
double x, y; | |||
json_unpack(pos, "[F, F]", &x, &y); | |||
box.pos = Vec(x, y); | |||
// params | |||
json_t *paramsJ = json_object_get(root, "params"); | |||
json_t *paramsJ = json_object_get(rootJ, "params"); | |||
size_t paramId; | |||
json_t *paramJ; | |||
json_array_foreach(paramsJ, paramId, paramJ) { | |||
@@ -83,7 +83,7 @@ void ModuleWidget::fromJson(json_t *root) { | |||
} | |||
// data | |||
json_t *dataJ = json_object_get(root, "data"); | |||
json_t *dataJ = json_object_get(rootJ, "data"); | |||
if (dataJ && module) { | |||
module->fromJsonData(dataJ); | |||
} | |||
@@ -197,41 +197,36 @@ struct DeleteModuleMenuItem : MenuItem { | |||
void ModuleWidget::onMouseDown(int button) { | |||
if (button == 1) { | |||
MenuOverlay *overlay = new MenuOverlay(); | |||
Menu *menu = new Menu(); | |||
menu->box.pos = gMousePos; | |||
{ | |||
MenuLabel *menuLabel = new MenuLabel(); | |||
menuLabel->text = model->plugin->name + ": " + model->name; | |||
menu->pushChild(menuLabel); | |||
ResetParamsMenuItem *resetItem = new ResetParamsMenuItem(); | |||
resetItem->text = "Initialize"; | |||
resetItem->moduleWidget = this; | |||
menu->pushChild(resetItem); | |||
RandomizeParamsMenuItem *randomizeParams = new RandomizeParamsMenuItem(); | |||
randomizeParams->text = "Randomize"; | |||
randomizeParams->moduleWidget = this; | |||
menu->pushChild(randomizeParams); | |||
DisconnectPortsMenuItem *disconnectItem = new DisconnectPortsMenuItem(); | |||
disconnectItem->text = "Disconnect cables"; | |||
disconnectItem->moduleWidget = this; | |||
menu->pushChild(disconnectItem); | |||
CloneModuleMenuItem *cloneItem = new CloneModuleMenuItem(); | |||
cloneItem->text = "Clone"; | |||
cloneItem->moduleWidget = this; | |||
menu->pushChild(cloneItem); | |||
DeleteModuleMenuItem *deleteItem = new DeleteModuleMenuItem(); | |||
deleteItem->text = "Delete"; | |||
deleteItem->moduleWidget = this; | |||
menu->pushChild(deleteItem); | |||
} | |||
overlay->addChild(menu); | |||
gScene->setOverlay(overlay); | |||
Menu *menu = gScene->createMenu(); | |||
MenuLabel *menuLabel = new MenuLabel(); | |||
menuLabel->text = model->plugin->name + ": " + model->name; | |||
menu->pushChild(menuLabel); | |||
ResetParamsMenuItem *resetItem = new ResetParamsMenuItem(); | |||
resetItem->text = "Initialize"; | |||
resetItem->moduleWidget = this; | |||
menu->pushChild(resetItem); | |||
RandomizeParamsMenuItem *randomizeParams = new RandomizeParamsMenuItem(); | |||
randomizeParams->text = "Randomize"; | |||
randomizeParams->moduleWidget = this; | |||
menu->pushChild(randomizeParams); | |||
DisconnectPortsMenuItem *disconnectItem = new DisconnectPortsMenuItem(); | |||
disconnectItem->text = "Disconnect cables"; | |||
disconnectItem->moduleWidget = this; | |||
menu->pushChild(disconnectItem); | |||
CloneModuleMenuItem *cloneItem = new CloneModuleMenuItem(); | |||
cloneItem->text = "Clone"; | |||
cloneItem->moduleWidget = this; | |||
menu->pushChild(cloneItem); | |||
DeleteModuleMenuItem *deleteItem = new DeleteModuleMenuItem(); | |||
deleteItem->text = "Delete"; | |||
deleteItem->moduleWidget = this; | |||
menu->pushChild(deleteItem); | |||
} | |||
} | |||
@@ -9,8 +9,8 @@ json_t *ParamWidget::toJson() { | |||
return paramJ; | |||
} | |||
void ParamWidget::fromJson(json_t *root) { | |||
setValue(json_number_value(root)); | |||
void ParamWidget::fromJson(json_t *rootJ) { | |||
setValue(json_number_value(rootJ)); | |||
} | |||
void ParamWidget::onMouseDown(int button) { | |||
@@ -30,5 +30,4 @@ void RackScene::draw(NVGcontext *vg) { | |||
} | |||
} // namespace rack |
@@ -33,10 +33,10 @@ void RackWidget::savePatch(std::string filename) { | |||
if (!file) | |||
return; | |||
json_t *root = toJson(); | |||
if (root) { | |||
json_dumpf(root, file, JSON_INDENT(2)); | |||
json_decref(root); | |||
json_t *rootJ = toJson(); | |||
if (rootJ) { | |||
json_dumpf(rootJ, file, JSON_INDENT(2)); | |||
json_decref(rootJ); | |||
} | |||
fclose(file); | |||
@@ -49,11 +49,11 @@ void RackWidget::loadPatch(std::string filename) { | |||
return; | |||
json_error_t error; | |||
json_t *root = json_loadf(file, 0, &error); | |||
if (root) { | |||
json_t *rootJ = json_loadf(file, 0, &error); | |||
if (rootJ) { | |||
clear(); | |||
fromJson(root); | |||
json_decref(root); | |||
fromJson(rootJ); | |||
json_decref(rootJ); | |||
} | |||
else { | |||
printf("JSON parsing error at %s %d:%d %s\n", error.source, error.line, error.column, error.text); | |||
@@ -64,19 +64,19 @@ void RackWidget::loadPatch(std::string filename) { | |||
json_t *RackWidget::toJson() { | |||
// root | |||
json_t *root = json_object(); | |||
json_t *rootJ = json_object(); | |||
// version | |||
json_t *versionJ = json_string(gApplicationVersion.c_str()); | |||
json_object_set_new(root, "version", versionJ); | |||
json_object_set_new(rootJ, "version", versionJ); | |||
// wireOpacity | |||
json_t *wireOpacityJ = json_real(dynamic_cast<RackScene*>(gScene)->toolbar->wireOpacitySlider->value); | |||
json_object_set_new(root, "wireOpacity", wireOpacityJ); | |||
json_object_set_new(rootJ, "wireOpacity", wireOpacityJ); | |||
// wireTension | |||
json_t *wireTensionJ = json_real(dynamic_cast<RackScene*>(gScene)->toolbar->wireTensionSlider->value); | |||
json_object_set_new(root, "wireTension", wireTensionJ); | |||
json_object_set_new(rootJ, "wireTension", wireTensionJ); | |||
// modules | |||
json_t *modulesJ = json_array(); | |||
@@ -91,7 +91,7 @@ json_t *RackWidget::toJson() { | |||
json_t *moduleJ = moduleWidget->toJson(); | |||
json_array_append_new(modulesJ, moduleJ); | |||
} | |||
json_object_set_new(root, "modules", modulesJ); | |||
json_object_set_new(rootJ, "modules", modulesJ); | |||
// wires | |||
json_t *wires = json_array(); | |||
@@ -129,14 +129,14 @@ json_t *RackWidget::toJson() { | |||
} | |||
json_array_append_new(wires, wire); | |||
} | |||
json_object_set_new(root, "wires", wires); | |||
json_object_set_new(rootJ, "wires", wires); | |||
return root; | |||
return rootJ; | |||
} | |||
void RackWidget::fromJson(json_t *root) { | |||
void RackWidget::fromJson(json_t *rootJ) { | |||
// version | |||
json_t *versionJ = json_object_get(root, "version"); | |||
json_t *versionJ = json_object_get(rootJ, "version"); | |||
if (versionJ) { | |||
const char *version = json_string_value(versionJ); | |||
if (gApplicationVersion != version) | |||
@@ -144,18 +144,18 @@ void RackWidget::fromJson(json_t *root) { | |||
} | |||
// wireOpacity | |||
json_t *wireOpacityJ = json_object_get(root, "wireOpacity"); | |||
json_t *wireOpacityJ = json_object_get(rootJ, "wireOpacity"); | |||
if (wireOpacityJ) | |||
dynamic_cast<RackScene*>(gScene)->toolbar->wireOpacitySlider->value = json_number_value(wireOpacityJ); | |||
// wireTension | |||
json_t *wireTensionJ = json_object_get(root, "wireTension"); | |||
json_t *wireTensionJ = json_object_get(rootJ, "wireTension"); | |||
if (wireTensionJ) | |||
dynamic_cast<RackScene*>(gScene)->toolbar->wireTensionSlider->value = json_number_value(wireTensionJ); | |||
// modules | |||
std::map<int, ModuleWidget*> moduleWidgets; | |||
json_t *modulesJ = json_object_get(root, "modules"); | |||
json_t *modulesJ = json_object_get(rootJ, "modules"); | |||
if (!modulesJ) return; | |||
size_t moduleId; | |||
json_t *moduleJ; | |||
@@ -193,7 +193,7 @@ void RackWidget::fromJson(json_t *root) { | |||
} | |||
// wires | |||
json_t *wiresJ = json_object_get(root, "wires"); | |||
json_t *wiresJ = json_object_get(rootJ, "wires"); | |||
if (!wiresJ) return; | |||
size_t wireId; | |||
json_t *wireJ; | |||
@@ -320,12 +320,8 @@ struct AddModuleMenuItem : MenuItem { | |||
void RackWidget::onMouseDown(int button) { | |||
if (button == 1) { | |||
// Get relative position of the click | |||
Vec modulePos = gMousePos.minus(getAbsolutePos()); | |||
MenuOverlay *overlay = new MenuOverlay(); | |||
Menu *menu = new Menu(); | |||
menu->box.pos = gMousePos; | |||
Menu *menu = gScene->createMenu(); | |||
MenuLabel *menuLabel = new MenuLabel(); | |||
menuLabel->text = "Add Module"; | |||
@@ -339,8 +335,6 @@ void RackWidget::onMouseDown(int button) { | |||
menu->pushChild(item); | |||
} | |||
} | |||
overlay->addChild(menu); | |||
gScene->setOverlay(overlay); | |||
} | |||
} | |||
@@ -4,7 +4,7 @@ | |||
#include "plugin.hpp" | |||
#if defined(APPLE) | |||
#if ARCH_MAC | |||
#include <CoreFoundation/CoreFoundation.h> | |||
#include <unistd.h> // for chdir and access | |||
#include <libgen.h> // for dirname | |||
@@ -81,7 +81,7 @@ void fixCwd() { | |||
using namespace rack; | |||
int main() { | |||
#if defined(APPLE) | |||
#if ARCH_MAC | |||
fixCwd(); | |||
#endif | |||
@@ -12,7 +12,7 @@ | |||
#include <zip.h> | |||
#include <jansson.h> | |||
#if defined(WINDOWS) | |||
#if ARCH_WIN | |||
#include <windows.h> | |||
#include <shellapi.h> | |||
#include <direct.h> | |||
@@ -43,22 +43,22 @@ Plugin::~Plugin() { | |||
static int loadPlugin(std::string slug) { | |||
#if defined(LINUX) | |||
#if ARCH_LIN | |||
std::string path = "./plugins/" + slug + "/plugin.so"; | |||
#elif defined(WINDOWS) | |||
#elif ARCH_WIN | |||
std::string path = "./plugins/" + slug + "/plugin.dll"; | |||
#elif defined(APPLE) | |||
#elif ARCH_MAC | |||
std::string path = "./plugins/" + slug + "/plugin.dylib"; | |||
#endif | |||
// Load dynamic/shared library | |||
#if defined(WINDOWS) | |||
#if ARCH_WIN | |||
HINSTANCE handle = LoadLibrary(path.c_str()); | |||
if (!handle) { | |||
fprintf(stderr, "Failed to load library %s\n", path.c_str()); | |||
return -1; | |||
} | |||
#elif defined(LINUX) || defined(APPLE) | |||
#elif ARCH_LIN || ARCH_MAC | |||
void *handle = dlopen(path.c_str(), RTLD_NOW | RTLD_GLOBAL); | |||
if (!handle) { | |||
fprintf(stderr, "Failed to load library %s: %s\n", path.c_str(), dlerror()); | |||
@@ -69,9 +69,9 @@ static int loadPlugin(std::string slug) { | |||
// Call plugin init() function | |||
typedef Plugin *(*InitCallback)(); | |||
InitCallback initCallback; | |||
#if defined(WINDOWS) | |||
#if ARCH_WIN | |||
initCallback = (InitCallback) GetProcAddress(handle, "init"); | |||
#elif defined(LINUX) || defined(APPLE) | |||
#elif ARCH_LIN || ARCH_MAC | |||
initCallback = (InitCallback) dlsym(handle, "init"); | |||
#endif | |||
if (!initCallback) { | |||
@@ -173,10 +173,8 @@ static void extract_zip(const char *dir, int zipfd) { | |||
if (err) goto cleanup; | |||
int nameLen = strlen(zs.name); | |||
char path[MAXPATHLEN] = "\0"; | |||
strncat(path, dir, MAXPATHLEN); | |||
strncat(path, "/", MAXPATHLEN); | |||
strncat(path, zs.name, MAXPATHLEN); | |||
char path[MAXPATHLEN]; | |||
snprintf(path, sizeof(path), "%s/%s", dir, zs.name); | |||
if (zs.name[nameLen - 1] == '/') { | |||
err = mkdir(path, 0755); | |||
@@ -213,15 +211,15 @@ cleanup: | |||
void pluginOpenBrowser(std::string url) { | |||
// shell injection is possible, so make sure the URL is trusted | |||
#if defined(LINUX) | |||
#if ARCH_LIN | |||
std::string command = "xdg-open " + url; | |||
system(command.c_str()); | |||
#endif | |||
#if defined(APPLE) | |||
#if ARCH_MAC | |||
std::string command = "open " + url; | |||
system(command.c_str()); | |||
#endif | |||
#if defined(WINDOWS) | |||
#if ARCH_WIN | |||
ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL); | |||
#endif | |||
} | |||
@@ -245,14 +243,14 @@ void pluginLogIn(std::string email, std::string password) { | |||
if (res == CURLE_OK) { | |||
// Parse JSON response | |||
json_error_t error; | |||
json_t *root = json_loads(resText.c_str(), 0, &error); | |||
if (root) { | |||
json_t *tokenJ = json_object_get(root, "token"); | |||
json_t *rootJ = json_loads(resText.c_str(), 0, &error); | |||
if (rootJ) { | |||
json_t *tokenJ = json_object_get(rootJ, "token"); | |||
if (tokenJ) { | |||
// Set the token, which logs the user in | |||
token = json_string_value(tokenJ); | |||
} | |||
json_decref(root); | |||
json_decref(rootJ); | |||
} | |||
} | |||
} | |||
@@ -287,11 +285,8 @@ static void pluginRefreshPlugin(json_t *pluginJ) { | |||
downloadProgress = 0.0; | |||
const char *dir = "plugins"; | |||
char path[MAXPATHLEN] = "\0"; | |||
strncat(path, dir, MAXPATHLEN); | |||
strncat(path, "/", MAXPATHLEN); | |||
strncat(path, slug.c_str(), MAXPATHLEN); | |||
strncat(path, ".zip", MAXPATHLEN); | |||
char path[MAXPATHLEN]; | |||
snprintf(path, sizeof(path), "%s/%s.zip", dir, slug.c_str()); | |||
int zip = open(path, O_RDWR | O_TRUNC | O_CREAT, 0644); | |||
// Download zip | |||
download_file(zip, url.c_str()); | |||
@@ -329,9 +324,9 @@ void pluginRefresh() { | |||
if (res == CURLE_OK) { | |||
// Parse JSON response | |||
json_error_t error; | |||
json_t *root = json_loads(resText.c_str(), 0, &error); | |||
if (root) { | |||
json_t *pluginsJ = json_object_get(root, "plugins"); | |||
json_t *rootJ = json_loads(resText.c_str(), 0, &error); | |||
if (rootJ) { | |||
json_t *pluginsJ = json_object_get(rootJ, "plugins"); | |||
if (pluginsJ) { | |||
// Iterate through each plugin object | |||
size_t index; | |||
@@ -340,7 +335,7 @@ void pluginRefresh() { | |||
pluginRefreshPlugin(pluginJ); | |||
} | |||
} | |||
json_decref(root); | |||
json_decref(rootJ); | |||
} | |||
} | |||
@@ -16,6 +16,18 @@ void Scene::setOverlay(Widget *w) { | |||
} | |||
} | |||
Menu *Scene::createMenu() { | |||
// Get relative position of the click | |||
MenuOverlay *overlay = new MenuOverlay(); | |||
Menu *menu = new Menu(); | |||
menu->box.pos = gMousePos; | |||
overlay->addChild(menu); | |||
gScene->setOverlay(overlay); | |||
return menu; | |||
} | |||
void Scene::step() { | |||
if (overlay) { | |||
overlay->box.size = box.size; | |||