diff options
Diffstat (limited to 'apps/plugins/midi/midiutil.h')
-rw-r--r-- | apps/plugins/midi/midiutil.h | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h new file mode 100644 index 0000000000..cfaa4fb2fe --- /dev/null +++ b/apps/plugins/midi/midiutil.h | |||
@@ -0,0 +1,172 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 Stepan Moskovchenko | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #define FRACTSIZE 10 | ||
21 | |||
22 | #define BUF_SIZE 256 | ||
23 | #define NBUF 2 | ||
24 | |||
25 | |||
26 | #ifndef SIMULATOR | ||
27 | |||
28 | #if (HW_SAMPR_CAPS & SAMPR_CAP_22) | ||
29 | #define SAMPLE_RATE SAMPR_22 // 44100 22050 11025 | ||
30 | #else | ||
31 | #define SAMPLE_RATE SAMPR_44 // 44100 22050 11025 | ||
32 | #endif | ||
33 | |||
34 | #define MAX_VOICES 20 // Note: 24 midi channels is the minimum general midi | ||
35 | // spec implementation | ||
36 | |||
37 | #else // Simulator requires 44100, and we can afford to use more voices | ||
38 | |||
39 | #define SAMPLE_RATE SAMPR_44 | ||
40 | #define MAX_VOICES 48 | ||
41 | |||
42 | #endif | ||
43 | |||
44 | #define BYTE unsigned char | ||
45 | |||
46 | //Data chunk ID types, returned by readID() | ||
47 | #define ID_UNKNOWN -1 | ||
48 | #define ID_MTHD 1 | ||
49 | #define ID_MTRK 2 | ||
50 | #define ID_EOF 3 | ||
51 | #define ID_RIFF 4 | ||
52 | |||
53 | //MIDI Commands | ||
54 | #define MIDI_NOTE_OFF 128 | ||
55 | #define MIDI_NOTE_ON 144 | ||
56 | #define MIDI_AFTERTOUCH 160 | ||
57 | #define MIDI_CONTROL 176 | ||
58 | #define MIDI_PRGM 192 | ||
59 | #define MIDI_PITCHW 224 | ||
60 | |||
61 | //MIDI Controllers | ||
62 | #define CTRL_VOLUME 7 | ||
63 | #define CTRL_BALANCE 8 | ||
64 | #define CTRL_PANNING 10 | ||
65 | #define CHANNEL 1 | ||
66 | |||
67 | //Most of these are deprecated.. rampdown is used, maybe one other one too | ||
68 | #define STATE_ATTACK 1 | ||
69 | #define STATE_DECAY 2 | ||
70 | #define STATE_SUSTAIN 3 | ||
71 | #define STATE_RELEASE 4 | ||
72 | #define STATE_RAMPDOWN 5 | ||
73 | |||
74 | //Loop states | ||
75 | #define STATE_LOOPING 7 | ||
76 | #define STATE_NONLOOPING 8 | ||
77 | |||
78 | //Various bits in the GUS mode byte | ||
79 | #define LOOP_ENABLED 4 | ||
80 | #define LOOP_PINGPONG 8 | ||
81 | #define LOOP_REVERSE 16 | ||
82 | |||
83 | #define LOOPDIR_FORWARD 0 | ||
84 | #define LOOPDIR_REVERSE 1 | ||
85 | |||
86 | struct MIDIfile | ||
87 | { | ||
88 | int Length; | ||
89 | unsigned short numTracks; | ||
90 | unsigned short div; /* Time division, X ticks per millisecond */ | ||
91 | struct Track * tracks[48]; | ||
92 | unsigned char patches[128]; | ||
93 | int numPatches; | ||
94 | }; | ||
95 | |||
96 | /* | ||
97 | struct SynthObject | ||
98 | { | ||
99 | struct GWaveform * wf; | ||
100 | unsigned int delta; | ||
101 | unsigned int decay; | ||
102 | unsigned int cp; | ||
103 | unsigned char state, loopState, loopDir; | ||
104 | unsigned char note, vol, ch, isUsed; | ||
105 | int curRate, curOffset, targetOffset; | ||
106 | unsigned int curPoint; | ||
107 | }; | ||
108 | */ | ||
109 | |||
110 | struct SynthObject | ||
111 | { | ||
112 | struct GWaveform * wf; | ||
113 | int delta; | ||
114 | int decay; | ||
115 | unsigned int cp; /* unsigned int */ | ||
116 | int state, loopState, loopDir; | ||
117 | int note, vol, ch, isUsed; | ||
118 | int curRate, curOffset, targetOffset; | ||
119 | int curPoint; | ||
120 | signed short int volscale; | ||
121 | }; | ||
122 | |||
123 | struct Event | ||
124 | { | ||
125 | unsigned int delta; | ||
126 | unsigned char status, d1, d2; | ||
127 | unsigned int len; | ||
128 | unsigned char * evData; | ||
129 | }; | ||
130 | |||
131 | struct Track | ||
132 | { | ||
133 | unsigned int size; | ||
134 | unsigned int numEvents; | ||
135 | unsigned int delta; /* For sequencing */ | ||
136 | unsigned int pos; /* For sequencing */ | ||
137 | void * dataBlock; | ||
138 | }; | ||
139 | |||
140 | int printf(const char *fmt, ...); | ||
141 | int midimain(void * filename); | ||
142 | unsigned char readChar(int file); | ||
143 | void sendEvent(struct Event * ev); | ||
144 | inline void setPoint(struct SynthObject * so, int pt); | ||
145 | struct Event * getEvent(struct Track * tr, int evNum); | ||
146 | int readTwoBytes(int file); | ||
147 | int readFourBytes(int file); | ||
148 | int readVarData(int file); | ||
149 | int eof(int fd); | ||
150 | unsigned char * readData(int file, int len); | ||
151 | void exit(int code); | ||
152 | |||
153 | #define malloc(n) my_malloc(n) | ||
154 | void * my_malloc(int size); | ||
155 | |||
156 | extern struct SynthObject voices[MAX_VOICES]; | ||
157 | |||
158 | extern int chVol[16]; /* Channel volume */ | ||
159 | extern int chPanLeft[16]; /* Channel panning */ | ||
160 | extern int chPanRight[16]; | ||
161 | extern int chPat[16]; /* Channel patch */ | ||
162 | extern int chPW[16]; /* Channel pitch wheel, MSB only */ | ||
163 | |||
164 | extern struct GPatch * gusload(char *); | ||
165 | extern struct GPatch * patchSet[128]; | ||
166 | extern struct GPatch * drumSet[128]; | ||
167 | |||
168 | extern struct MIDIfile * mf; | ||
169 | |||
170 | extern int numberOfSamples; | ||
171 | extern long bpm; | ||
172 | |||