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) 2005 Stepan Moskovchenko
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#include "plugin.h"
22#include "midiutil.h"
23
24int chVol[16] IBSS_ATTR; /* Channel volume */
25int chPan[16] IBSS_ATTR; /* Channel panning */
26int chPat[16] IBSS_ATTR; /* Channel patch */
27int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */
28int chPBDepth[16] IBSS_ATTR; /* Channel pitch bend depth */
29int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
30int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
31unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */
32unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */
33
34struct GPatch * gusload(char *);
35struct GPatch * patchSet[128];
36struct GPatch * drumSet[128];
37
38struct SynthObject voices[MAX_VOICES] IBSS_ATTR;
39
40static void *alloc(int size)
41{
42 static char *offset[2] = {NULL};
43 static size_t totalSize[2] = {0};
44 char *ret;
45 int n;
46
47 int remainder = size % 4;
48
49 size = size + 4-remainder;
50
51 if (offset[0] == NULL)
52 {
53 offset[0] = rb->plugin_get_buffer(&totalSize[0]);
54 }
55
56 if (offset[1] == NULL)
57 {
58 offset[1] = rb->plugin_get_audio_buffer(&totalSize[1]);
59 }
60
61 n = (totalSize[0] > totalSize[1]) ? 1 : 0;
62
63 if (size + 4 > (int)totalSize[n])
64 n ^= 1;
65 if (size + 4 > (int)totalSize[n])
66 {
67 midi_debug("Out of Memory");
68 return NULL;
69 }
70
71 ret = offset[n] + 4;
72 *((unsigned int *)offset[n]) = size;
73
74 offset[n] += size + 4;
75 totalSize[n] -= size + 4;
76 return ret;
77}
78
79/* Rick's code */
80/*
81void *alloc(int size)
82{
83 static char *offset = NULL;
84 static ssize_t totalSize = 0;
85 char *ret;
86
87
88 if (offset == NULL)
89 {
90 offset = rb->plugin_get_audio_buffer((size_t *)&totalSize);
91 }
92
93 if (size + 4 > totalSize)
94 {
95 return NULL;
96 }
97
98 ret = offset + 4;
99 *((unsigned int *)offset) = size;
100
101 offset += size + 4;
102 totalSize -= size + 4;
103 return ret;
104}
105*/
106
107#define malloc(n) my_malloc(n)
108void * my_malloc(int size)
109{
110 return alloc(size);
111}
112
113unsigned char readChar(int file)
114{
115 char buf[2];
116 rb->read(file, &buf, 1);
117 return buf[0];
118}
119
120void * readData(int file, int len)
121{
122 void * dat = malloc(len);
123 if (dat)
124 rb->read(file, dat, len);
125 return dat;
126}
127
128int eof(int fd)
129{
130 int curPos = rb->lseek(fd, 0, SEEK_CUR);
131
132 int size = rb->lseek(fd, 0, SEEK_END);
133
134 rb->lseek(fd, curPos, SEEK_SET);
135 return size+1 == rb->lseek(fd, 0, SEEK_CUR);
136}
137
138/* Here is a hacked up printf command to get the output from the game. */
139int midi_debug(const char *fmt, ...)
140{
141 static int p_xtpt = 0;
142 char p_buf[50];
143 va_list ap;
144
145 va_start(ap, fmt);
146 rb->vsnprintf(p_buf,sizeof(p_buf), fmt, ap);
147 va_end(ap);
148
149 int i=0;
150
151 /* Device LCDs display newlines funny. */
152 for(i=0; p_buf[i]!=0; i++)
153 if(p_buf[i] == '\n')
154 p_buf[i] = ' ';
155
156 rb->lcd_putsxy(1,p_xtpt, (unsigned char *)p_buf);
157 rb->lcd_update();
158
159 p_xtpt+=8;
160 if(p_xtpt>LCD_HEIGHT-8)
161 {
162 p_xtpt=0;
163 rb->lcd_clear_display();
164 }
165 return 1;
166}
167