summaryrefslogtreecommitdiff
path: root/apps/plugins/midi/guspat.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/midi/guspat.c')
-rw-r--r--apps/plugins/midi/guspat.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/apps/plugins/midi/guspat.c b/apps/plugins/midi/guspat.c
new file mode 100644
index 0000000000..f0f1effd2a
--- /dev/null
+++ b/apps/plugins/midi/guspat.c
@@ -0,0 +1,151 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2005 Stepan Moskovchenko
10 *
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19
20extern struct plugin_api * rb;
21
22unsigned int readWord(int file)
23{
24 return (readChar(file)<<0) | (readChar(file)<<8); // | (readChar(file)<<8) | (readChar(file)<<0);
25}
26
27unsigned int readDWord(int file)
28{
29 return (readChar(file)<<0) | (readChar(file)<<8) | (readChar(file)<<16) | (readChar(file)<<24);
30}
31
32struct GWaveform * loadWaveform(int file)
33{
34 struct GWaveform * wav = (struct GWaveform *)allocate(sizeof(struct GWaveform));
35 rb->memset(wav, 0, sizeof(struct GWaveform));
36
37 wav->name=readData(file, 7);
38 printf("\nWAVE NAME = [%s]", wav->name);
39 wav->fractions=readChar(file);
40 wav->wavSize=readDWord(file);
41 wav->startLoop=readDWord(file);
42 wav->endLoop=readDWord(file);
43 wav->sampRate=readWord(file);
44
45 wav->lowFreq=readDWord(file);
46 wav->highFreq=readDWord(file);
47 wav->rootFreq=readDWord(file);
48
49 wav->tune=readWord(file);
50
51 wav->balance=readChar(file);
52 wav->envRate=readData(file, 6);
53 wav->envOffset=readData(file, 6);
54
55 wav->tremSweep=readChar(file);
56 wav->tremRate==readChar(file);
57 wav->tremDepth=readChar(file);
58 wav->vibSweep=readChar(file);
59 wav->vibRate=readChar(file);
60 wav->vibDepth=readChar(file);
61 wav->mode=readChar(file);
62
63 wav->scaleFreq=readWord(file);
64 wav->scaleFactor=readWord(file);
65 printf("\nScaleFreq = %d ScaleFactor = %d RootFreq = %d", wav->scaleFreq, wav->scaleFactor, wav->rootFreq);
66 wav->res=readData(file, 36);
67 wav->data=readData(file, wav->wavSize);
68
69 return wav;
70}
71
72
73
74int selectWaveform(struct GPatch * pat, int midiNote)
75{
76 int tabFreq = gustable[midiNote]/100; //Comparison
77 int a=0;
78 for(a=0; a<pat->numWaveforms; a++)
79 {
80 if(pat->waveforms[a]->lowFreq/100 <= tabFreq &&
81 pat->waveforms[a]->highFreq/100 >= tabFreq)
82 {
83 return a;
84 }
85 }
86 return 0;
87}
88
89
90struct GPatch * gusload(char * filename)
91{
92 struct GPatch * gp = (struct GPatch *)allocate(sizeof(struct GPatch));
93 rb->memset(gp, 0, sizeof(struct GPatch));
94
95 int file = rb->open(filename, O_RDONLY);
96
97 gp->header=readData(file, 12);
98 gp->gravisid=readData(file, 10);
99 gp->desc=readData(file, 60);
100 gp->inst=readChar(file);
101 gp->voc=readChar(file);
102 gp->chan=readChar(file);
103 gp->numWaveforms=readWord(file); //readWord(file);
104 gp->vol=readWord(file);
105 gp->datSize=readDWord(file);
106 gp->res=readData(file, 36);
107
108 gp->instrID=readWord(file);
109 gp->instrName=readData(file,16);
110 gp->instrSize=readDWord(file);
111 gp->layers=readChar(file);
112 gp->instrRes=readData(file,40);
113
114
115 gp->layerDup=readChar(file);
116 gp->layerID=readChar(file);
117 gp->layerSize=readDWord(file);
118 gp->numWaves=readChar(file);
119 gp->layerRes=readData(file,40);
120
121/* printf("\n%s\n%s\n%s", gp->header, gp->gravisid, gp->desc);
122 printf("\nInst = %d", gp->inst);
123 printf("\nVoc = %d", gp->voc);
124 printf("\nChan = %d", gp->chan);
125 printf("\nWav = %d", gp->numWaveforms);
126 printf("\nVol = %d", gp->vol);
127 printf("\nSize = %d", gp->datSize);
128
129 printf("\n\ninstrID = %d", gp->instrID);
130 printf("\ninstrName = %s", gp->instrName);
131// printf("\ninstrSize = %d", gp->instrSize);
132// printf("\nlayers = %d", gp->layers);
133*/
134 printf("\nFILE: %s", filename);
135 printf("\nlayerSamples=%d", gp->numWaves);
136
137 int a=0;
138 for(a=0; a<gp->numWaves; a++)
139 gp->waveforms[a] = loadWaveform(file);
140
141
142 printf("\nPrecomputing note table");
143
144 for(a=0; a<128; a++)
145 {
146 gp->noteTable[a] = selectWaveform(gp, a);
147 }
148 rb->close(file);
149
150 return gp;
151}