A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef MISC_H
22#define MISC_H
23
24#include <stdbool.h>
25#include <stdint.h>
26#include <inttypes.h>
27#include "config.h"
28#include "screen_access.h"
29
30extern const unsigned char * const byte_units[];
31extern const unsigned char * const * const kibyte_units;
32extern const unsigned char * const unit_strings_core[];
33/* Format a large-range value for output, using the appropriate unit so that
34 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
35 * units) if possible, and 3 significant digits are shown. If a buffer is
36 * given, the result is snprintf()'d into that buffer, otherwise the result is
37 * voiced.*/
38char *output_dyn_value(char *buf,
39 int buf_size,
40 int64_t value,
41 const unsigned char * const *units,
42 unsigned int unit_count,
43 bool binary_scale);
44
45
46/* format_time_auto */
47enum e_fmt_time_auto_idx
48{
49 UNIT_IDX_HR = 0,
50 UNIT_IDX_MIN,
51 UNIT_IDX_SEC,
52 UNIT_IDX_MS,
53 UNIT_IDX_TIME_COUNT,
54};
55#define UNIT_IDX_MASK 0x01FFU /*Return only Unit_IDX*/
56#define UNIT_TRIM_ZERO 0x0200U /*Don't show leading zero on max_idx*/
57#define UNIT_LOCK_HR 0x0400U /*Don't Auto Range below this field*/
58#define UNIT_LOCK_MIN 0x0800U /*Don't Auto Range below this field*/
59#define UNIT_LOCK_SEC 0x1000U /*Don't Auto Range below this field*/
60
61/* time_split_units()
62 split time values depending on base unit
63 unit_idx: UNIT_HOUR, UNIT_MIN, UNIT_SEC, UNIT_MS
64 abs_value: absolute time value
65 units_in: array of unsigned ints with IDX_TIME_COUNT fields
66*/
67unsigned int time_split_units(int unit_idx, unsigned long abs_val,
68 unsigned long (*units_in)[UNIT_IDX_TIME_COUNT]);
69
70/* format_time_auto - return an auto ranged time string;
71 buffer: needs to be at least 25 characters for full range
72
73 unit_idx: specifies lowest or base index of the value
74 add | UNIT_LOCK_ to keep place holder of units that would normally be
75 discarded.. For instance, UNIT_LOCK_HR would keep the hours place, ex: string
76 00:10:10 (0 HRS 10 MINS 10 SECONDS) normally it would return as 10:10
77 add | UNIT_TRIM_ZERO to supress leading zero on the largest unit
78
79 value: should be passed in the same form as unit_idx
80
81 supress_unit: may be set to true and in this case the
82 hr, min, sec, ms identifiers will be left off the resulting string but
83 since right to left languages are handled it is advisable to leave units
84 as an indication of the text direction
85*/
86const char *format_time_auto(char *buffer, int buf_len, long value,
87 int unit_idx, bool supress_unit);
88
89/* Format time into buf.
90 *
91 * buf - buffer to format to.
92 * buf_size - size of buffer.
93 * t - time to format, in milliseconds.
94 */
95void format_time(char* buf, int buf_size, long t);
96
97const char* format_sleeptimer(char* buffer, size_t buffer_size,
98 int value, const char* unit);
99
100/* A string representation of either whether a sleep timer will be started or
101 canceled, and how long it will be or how long is remaining in brackets */
102char* string_sleeptimer(char *buffer, size_t buffer_len);
103int toggle_sleeptimer(void);
104void talk_sleeptimer(int custom_duration);
105
106#if CONFIG_RTC
107void talk_timedate(void);
108#endif
109
110/* Ask the user if they really want to erase the current dynamic playlist
111 * returns true if the playlist should be replaced */
112bool warn_on_pl_erase(void);
113
114bool show_search_progress(bool init, int count, int current, int total);
115
116/* Read (up to) a line of text from fd into buffer and return number of bytes
117 * read (which may be larger than the number of bytes stored in buffer). If
118 * an error occurs, -1 is returned (and buffer contains whatever could be
119 * read). A line is terminated by a LF char. Neither LF nor CR chars are
120 * stored in buffer.
121 */
122int read_line(int fd, char* buffer, int buffer_size);
123int fast_readline(int fd, char *buf, int buf_size, void *parameters,
124 int (*callback)(int n, char *buf, void *parameters));
125
126bool settings_parseline(char* line, char** name, char** value);
127long default_event_handler_ex(long event, void (*callback)(void *), void *parameter);
128long default_event_handler(long event);
129bool list_stop_handler(void);
130void car_adapter_mode_init(void) INIT_ATTR;
131
132/* Unicode byte order mark sequences and lengths */
133#define BOM_UTF_8 "\xef\xbb\xbf"
134#define BOM_UTF_8_SIZE 3
135#define BOM_UTF_16_LE "\xff\xfe"
136#define BOM_UTF_16_BE "\xfe\xff"
137#define BOM_UTF_16_SIZE 2
138
139int split_string(char *str, const char needle, char *vector[], int vector_length);
140#ifndef O_PATH
141#define O_PATH 0x2000
142#endif
143
144void fix_path_part(char* path, int offset, int count);
145int open_pathfmt(char *buf, size_t size, int oflag, const char *pathfmt, ...);
146int open_utf8(const char* pathname, int flags);
147int string_option(const char *option, const char *const oplist[], bool ignore_case);
148
149#ifdef BOOTFILE
150#if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \
151 || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
152void check_bootfile(bool do_rolo);
153#endif
154#endif
155
156enum volume_adjust_mode
157{
158 VOLUME_ADJUST_DIRECT, /* adjust in units of the volume step size */
159 VOLUME_ADJUST_PERCEPTUAL, /* adjust using perceptual steps */
160};
161
162/* min/max values for global_settings.volume_adjust_norm_steps */
163#define MIN_NORM_VOLUME_STEPS 10
164#define MAX_NORM_VOLUME_STEPS 100
165
166/* check range, set volume and save settings */
167void setvol(void);
168void set_normalized_volume(int vol);
169int get_normalized_volume(void);
170void adjust_volume(int steps);
171void adjust_volume_ex(int steps, enum volume_adjust_mode mode);
172
173#ifdef HAVE_LCD_COLOR
174int hex_to_rgb(const char* hex, int* color);
175#endif
176
177int confirm_delete_yesno(const char *name);
178
179char* strrsplt(char* str, int c);
180char* skip_whitespace(char* const str);
181
182/*
183 * removes the extension of filename (if it doesn't start with a .)
184 * puts the result in buffer
185 */
186char *strip_extension(char* buffer, int buffer_size, const char *filename);
187
188bool parse_color(enum screen_type screen, char *text, int *value);
189
190/* only used in USB HID and set_time screen */
191#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
192int clamp_value_wrap(int value, int max, int min);
193#endif
194
195enum current_activity {
196 ACTIVITY_UNKNOWN = 0,
197 ACTIVITY_MAINMENU,
198 ACTIVITY_WPS,
199 ACTIVITY_RECORDING,
200 ACTIVITY_FM,
201 ACTIVITY_PLAYLISTVIEWER,
202 ACTIVITY_SETTINGS,
203 ACTIVITY_FILEBROWSER,
204 ACTIVITY_DATABASEBROWSER,
205 ACTIVITY_PLUGINBROWSER,
206 ACTIVITY_QUICKSCREEN,
207 ACTIVITY_PITCHSCREEN,
208 ACTIVITY_OPTIONSELECT,
209 ACTIVITY_PLAYLISTBROWSER,
210 ACTIVITY_PLUGIN,
211 ACTIVITY_CONTEXTMENU,
212 ACTIVITY_SYSTEMSCREEN,
213 ACTIVITY_TIMEDATESCREEN,
214 ACTIVITY_BOOKMARKSLIST,
215 ACTIVITY_SHORTCUTSMENU,
216 ACTIVITY_ID3SCREEN,
217 ACTIVITY_USBSCREEN
218};
219
220/* custom string representation of activity */
221#define MAKE_ACT_STR(act) ((char[3]){'>', 'A'+ (act), 0x0})
222
223void beep_play(unsigned int frequency, unsigned int duration,
224 unsigned int amplitude);
225
226enum system_sound
227{
228 SOUND_KEYCLICK = 0,
229 SOUND_TRACK_SKIP,
230 SOUND_TRACK_NO_MORE,
231 SOUND_LIST_EDGE_BEEP_WRAP,
232 SOUND_LIST_EDGE_BEEP_NOWRAP,
233};
234
235/* Play a standard sound */
236void system_sound_play(enum system_sound sound);
237
238typedef bool (*keyclick_callback)(int action, void* data);
239void keyclick_set_callback(keyclick_callback cb, void* data);
240/* Produce keyclick based upon button and global settings */
241void keyclick_click(bool rawbutton, int action);
242
243/* Return current ReplayGain mode a file should have (REPLAYGAIN_TRACK or
244 * REPLAYGAIN_ALBUM) if ReplayGain processing is enabled, or -1 if no
245 * information present.
246 */
247struct mp3entry;
248int id3_get_replaygain_mode(const struct mp3entry *id3);
249void replaygain_update(void);
250
251void push_current_activity(enum current_activity screen);
252void push_activity_without_refresh(enum current_activity screen);
253void pop_current_activity(void);
254void pop_current_activity_without_refresh(void);
255enum current_activity get_current_activity(void);
256
257/* Format a sound value like: "-1.05 dB" (negative values)
258 * " 1.05 dB" (positive values include leading space)
259 */
260void format_sound_value(char *buf, size_t buf_sz, int snd, int val);
261
262/* Set skin_token parameter to true to format a sound value for
263 * display in themes, like: "-1.05" (negative values)
264 * "1.05" (positive values without leading space)
265 *
266 * (The new formatting includes a unit based on the AUDIOHW_SETTING
267 * definition -- on all targets, it's defined to be "dB". But the
268 * old formatting was just an integer value, and many themes append
269 * "dB" manually. So we need to strip the unit to unbreak all those
270 * existing themes.)
271 */
272void format_sound_value_ex(char *buf, size_t buf_sz, int snd, int val, bool skin_token);
273
274#ifndef PLUGIN
275enum core_load_bmp_error
276{
277 CLB_ALOC_ERR = 0,
278 CLB_READ_ERR = -1,
279};
280struct buflib_callbacks;
281int core_load_bmp(const char *filename, struct bitmap *bm, const int bmformat,
282 ssize_t *buf_reqd, struct buflib_callbacks *ops);
283#endif
284
285/* Convert a volume (in tenth dB) in the range [min_vol, max_vol]
286 * to a normalized linear value in the range [0, max_norm]. */
287long to_normalized_volume(long vol, long min_vol, long max_vol, long max_norm);
288
289/* Inverse of to_normalized_volume(), returns the volume in tenth dB
290 * for the given normalized volume. */
291long from_normalized_volume(long norm, long min_vol, long max_vol, long max_norm);
292
293/* clear the lcd output buffer, if update is true the cleared buffer
294 * will be written to the lcd */
295void clear_screen_buffer(bool update);
296
297#endif /* MISC_H */