@@ -131,14 +131,10 @@ struct VIPLock { | |||
// logger | |||
//////////////////// | |||
enum LogLevel { | |||
INFO, | |||
WARN, | |||
ERROR, | |||
}; | |||
extern FILE *gLogFile; | |||
void log(LogLevel level, const char *format, ...); | |||
void info(const char *format, ...); | |||
void warn(const char *format, ...); | |||
void fatal(const char *format, ...); | |||
} // namespace rack |
@@ -83,7 +83,7 @@ void RackWidget::saveAsDialog() { | |||
void RackWidget::savePatch(std::string path) { | |||
log(INFO, "Saving patch %s", path.c_str()); | |||
info("Saving patch %s", path.c_str()); | |||
FILE *file = fopen(path.c_str(), "w"); | |||
if (!file) | |||
return; | |||
@@ -98,7 +98,7 @@ void RackWidget::savePatch(std::string path) { | |||
} | |||
void RackWidget::loadPatch(std::string path) { | |||
log(INFO, "Loading patch %s", path.c_str()); | |||
info("Loading patch %s", path.c_str()); | |||
FILE *file = fopen(path.c_str(), "r"); | |||
if (!file) { | |||
// Exit silently | |||
@@ -17,7 +17,7 @@ void audioInit() { | |||
PaError err = Pa_Initialize(); | |||
if (err) { | |||
log(WARN, "Failed to initialize PortAudio: %s", Pa_GetErrorText(err)); | |||
warn("Failed to initialize PortAudio: %s", Pa_GetErrorText(err)); | |||
return; | |||
} | |||
initialized = true; | |||
@@ -244,7 +244,7 @@ void AudioInterface::openDevice(int deviceId, float sampleRate, int blockSize) { | |||
PaError err; | |||
const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(deviceId); | |||
if (!deviceInfo) { | |||
log(WARN, "Failed to query audio device"); | |||
warn("Failed to query audio device"); | |||
return; | |||
} | |||
@@ -271,13 +271,13 @@ void AudioInterface::openDevice(int deviceId, float sampleRate, int blockSize) { | |||
numOutputs == 0 ? NULL : &outputParameters, | |||
sampleRate, blockSize, paNoFlag, paCallback, this); | |||
if (err) { | |||
log(WARN, "Failed to open audio stream: %s", Pa_GetErrorText(err)); | |||
warn("Failed to open audio stream: %s", Pa_GetErrorText(err)); | |||
return; | |||
} | |||
err = Pa_StartStream(stream); | |||
if (err) { | |||
log(WARN, "Failed to start audio stream: %s", Pa_GetErrorText(err)); | |||
warn("Failed to start audio stream: %s", Pa_GetErrorText(err)); | |||
return; | |||
} | |||
// This should go after Pa_StartStream because sometimes it will call the callback once synchronously, and that time it should return early | |||
@@ -299,12 +299,12 @@ void AudioInterface::closeDevice() { | |||
err = Pa_AbortStream(stream); | |||
// err = Pa_StopStream(stream); | |||
if (err) { | |||
log(WARN, "Failed to stop audio stream: %s", Pa_GetErrorText(err)); | |||
warn("Failed to stop audio stream: %s", Pa_GetErrorText(err)); | |||
} | |||
err = Pa_CloseStream(stream); | |||
if (err) { | |||
log(WARN, "Failed to close audio stream: %s", Pa_GetErrorText(err)); | |||
warn("Failed to close audio stream: %s", Pa_GetErrorText(err)); | |||
} | |||
} | |||
@@ -60,7 +60,7 @@ std::vector<std::string> MidiIO::getDevices() { | |||
try { | |||
m = new RtMidiIn(); | |||
} catch (RtMidiError &error) { | |||
log(WARN, "Failed to create RtMidiIn: %s", error.getMessage().c_str()); | |||
warn("Failed to create RtMidiIn: %s", error.getMessage().c_str()); | |||
return names; | |||
} | |||
@@ -96,14 +96,14 @@ void MidiIO::openDevice(std::string deviceName) { | |||
} | |||
if (!mw->isPortOpen()) { | |||
log(WARN, "Failed to create RtMidiIn: No such device %s", deviceName.c_str()); | |||
warn("Failed to create RtMidiIn: No such device %s", deviceName.c_str()); | |||
this->deviceName = ""; | |||
this->id = -1; | |||
return; | |||
} | |||
} | |||
catch (RtMidiError &error) { | |||
log(WARN, "Failed to create RtMidiIn: %s", error.getMessage().c_str()); | |||
warn("Failed to create RtMidiIn: %s", error.getMessage().c_str()); | |||
this->deviceName = ""; | |||
this->id = -1; | |||
return; | |||
@@ -144,7 +144,7 @@ double MidiIO::getMessage(std::vector<unsigned char> *msg) { | |||
MidiInWrapper *mw = midiInMap[deviceName]; | |||
if (!mw) { | |||
log(WARN, "Device not opened!: %s", deviceName.c_str()); | |||
warn("Device not opened!: %s", deviceName.c_str()); | |||
return 0; | |||
} | |||
@@ -176,7 +176,7 @@ void MidiIO::close() { | |||
MidiInWrapper *mw = midiInMap[deviceName]; | |||
if (!mw || id < 0) { | |||
//log(WARN, "Trying to close already closed device!"); | |||
//warn("Trying to close already closed device!"); | |||
return; | |||
} | |||
@@ -279,7 +279,7 @@ void dropCallback(GLFWwindow *window, int count, const char **paths) { | |||
} | |||
void errorCallback(int error, const char *description) { | |||
log(WARN, "GLFW error %d: %s", error, description); | |||
warn("GLFW error %d: %s", error, description); | |||
} | |||
void renderGui() { | |||
@@ -446,7 +446,7 @@ void guiRun() { | |||
std::this_thread::sleep_for(std::chrono::duration<double>(minTime - frameTime)); | |||
} | |||
endTime = glfwGetTime(); | |||
// log(INFO, "%lf fps", 1.0 / (endTime - startTime)); | |||
// info("%lf fps", 1.0 / (endTime - startTime)); | |||
} | |||
} | |||
@@ -519,10 +519,10 @@ bool guiIsMaximized() { | |||
Font::Font(const std::string &filename) { | |||
handle = nvgCreateFont(gVg, filename.c_str(), filename.c_str()); | |||
if (handle >= 0) { | |||
log(INFO, "Loaded font %s", filename.c_str()); | |||
info("Loaded font %s", filename.c_str()); | |||
} | |||
else { | |||
log(WARN, "Failed to load font %s", filename.c_str()); | |||
warn("Failed to load font %s", filename.c_str()); | |||
} | |||
} | |||
@@ -545,10 +545,10 @@ std::shared_ptr<Font> Font::load(const std::string &filename) { | |||
Image::Image(const std::string &filename) { | |||
handle = nvgCreateImage(gVg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); | |||
if (handle > 0) { | |||
log(INFO, "Loaded image %s", filename.c_str()); | |||
info("Loaded image %s", filename.c_str()); | |||
} | |||
else { | |||
log(WARN, "Failed to load image %s", filename.c_str()); | |||
warn("Failed to load image %s", filename.c_str()); | |||
} | |||
} | |||
@@ -572,10 +572,10 @@ std::shared_ptr<Image> Image::load(const std::string &filename) { | |||
SVG::SVG(const std::string &filename) { | |||
handle = nsvgParseFromFile(filename.c_str(), "px", SVG_DPI); | |||
if (handle) { | |||
log(INFO, "Loaded SVG %s", filename.c_str()); | |||
info("Loaded SVG %s", filename.c_str()); | |||
} | |||
else { | |||
log(WARN, "Failed to load SVG %s", filename.c_str()); | |||
warn("Failed to load SVG %s", filename.c_str()); | |||
} | |||
} | |||
@@ -18,17 +18,17 @@ int main(int argc, char* argv[]) { | |||
#endif | |||
if (!gApplicationVersion.empty()) { | |||
log(INFO, "Rack v%s", gApplicationVersion.c_str()); | |||
info("Rack v%s", gApplicationVersion.c_str()); | |||
} | |||
{ | |||
char *cwd = getcwd(NULL, 0); | |||
log(INFO, "Current working directory: %s", cwd); | |||
info("Current working directory: %s", cwd); | |||
free(cwd); | |||
std::string globalDir = assetGlobal(""); | |||
std::string localDir = assetLocal(""); | |||
log(INFO, "Global directory: %s", globalDir.c_str()); | |||
log(INFO, "Local directory: %s", localDir.c_str()); | |||
info("Global directory: %s", globalDir.c_str()); | |||
info("Local directory: %s", localDir.c_str()); | |||
} | |||
pluginInit(); | |||
@@ -112,13 +112,13 @@ static int loadPlugin(std::string path) { | |||
HINSTANCE handle = LoadLibrary(libraryFilename.c_str()); | |||
if (!handle) { | |||
int error = GetLastError(); | |||
log(WARN, "Failed to load library %s: %d", libraryFilename.c_str(), error); | |||
warn("Failed to load library %s: %d", libraryFilename.c_str(), error); | |||
return -1; | |||
} | |||
#elif ARCH_LIN || ARCH_MAC | |||
void *handle = dlopen(libraryFilename.c_str(), RTLD_NOW); | |||
if (!handle) { | |||
log(WARN, "Failed to load library %s: %s", libraryFilename.c_str(), dlerror()); | |||
warn("Failed to load library %s: %s", libraryFilename.c_str(), dlerror()); | |||
return -1; | |||
} | |||
#endif | |||
@@ -132,7 +132,7 @@ static int loadPlugin(std::string path) { | |||
initCallback = (InitCallback) dlsym(handle, "init"); | |||
#endif | |||
if (!initCallback) { | |||
log(WARN, "Failed to read init() symbol in %s", libraryFilename.c_str()); | |||
warn("Failed to read init() symbol in %s", libraryFilename.c_str()); | |||
return -2; | |||
} | |||
@@ -144,7 +144,7 @@ static int loadPlugin(std::string path) { | |||
// Add plugin to list | |||
gPlugins.push_back(plugin); | |||
log(INFO, "Loaded plugin %s", libraryFilename.c_str()); | |||
info("Loaded plugin %s", libraryFilename.c_str()); | |||
return 0; | |||
} | |||
@@ -277,14 +277,14 @@ void pluginInit() { | |||
// Load plugins from global directory | |||
std::string globalPlugins = assetGlobal("plugins"); | |||
log(INFO, "Loading plugins from %s", globalPlugins.c_str()); | |||
info("Loading plugins from %s", globalPlugins.c_str()); | |||
loadPlugins(globalPlugins); | |||
// Load plugins from local directory | |||
std::string localPlugins = assetLocal("plugins"); | |||
if (globalPlugins != localPlugins) { | |||
mkdir(localPlugins.c_str(), 0755); | |||
log(INFO, "Loading plugins from %s", localPlugins.c_str()); | |||
info("Loading plugins from %s", localPlugins.c_str()); | |||
loadPlugins(localPlugins); | |||
} | |||
} | |||
@@ -353,7 +353,7 @@ void pluginRefresh() { | |||
json_t *errorJ = json_object_get(resJ, "error"); | |||
if (errorJ) { | |||
const char *errorStr = json_string_value(errorJ); | |||
log(WARN, "Plugin refresh error: %s", errorStr); | |||
warn("Plugin refresh error: %s", errorStr); | |||
} | |||
else { | |||
json_t *purchasesJ = json_object_get(resJ, "purchases"); | |||
@@ -127,7 +127,7 @@ static void settingsFromJson(json_t *rootJ) { | |||
void settingsSave(std::string filename) { | |||
log(INFO, "Saving settings %s", filename.c_str()); | |||
info("Saving settings %s", filename.c_str()); | |||
FILE *file = fopen(filename.c_str(), "w"); | |||
if (!file) | |||
return; | |||
@@ -142,7 +142,7 @@ void settingsSave(std::string filename) { | |||
} | |||
void settingsLoad(std::string filename) { | |||
log(INFO, "Loading settings %s", filename.c_str()); | |||
info("Loading settings %s", filename.c_str()); | |||
FILE *file = fopen(filename.c_str(), "r"); | |||
if (!file) | |||
return; | |||
@@ -154,7 +154,7 @@ void settingsLoad(std::string filename) { | |||
json_decref(rootJ); | |||
} | |||
else { | |||
log(WARN, "JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); | |||
warn("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); | |||
} | |||
fclose(file); | |||
@@ -161,22 +161,28 @@ void openBrowser(std::string url) { | |||
FILE *gLogFile = stderr; | |||
void log(LogLevel level, const char *format, ...) { | |||
void info(const char *format, ...) { | |||
va_list args; | |||
va_start(args, format); | |||
switch (level) { | |||
case INFO: | |||
fprintf(gLogFile, "[info] "); | |||
break; | |||
case WARN: | |||
fprintf(gLogFile, "[warning] "); | |||
break; | |||
case ERROR: | |||
fprintf(gLogFile, "[error] "); | |||
break; | |||
default: | |||
break; | |||
} | |||
fprintf(gLogFile, "[info] "); | |||
vfprintf(gLogFile, format, args); | |||
fprintf(gLogFile, "\n"); | |||
va_end(args); | |||
} | |||
void warn(const char *format, ...) { | |||
va_list args; | |||
va_start(args, format); | |||
fprintf(gLogFile, "[warn] "); | |||
vfprintf(gLogFile, format, args); | |||
fprintf(gLogFile, "\n"); | |||
va_end(args); | |||
} | |||
void fatal(const char *format, ...) { | |||
va_list args; | |||
va_start(args, format); | |||
fprintf(gLogFile, "[fatal] "); | |||
vfprintf(gLogFile, format, args); | |||
fprintf(gLogFile, "\n"); | |||
va_end(args); | |||
@@ -83,7 +83,7 @@ json_t *requestJson(RequestMethod method, std::string url, json_t *dataJ) { | |||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resText); | |||
// Perform request | |||
log(INFO, "Requesting %s", url.c_str()); | |||
info("Requesting %s", url.c_str()); | |||
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); | |||
CURLcode res = curl_easy_perform(curl); | |||
@@ -131,7 +131,7 @@ bool requestDownload(std::string url, std::string filename, float *progress) { | |||
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferInfoCallback); | |||
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, progress); | |||
log(INFO, "Downloading %s", url.c_str()); | |||
info("Downloading %s", url.c_str()); | |||
CURLcode res = curl_easy_perform(curl); | |||
curl_easy_cleanup(curl); | |||
@@ -64,7 +64,7 @@ void FramebufferWidget::draw(NVGcontext *vg) { | |||
if (fbSize.isZero()) | |||
return; | |||
// log(INFO, "rendering framebuffer %f %f", fbSize.x, fbSize.y); | |||
// info("rendering framebuffer %f %f", fbSize.x, fbSize.y); | |||
// Delete old one first to free up GPU memory | |||
internal->setFramebuffer(NULL); | |||
// Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context. | |||
@@ -8,7 +8,7 @@ void SpriteWidget::draw(NVGcontext *vg) { | |||
nvgImageSize(vg, spriteImage->handle, &width, &height); | |||
int stride = width / spriteSize.x; | |||
if (stride == 0) { | |||
log(WARN, "Size of SpriteWidget is %d, %d but spriteSize is %f, %f", width, height, spriteSize.x, spriteSize.y); | |||
warn("Size of SpriteWidget is %d, %d but spriteSize is %f, %f", width, height, spriteSize.x, spriteSize.y); | |||
return; | |||
} | |||
Vec offset = Vec((index % stride) * spriteSize.x, (index / stride) * spriteSize.y); | |||