1 /*
2  * Copyright (C) 2019 Alexandros Theodotou <alex at zrythm dot org>
3  *
4  * This file is part of Zrythm
5  *
6  * Zrythm is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Zrythm is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with Zrythm.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "plugins/lv2_plugin.h"
21 #include "plugins/lv2/lv2_log.h"
22 #include "plugins/plugin.h"
23 #include "plugins/plugin_manager.h"
24 #include "zrythm.h"
25 #include "zrythm_app.h"
26 
27 /**
28  * Needed because we can't set them directly when
29  * gi18n.h is included.
30  */
31 void
lv2_log_set_printf_funcs(LV2_Log_Log * log)32 lv2_log_set_printf_funcs (
33   LV2_Log_Log * log)
34 {
35   log->printf = lv2_log_printf;
36   log->vprintf = lv2_log_vprintf;
37 }
38 
39 int
lv2_log_vprintf(LV2_Log_Handle handle,LV2_URID type,const char * _fmt,va_list ap)40 lv2_log_vprintf (
41   LV2_Log_Handle handle,
42   LV2_URID       type,
43   const char*    _fmt,
44   va_list        ap)
45 {
46   Lv2Plugin* plugin  = (Lv2Plugin*) handle;
47   GLogLevelFlags level;
48   if (type == PM_URIDS.log_Trace)
49     level = G_LOG_LEVEL_DEBUG;
50   else if (type == PM_URIDS.log_Error ||
51            type == PM_URIDS.log_Warning)
52     level = G_LOG_LEVEL_WARNING;
53   else
54     level = G_LOG_LEVEL_MESSAGE;
55 
56   /* remove trailing new line - glib adds its own */
57   char fmt[strlen (_fmt) + 1];
58   strcpy (fmt, _fmt);
59   if (fmt[strlen (fmt) - 1] == '\n')
60     fmt[strlen (fmt) - 1] = '\0';
61 
62   g_logv (
63     plugin->plugin->setting->descr->name,
64     level, fmt, ap);
65 
66   return 0;
67 }
68 
69 int
lv2_log_printf(LV2_Log_Handle handle,LV2_URID type,const char * fmt,...)70 lv2_log_printf (
71   LV2_Log_Handle handle,
72   LV2_URID       type,
73   const char*    fmt, ...)
74 {
75 	va_list args;
76 	va_start (args, fmt);
77 	const int ret =
78     lv2_log_vprintf (handle, type, fmt, args);
79 	va_end (args);
80 
81   return ret;
82 }
83