src/aubio_setup.c: add custom logging function
authorPaul Brossier <piem@piem.org>
Tue, 27 Sep 2016 23:29:58 +0000 (01:29 +0200)
committerPaul Brossier <piem@piem.org>
Tue, 27 Sep 2016 23:29:58 +0000 (01:29 +0200)
src/aubio_setup.c

index f56be15..6f3664f 100644 (file)
@@ -1,5 +1,7 @@
 
 #include <m_pd.h>
+#include <aubio/aubio.h>
+#include <string.h>
 
 char aubio_version[] = "aubio external for pd, version " PACKAGE_VERSION;
 
@@ -25,9 +27,22 @@ void *aubio_new (void)
   return (void *)x;
 }
 
+void aubio_custom_log(int level, const char *message, void *data)
+{
+  // remove the last character, removing the trailing space
+  char *pos;
+  if ((pos=strchr(message, '\n')) != NULL) {
+        *pos = '\0';
+  }
+  post(message);
+}
+
 void aubio_setup (void)
 {
   post(aubio_version);
+  // register custom log function for errors and warnings
+  aubio_log_set_level_function(AUBIO_LOG_ERR, aubio_custom_log, NULL);
+  aubio_log_set_level_function(AUBIO_LOG_WRN, aubio_custom_log, NULL);
   aubioonset_tilde_setup();
   aubiotempo_tilde_setup();
   aubiotss_tilde_setup();