FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / apps / plugins / midi / midiutil.h
blobba64a00e28be92189e0242dcb61c9bbcfb60ea1a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Stepan Moskovchenko
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #define FRACTSIZE 12
24 #define BUF_SIZE 16384 /* 64 kB output buffers */
25 #define NBUF 2
27 #ifndef SIMULATOR
29 #if (HW_SAMPR_CAPS & SAMPR_CAP_22) /* use 22050Hz if we can */
30 #define SAMPLE_RATE SAMPR_22 /* 22050 */
31 #else
32 #define SAMPLE_RATE SAMPR_44 /* 44100 */
33 #endif
35 /* Some of the pp based targets can't handle too many voices
36 mainly because they have to use 44100Hz sample rate, this could be
37 improved to increase MAX_VOICES for targets that can do 22kHz */
38 #ifdef CPU_PP
39 #define MAX_VOICES 16
40 #else
41 #define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
42 #endif /* CPU_PP */
44 #else /* Simulator requires 44100Hz, and we can afford to use more voices */
46 #define SAMPLE_RATE SAMPR_44
47 #define MAX_VOICES 48
49 #endif
51 #define BYTE unsigned char
53 /* Data chunk ID types, returned by readID() */
54 #define ID_UNKNOWN -1
55 #define ID_MTHD 1
56 #define ID_MTRK 2
57 #define ID_EOF 3
58 #define ID_RIFF 4
60 /* MIDI Commands */
61 #define MIDI_NOTE_OFF 128
62 #define MIDI_NOTE_ON 144
63 #define MIDI_AFTERTOUCH 160
64 #define MIDI_CONTROL 176
65 #define MIDI_PRGM 192
66 #define MIDI_PITCHW 224
68 /* MIDI Controllers */
69 #define CTRL_DATAENT_MSB 6
70 #define CTRL_VOLUME 7
71 #define CTRL_BALANCE 8
72 #define CTRL_PANNING 10
73 #define CTRL_NONREG_LSB 98
74 #define CTRL_NONREG_MSB 99
75 #define CTRL_REG_LSB 100
76 #define CTRL_REG_MSB 101
78 #define REG_PITCHBEND_MSB 0
79 #define REG_PITCHBEND_LSB 0
82 #define CHANNEL 1
84 /* Most of these are deprecated.. rampdown is used, maybe one other one too */
85 #define STATE_ATTACK 1
86 #define STATE_DECAY 2
87 #define STATE_SUSTAIN 3
88 #define STATE_RELEASE 4
89 #define STATE_RAMPDOWN 5
91 /* Loop states */
92 #define STATE_LOOPING 7
93 #define STATE_NONLOOPING 8
95 /* Various bits in the GUS mode byte */
96 #define LOOP_ENABLED 4
97 #define LOOP_PINGPONG 8
98 #define LOOP_REVERSE 16
100 struct MIDIfile
102 int Length;
103 unsigned short numTracks;
104 unsigned short div; /* Time division, X ticks per millisecond */
105 struct Track * tracks[48];
106 unsigned char patches[128];
107 int numPatches;
110 struct SynthObject
112 struct GWaveform * wf;
113 int delta;
114 int decay;
115 unsigned int cp; /* unsigned int */
116 int state, loopState;
117 int note, vol, ch;
118 int curRate, curOffset, targetOffset;
119 int curPoint;
120 signed short int volscale;
121 bool isUsed;
124 struct Event
126 unsigned int delta;
127 unsigned char status, d1, d2;
128 unsigned int len;
129 unsigned char * evData;
132 struct Track
134 unsigned int size;
135 unsigned int numEvents;
136 unsigned int delta; /* For sequencing */
137 unsigned int pos; /* For sequencing */
138 void * dataBlock;
141 int printf(const char *fmt, ...);
142 unsigned char readChar(int file);
143 int readTwoBytes(int file);
144 int readFourBytes(int file);
145 int readVarData(int file);
146 int eof(int fd);
147 unsigned char * readData(int file, int len);
148 void exit(int code);
150 #define malloc(n) my_malloc(n)
151 void * my_malloc(int size);
153 extern struct SynthObject voices[MAX_VOICES];
155 extern int chVol[16]; /* Channel volume */
156 extern int chPan[16]; /* Channel panning */
157 extern int chPat[16]; /* Channel patch */
158 extern int chPW[16]; /* Channel pitch wheel, MSB only */
159 extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */
160 extern int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
161 extern int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
162 extern unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */
163 extern unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */
165 extern struct GPatch * gusload(char *);
166 extern struct GPatch * patchSet[128];
167 extern struct GPatch * drumSet[128];
169 extern struct MIDIfile * mf;
171 extern int number_of_samples;
172 extern int playing_time IBSS_ATTR;
173 extern int samples_this_second IBSS_ATTR;
174 extern long bpm;