FS#12076 - DB stats resurrection: If the filename was changed, require
[kugel-rb.git] / apps / plugins / midi / midiutil.h
blob62a31d0c65d094ea7a345bf6f2568f27332de8d7
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 #include "lib/pluginlib_exit.h"
26 #define BUF_SIZE 16384 /* 64 kB output buffers */
27 #define NBUF 2
29 #ifndef SIMULATOR
31 #if (HW_SAMPR_CAPS & SAMPR_CAP_22) /* use 22050Hz if we can */
32 #define SAMPLE_RATE SAMPR_22 /* 22050 */
33 #else
34 #define SAMPLE_RATE SAMPR_44 /* 44100 */
35 #endif
37 /* Some of the pp based targets can't handle too many voices
38 mainly because they have to use 44100Hz sample rate, this could be
39 improved to increase MAX_VOICES for targets that can do 22kHz */
40 #ifdef CPU_PP
41 #define MAX_VOICES 16
42 #elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
43 #define MAX_VOICES 48
44 #else
45 #define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
46 #endif /* CPU_PP */
48 #else /* Simulator requires 44100Hz, and we can afford to use more voices */
50 #define SAMPLE_RATE SAMPR_44
51 #define MAX_VOICES 48
53 #endif
55 #define BYTE unsigned char
57 /* Data chunk ID types, returned by readID() */
58 #define ID_UNKNOWN -1
59 #define ID_MTHD 1
60 #define ID_MTRK 2
61 #define ID_EOF 3
62 #define ID_RIFF 4
64 /* MIDI Commands */
65 #define MIDI_NOTE_OFF 128
66 #define MIDI_NOTE_ON 144
67 #define MIDI_AFTERTOUCH 160
68 #define MIDI_CONTROL 176
69 #define MIDI_PRGM 192
70 #define MIDI_PITCHW 224
72 /* MIDI Controllers */
73 #define CTRL_DATAENT_MSB 6
74 #define CTRL_VOLUME 7
75 #define CTRL_BALANCE 8
76 #define CTRL_PANNING 10
77 #define CTRL_NONREG_LSB 98
78 #define CTRL_NONREG_MSB 99
79 #define CTRL_REG_LSB 100
80 #define CTRL_REG_MSB 101
82 #define REG_PITCHBEND_MSB 0
83 #define REG_PITCHBEND_LSB 0
86 #define CHANNEL 1
88 /* Most of these are deprecated.. rampdown is used, maybe one other one too */
89 #define STATE_ATTACK 1
90 #define STATE_DECAY 2
91 #define STATE_SUSTAIN 3
92 #define STATE_RELEASE 4
93 #define STATE_RAMPDOWN 5
95 /* Loop states */
96 #define STATE_LOOPING 7
97 #define STATE_NONLOOPING 8
99 /* Various bits in the GUS mode byte */
100 #define LOOP_ENABLED 4
101 #define LOOP_PINGPONG 8
102 #define LOOP_REVERSE 16
104 struct MIDIfile
106 int Length;
107 unsigned short numTracks;
108 unsigned short div; /* Time division, X ticks per millisecond */
109 struct Track * tracks[48];
110 unsigned char patches[128];
111 int numPatches;
114 struct SynthObject
116 struct GWaveform * wf;
117 int delta;
118 int decay;
119 unsigned int cp; /* unsigned int */
120 int state, loopState;
121 int note, vol, ch;
122 int curRate, curOffset, targetOffset;
123 int curPoint;
124 signed short int volscale;
125 bool isUsed;
128 struct Event
130 unsigned int delta;
131 unsigned char status, d1, d2;
132 unsigned int len;
133 unsigned char * evData;
136 struct Track
138 unsigned int size;
139 unsigned int numEvents;
140 unsigned int delta; /* For sequencing */
141 unsigned int pos; /* For sequencing */
142 void * dataBlock;
145 int midi_debug(const char *fmt, ...);
146 unsigned char readChar(int file);
147 int readTwoBytes(int file);
148 int readFourBytes(int file);
149 int readVarData(int file);
150 int eof(int fd);
151 unsigned char * readData(int file, int len);
153 #define malloc(n) my_malloc(n)
154 void * my_malloc(int size);
156 extern struct SynthObject voices[MAX_VOICES];
158 extern int chVol[16]; /* Channel volume */
159 extern int chPan[16]; /* Channel panning */
160 extern int chPat[16]; /* Channel patch */
161 extern int chPW[16]; /* Channel pitch wheel, MSB only */
162 extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */
163 extern int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
164 extern int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
165 extern unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */
166 extern unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */
168 extern struct GPatch * gusload(char *);
169 extern struct GPatch * patchSet[128];
170 extern struct GPatch * drumSet[128];
172 extern struct MIDIfile * mf;
174 extern int number_of_samples;
175 extern int playing_time IBSS_ATTR;
176 extern int samples_this_second IBSS_ATTR;
177 extern long bpm;