Browse Source

Changed log() to info(), warn(), and fatal()

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
85c75eef33
12 changed files with 62 additions and 60 deletions
  1. +3
    -7
      include/util.hpp
  2. +2
    -2
      src/app/RackWidget.cpp
  3. +6
    -6
      src/core/AudioInterface.cpp
  4. +5
    -5
      src/core/MidiIO.cpp
  5. +8
    -8
      src/gui.cpp
  6. +4
    -4
      src/main.cpp
  7. +7
    -7
      src/plugin.cpp
  8. +3
    -3
      src/settings.cpp
  9. +20
    -14
      src/util.cpp
  10. +2
    -2
      src/util/request.cpp
  11. +1
    -1
      src/widgets/FramebufferWidget.cpp
  12. +1
    -1
      src/widgets/SpriteWidget.cpp

+ 3
- 7
include/util.hpp View File

@@ -131,14 +131,10 @@ struct VIPLock {
// logger // logger
//////////////////// ////////////////////


enum LogLevel {
INFO,
WARN,
ERROR,
};

extern FILE *gLogFile; 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 } // namespace rack

+ 2
- 2
src/app/RackWidget.cpp View File

@@ -83,7 +83,7 @@ void RackWidget::saveAsDialog() {




void RackWidget::savePatch(std::string path) { 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"); FILE *file = fopen(path.c_str(), "w");
if (!file) if (!file)
return; return;
@@ -98,7 +98,7 @@ void RackWidget::savePatch(std::string path) {
} }


void RackWidget::loadPatch(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"); FILE *file = fopen(path.c_str(), "r");
if (!file) { if (!file) {
// Exit silently // Exit silently


+ 6
- 6
src/core/AudioInterface.cpp View File

@@ -17,7 +17,7 @@ void audioInit() {


PaError err = Pa_Initialize(); PaError err = Pa_Initialize();
if (err) { if (err) {
log(WARN, "Failed to initialize PortAudio: %s", Pa_GetErrorText(err));
warn("Failed to initialize PortAudio: %s", Pa_GetErrorText(err));
return; return;
} }
initialized = true; initialized = true;
@@ -244,7 +244,7 @@ void AudioInterface::openDevice(int deviceId, float sampleRate, int blockSize) {
PaError err; PaError err;
const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(deviceId); const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(deviceId);
if (!deviceInfo) { if (!deviceInfo) {
log(WARN, "Failed to query audio device");
warn("Failed to query audio device");
return; return;
} }


@@ -271,13 +271,13 @@ void AudioInterface::openDevice(int deviceId, float sampleRate, int blockSize) {
numOutputs == 0 ? NULL : &outputParameters, numOutputs == 0 ? NULL : &outputParameters,
sampleRate, blockSize, paNoFlag, paCallback, this); sampleRate, blockSize, paNoFlag, paCallback, this);
if (err) { if (err) {
log(WARN, "Failed to open audio stream: %s", Pa_GetErrorText(err));
warn("Failed to open audio stream: %s", Pa_GetErrorText(err));
return; return;
} }


err = Pa_StartStream(stream); err = Pa_StartStream(stream);
if (err) { if (err) {
log(WARN, "Failed to start audio stream: %s", Pa_GetErrorText(err));
warn("Failed to start audio stream: %s", Pa_GetErrorText(err));
return; return;
} }
// This should go after Pa_StartStream because sometimes it will call the callback once synchronously, and that time it should return early // 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_AbortStream(stream);
// err = Pa_StopStream(stream); // err = Pa_StopStream(stream);
if (err) { 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); err = Pa_CloseStream(stream);
if (err) { if (err) {
log(WARN, "Failed to close audio stream: %s", Pa_GetErrorText(err));
warn("Failed to close audio stream: %s", Pa_GetErrorText(err));
} }
} }




+ 5
- 5
src/core/MidiIO.cpp View File

@@ -60,7 +60,7 @@ std::vector<std::string> MidiIO::getDevices() {
try { try {
m = new RtMidiIn(); m = new RtMidiIn();
} catch (RtMidiError &error) { } 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; return names;
} }


@@ -96,14 +96,14 @@ void MidiIO::openDevice(std::string deviceName) {
} }


if (!mw->isPortOpen()) { 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->deviceName = "";
this->id = -1; this->id = -1;
return; return;
} }
} }
catch (RtMidiError &error) { 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->deviceName = "";
this->id = -1; this->id = -1;
return; return;
@@ -144,7 +144,7 @@ double MidiIO::getMessage(std::vector<unsigned char> *msg) {
MidiInWrapper *mw = midiInMap[deviceName]; MidiInWrapper *mw = midiInMap[deviceName];


if (!mw) { if (!mw) {
log(WARN, "Device not opened!: %s", deviceName.c_str());
warn("Device not opened!: %s", deviceName.c_str());
return 0; return 0;
} }


@@ -176,7 +176,7 @@ void MidiIO::close() {
MidiInWrapper *mw = midiInMap[deviceName]; MidiInWrapper *mw = midiInMap[deviceName];


if (!mw || id < 0) { if (!mw || id < 0) {
//log(WARN, "Trying to close already closed device!");
//warn("Trying to close already closed device!");
return; return;
} }




+ 8
- 8
src/gui.cpp View File

@@ -279,7 +279,7 @@ void dropCallback(GLFWwindow *window, int count, const char **paths) {
} }


void errorCallback(int error, const char *description) { void errorCallback(int error, const char *description) {
log(WARN, "GLFW error %d: %s", error, description);
warn("GLFW error %d: %s", error, description);
} }


void renderGui() { void renderGui() {
@@ -446,7 +446,7 @@ void guiRun() {
std::this_thread::sleep_for(std::chrono::duration<double>(minTime - frameTime)); std::this_thread::sleep_for(std::chrono::duration<double>(minTime - frameTime));
} }
endTime = glfwGetTime(); 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) { Font::Font(const std::string &filename) {
handle = nvgCreateFont(gVg, filename.c_str(), filename.c_str()); handle = nvgCreateFont(gVg, filename.c_str(), filename.c_str());
if (handle >= 0) { if (handle >= 0) {
log(INFO, "Loaded font %s", filename.c_str());
info("Loaded font %s", filename.c_str());
} }
else { 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) { Image::Image(const std::string &filename) {
handle = nvgCreateImage(gVg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); handle = nvgCreateImage(gVg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY);
if (handle > 0) { if (handle > 0) {
log(INFO, "Loaded image %s", filename.c_str());
info("Loaded image %s", filename.c_str());
} }
else { 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) { SVG::SVG(const std::string &filename) {
handle = nsvgParseFromFile(filename.c_str(), "px", SVG_DPI); handle = nsvgParseFromFile(filename.c_str(), "px", SVG_DPI);
if (handle) { if (handle) {
log(INFO, "Loaded SVG %s", filename.c_str());
info("Loaded SVG %s", filename.c_str());
} }
else { else {
log(WARN, "Failed to load SVG %s", filename.c_str());
warn("Failed to load SVG %s", filename.c_str());
} }
} }




+ 4
- 4
src/main.cpp View File

@@ -18,17 +18,17 @@ int main(int argc, char* argv[]) {
#endif #endif


if (!gApplicationVersion.empty()) { if (!gApplicationVersion.empty()) {
log(INFO, "Rack v%s", gApplicationVersion.c_str());
info("Rack v%s", gApplicationVersion.c_str());
} }


{ {
char *cwd = getcwd(NULL, 0); char *cwd = getcwd(NULL, 0);
log(INFO, "Current working directory: %s", cwd);
info("Current working directory: %s", cwd);
free(cwd); free(cwd);
std::string globalDir = assetGlobal(""); std::string globalDir = assetGlobal("");
std::string localDir = assetLocal(""); 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(); pluginInit();


+ 7
- 7
src/plugin.cpp View File

@@ -112,13 +112,13 @@ static int loadPlugin(std::string path) {
HINSTANCE handle = LoadLibrary(libraryFilename.c_str()); HINSTANCE handle = LoadLibrary(libraryFilename.c_str());
if (!handle) { if (!handle) {
int error = GetLastError(); 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; return -1;
} }
#elif ARCH_LIN || ARCH_MAC #elif ARCH_LIN || ARCH_MAC
void *handle = dlopen(libraryFilename.c_str(), RTLD_NOW); void *handle = dlopen(libraryFilename.c_str(), RTLD_NOW);
if (!handle) { 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; return -1;
} }
#endif #endif
@@ -132,7 +132,7 @@ static int loadPlugin(std::string path) {
initCallback = (InitCallback) dlsym(handle, "init"); initCallback = (InitCallback) dlsym(handle, "init");
#endif #endif
if (!initCallback) { 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; return -2;
} }


@@ -144,7 +144,7 @@ static int loadPlugin(std::string path) {


// Add plugin to list // Add plugin to list
gPlugins.push_back(plugin); gPlugins.push_back(plugin);
log(INFO, "Loaded plugin %s", libraryFilename.c_str());
info("Loaded plugin %s", libraryFilename.c_str());
return 0; return 0;
} }


@@ -277,14 +277,14 @@ void pluginInit() {


// Load plugins from global directory // Load plugins from global directory
std::string globalPlugins = assetGlobal("plugins"); std::string globalPlugins = assetGlobal("plugins");
log(INFO, "Loading plugins from %s", globalPlugins.c_str());
info("Loading plugins from %s", globalPlugins.c_str());
loadPlugins(globalPlugins); loadPlugins(globalPlugins);


// Load plugins from local directory // Load plugins from local directory
std::string localPlugins = assetLocal("plugins"); std::string localPlugins = assetLocal("plugins");
if (globalPlugins != localPlugins) { if (globalPlugins != localPlugins) {
mkdir(localPlugins.c_str(), 0755); mkdir(localPlugins.c_str(), 0755);
log(INFO, "Loading plugins from %s", localPlugins.c_str());
info("Loading plugins from %s", localPlugins.c_str());
loadPlugins(localPlugins); loadPlugins(localPlugins);
} }
} }
@@ -353,7 +353,7 @@ void pluginRefresh() {
json_t *errorJ = json_object_get(resJ, "error"); json_t *errorJ = json_object_get(resJ, "error");
if (errorJ) { if (errorJ) {
const char *errorStr = json_string_value(errorJ); const char *errorStr = json_string_value(errorJ);
log(WARN, "Plugin refresh error: %s", errorStr);
warn("Plugin refresh error: %s", errorStr);
} }
else { else {
json_t *purchasesJ = json_object_get(resJ, "purchases"); json_t *purchasesJ = json_object_get(resJ, "purchases");


+ 3
- 3
src/settings.cpp View File

@@ -127,7 +127,7 @@ static void settingsFromJson(json_t *rootJ) {




void settingsSave(std::string filename) { 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"); FILE *file = fopen(filename.c_str(), "w");
if (!file) if (!file)
return; return;
@@ -142,7 +142,7 @@ void settingsSave(std::string filename) {
} }


void settingsLoad(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"); FILE *file = fopen(filename.c_str(), "r");
if (!file) if (!file)
return; return;
@@ -154,7 +154,7 @@ void settingsLoad(std::string filename) {
json_decref(rootJ); json_decref(rootJ);
} }
else { 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); fclose(file);


+ 20
- 14
src/util.cpp View File

@@ -161,22 +161,28 @@ void openBrowser(std::string url) {


FILE *gLogFile = stderr; FILE *gLogFile = stderr;


void log(LogLevel level, const char *format, ...) {
void info(const char *format, ...) {
va_list args; va_list args;
va_start(args, format); 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); vfprintf(gLogFile, format, args);
fprintf(gLogFile, "\n"); fprintf(gLogFile, "\n");
va_end(args); va_end(args);


+ 2
- 2
src/util/request.cpp View File

@@ -83,7 +83,7 @@ json_t *requestJson(RequestMethod method, std::string url, json_t *dataJ) {
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resText); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resText);


// Perform request // Perform request
log(INFO, "Requesting %s", url.c_str());
info("Requesting %s", url.c_str());
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
CURLcode res = curl_easy_perform(curl); 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_XFERINFOFUNCTION, xferInfoCallback);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, progress); 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); CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);




+ 1
- 1
src/widgets/FramebufferWidget.cpp View File

@@ -64,7 +64,7 @@ void FramebufferWidget::draw(NVGcontext *vg) {
if (fbSize.isZero()) if (fbSize.isZero())
return; 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 // Delete old one first to free up GPU memory
internal->setFramebuffer(NULL); internal->setFramebuffer(NULL);
// Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context. // Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context.


+ 1
- 1
src/widgets/SpriteWidget.cpp View File

@@ -8,7 +8,7 @@ void SpriteWidget::draw(NVGcontext *vg) {
nvgImageSize(vg, spriteImage->handle, &width, &height); nvgImageSize(vg, spriteImage->handle, &width, &height);
int stride = width / spriteSize.x; int stride = width / spriteSize.x;
if (stride == 0) { 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; return;
} }
Vec offset = Vec((index % stride) * spriteSize.x, (index / stride) * spriteSize.y); Vec offset = Vec((index % stride) * spriteSize.x, (index / stride) * spriteSize.y);


Loading…
Cancel
Save