1 /*
2  * runtime.h
3  * Copyright 2014 John Lindgren
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions, and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions, and the following disclaimer in the documentation
13  *    provided with the distribution.
14  *
15  * This software is provided "as is" and without any warranty, express or
16  * implied. In no event shall the authors be liable for any damages arising from
17  * the use of this software.
18  */
19 
20 #ifndef LIBAUDCORE_RUNTIME_H
21 #define LIBAUDCORE_RUNTIME_H
22 
23 #include <libaudcore/objects.h>
24 
25 enum class AudPath
26 {
27     BinDir,
28     DataDir,
29     PluginDir,
30     LocaleDir,
31     DesktopFile,
32     IconFile,
33     UserDir,
34     PlaylistDir,
35     count
36 };
37 
38 enum class MainloopType
39 {
40     GLib,
41     Qt
42 };
43 
44 enum class OutputReset
45 {
46     EffectsOnly,
47     ReopenStream,
48     ResetPlugin
49 };
50 
51 enum class OutputStream
52 {
53     AsDecoded,
54     AfterReplayGain,
55     AfterEffects,
56     AfterEqualizer
57 };
58 
59 enum class ReplayGainMode
60 {
61     Track,
62     Album,
63     Automatic
64 };
65 
66 namespace audlog
67 {
68 enum Level
69 {
70     Debug,
71     Info,
72     Warning,
73     Error
74 };
75 
76 typedef void (*Handler)(Level level, const char * file, int line,
77                         const char * func, const char * message);
78 
79 void set_stderr_level(Level level);
80 void subscribe(Handler handler, Level level);
81 void unsubscribe(Handler handler);
82 
83 #ifdef _WIN32
84 void log(Level level, const char * file, int line, const char * func,
85          const char * format, ...)
86     __attribute__((__format__(gnu_printf, 5, 6)));
87 #else
88 void log(Level level, const char * file, int line, const char * func,
89          const char * format, ...)
90     __attribute__((__format__(__printf__, 5, 6)));
91 #endif
92 
93 const char * get_level_name(Level level);
94 } // namespace audlog
95 
96 #define AUDERR(...)                                                            \
97     do                                                                         \
98     {                                                                          \
99         audlog::log(audlog::Error, __FILE__, __LINE__, __FUNCTION__,           \
100                     __VA_ARGS__);                                              \
101     } while (0)
102 #define AUDWARN(...)                                                           \
103     do                                                                         \
104     {                                                                          \
105         audlog::log(audlog::Warning, __FILE__, __LINE__, __FUNCTION__,         \
106                     __VA_ARGS__);                                              \
107     } while (0)
108 #define AUDINFO(...)                                                           \
109     do                                                                         \
110     {                                                                          \
111         audlog::log(audlog::Info, __FILE__, __LINE__, __FUNCTION__,            \
112                     __VA_ARGS__);                                              \
113     } while (0)
114 #define AUDDBG(...)                                                            \
115     do                                                                         \
116     {                                                                          \
117         audlog::log(audlog::Debug, __FILE__, __LINE__, __FUNCTION__,           \
118                     __VA_ARGS__);                                              \
119     } while (0)
120 
121 const char * aud_get_path(AudPath id);
122 
123 void aud_set_headless_mode(bool headless);
124 bool aud_get_headless_mode();
125 
126 // Note that the UserDir and PlaylistDir paths vary depending on the instance
127 // number.  Therefore, calling aud_set_instance() after these paths have been
128 // referenced, or after aud_init(), is an error.
129 void aud_set_instance(int instance);
130 int aud_get_instance();
131 
132 void aud_set_mainloop_type(MainloopType type);
133 MainloopType aud_get_mainloop_type();
134 
135 void aud_request_restart();
136 bool aud_restart_requested();
137 
138 void aud_init_i18n();
139 
140 void aud_config_set_defaults(const char * section,
141                              const char * const * entries);
142 
143 void aud_set_str(const char * section, const char * name, const char * value);
144 String aud_get_str(const char * section, const char * name);
145 void aud_set_bool(const char * section, const char * name, bool value);
146 bool aud_get_bool(const char * section, const char * name);
147 void aud_toggle_bool(const char * section, const char * name);
148 void aud_set_int(const char * section, const char * name, int value);
149 int aud_get_int(const char * section, const char * name);
150 void aud_set_double(const char * section, const char * name, double value);
151 double aud_get_double(const char * section, const char * name);
152 
153 /* overloads for main ("audacious") config section */
aud_set_str(const char * name,const char * value)154 static inline void aud_set_str(const char * name, const char * value)
155 {
156     aud_set_str(nullptr, name, value);
157 }
aud_get_str(const char * name)158 static inline String aud_get_str(const char * name)
159 {
160     return aud_get_str(nullptr, name);
161 }
aud_set_bool(const char * name,bool value)162 static inline void aud_set_bool(const char * name, bool value)
163 {
164     aud_set_bool(nullptr, name, value);
165 }
aud_get_bool(const char * name)166 static inline bool aud_get_bool(const char * name)
167 {
168     return aud_get_bool(nullptr, name);
169 }
aud_toggle_bool(const char * name)170 static inline void aud_toggle_bool(const char * name)
171 {
172     aud_toggle_bool(nullptr, name);
173 }
aud_set_int(const char * name,int value)174 static inline void aud_set_int(const char * name, int value)
175 {
176     aud_set_int(nullptr, name, value);
177 }
aud_get_int(const char * name)178 static inline int aud_get_int(const char * name)
179 {
180     return aud_get_int(nullptr, name);
181 }
aud_set_double(const char * name,double value)182 static inline void aud_set_double(const char * name, double value)
183 {
184     aud_set_double(nullptr, name, value);
185 }
aud_get_double(const char * name)186 static inline double aud_get_double(const char * name)
187 {
188     return aud_get_double(nullptr, name);
189 }
190 
191 void aud_init();
192 void aud_resume();
193 void aud_run();
194 void aud_quit();
195 void aud_cleanup();
196 
197 void aud_leak_check();
198 
199 String aud_history_get(int entry);
200 void aud_history_add(const char * path);
201 void aud_history_clear();
202 
203 void aud_output_reset(OutputReset type);
204 
205 #endif
206