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) 2014 Franklin Wei, Benjamin Brown
11 * Copyright (C) 2004 Gregory Montoir
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22
23#ifndef __XWORLD_SYS_H__
24#define __XWORLD_SYS_H__
25
26#include "plugin.h"
27#include "intern.h"
28
29#if (PLUGIN_BUFFER_SIZE >= 0x80000 && defined(HAVE_LCD_COLOR) && LCD_DEPTH < 24)
30#define SYS_MOTION_BLUR
31/* must be odd */
32#define BLUR_FRAMES 3
33#endif
34
35#define NUM_COLORS 16
36#define MAX_MUTEXES 16
37#define SETTINGS_FILE "settings.zfg" /* change when backwards-compatibility is broken */
38#define CODE_X 80
39#define CODE_Y 36
40
41enum {
42 DIR_LEFT = 1 << 0,
43 DIR_RIGHT = 1 << 1,
44 DIR_UP = 1 << 2,
45 DIR_DOWN = 1 << 3
46};
47
48struct PlayerInput {
49
50 uint8_t dirMask;
51 bool button;
52 bool code;
53 bool pause;
54 bool quit;
55 char lastChar;
56 bool save, load;
57 bool fastMode;
58 int8_t stateSlot;
59};
60
61
62struct keymapping_t {
63 int up;
64 int down;
65 int left;
66 int right;
67
68 /* These aren't conditional, even if they aren't used (this is to
69 * prevent headers and source from having varying defintions of
70 * this structure, leading to memory corruption */
71 int upleft;
72 int upright;
73 int downleft;
74 int downright;
75};
76
77typedef void (*AudioCallback)(void *param, uint8_t *stream, int len);
78typedef uint32_t (*TimerCallback)(uint32_t delay, void *param);
79
80struct System {
81 struct mutex mutex_memory[MAX_MUTEXES];
82 uint16_t mutex_bitfield;
83 struct PlayerInput input;
84 fb_data palette[NUM_COLORS];
85 struct Engine* e;
86 struct keymapping_t keymap;
87
88 void *membuf;
89 size_t bytes_left;
90
91 bool loaded;
92
93 struct {
94 bool negative_enabled;
95 /*
96 scaling quality:
97 0: off
98 1: fast
99 2: good (color only)
100 */
101 int scaling_quality;
102 /*
103 rotation:
104 0: off
105 1: cw
106 2: ccw
107 */
108 int rotation_option;
109
110 bool showfps;
111 bool sound_enabled;
112 int sound_bufsize;
113 bool zoom;
114 bool blur;
115 } settings;
116};
117
118void sys_init(struct System*, const char *title);
119void sys_menu(struct System*);
120void sys_destroy(struct System*);
121
122void sys_setPalette(struct System*, uint8_t s, uint8_t n, const uint8_t *buf);
123void sys_copyRect(struct System*, uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *buf, uint32_t pitch);
124
125void sys_processEvents(struct System*);
126void sys_sleep(struct System*, uint32_t duration);
127uint32_t sys_getTimeStamp(struct System*);
128
129void sys_startAudio(struct System*, AudioCallback callback, void *param);
130void sys_stopAudio(struct System*);
131uint32_t sys_getOutputSampleRate(struct System*);
132
133void *sys_addTimer(struct System*, uint32_t delay, TimerCallback callback, void *param);
134void sys_removeTimer(struct System*, void *timerId);
135
136void *sys_createMutex(struct System*);
137void sys_destroyMutex(struct System*, void *mutex);
138void sys_lockMutex(struct System*, void *mutex);
139void sys_unlockMutex(struct System*, void *mutex);
140
141/* a quick 'n dirty function to get some bytes in the audio buffer after zeroing them */
142/* pretty much does the same thing as calloc, though much uglier and there's no free() */
143void *sys_get_buffer(struct System*, size_t);
144
145uint8_t* getOffScreenFramebuffer(struct System*);
146
147struct MutexStack_t {
148 struct System *sys;
149 void *_mutex;
150};
151
152void MutexStack(struct MutexStack_t*, struct System*, void*);
153void MutexStack_destroy(struct MutexStack_t*);
154
155#endif