sysex.c
31.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
#include <dmedia/midi.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <libaudio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "midiApp.h"
#include "midiDmon.h"
#include "midiGlobals.h"
#ifdef SYSEX_IMPL
#include <sysex.h>
#include <synthcommon.h>
void CreateInstrumentFile(char *instName);
void CreateSoundFile(char *soundName);
void CreateKeymapFile(char *keyMapName);
void CreateEnvelopeFile(char *envlpName);
void CreateObjectFiles(void);
void DumpInstFromOffset(u32 offset);
#define MAX_CHECK_STRS 31
array32 gCmmdStrList[MAX_CHECK_STRS]= {
"bank",
"preset", /* "Instrument:", */
"oscillator", /* "Sound:", */
"envelope",
"keymap",
"synthesizer present",
"ListAllBanks",
"ListAllInstruments",
"ListAllSounds",
"ListAllEnvelopes",
"ListAllKeymaps",
"ListAllWavetables",
"ListInstruments:",
"ListSounds:",
"CreateBank:",
"CreateInstrument:",
"CreateSound:",
"CreateKeymap:",
"CreateEnvelope:",
"CreateWavetable:",
"DeleteBank:",
"DeleteInstrument:",
"DeleteSound:",
"DeleteKeymap:",
"DeleteEnvelope:",
"DeleteWavetable:",
"CleanMemory",
"CompactMemory",
"SelectBank",
"SaveBanks",
"dump preset units"};
#define BANK_CMD 1
#define INST_CMD 2
#define SOUND_CMD 3
#define ENVLP_CMD 4
#define KMAP_CMD 5
#define PRESENT_STR 6
#define LIST_ALL_BANK 7
#define LIST_ALL_INST 8
#define LIST_ALL_SNDS 9
#define LIST_ALL_ENV 10
#define LIST_ALL_KMAP 11
#define LIST_ALL_WAVETBL 12
#define LIST_INSTS 13
#define LIST_SNDS 14
#define CREATE_BANK_CMD 15
#define CREATE_INST_CMD 16
#define CREATE_SND_CMD 17
#define CREATE_KMAP_CMD 18
#define CREATE_ENVLP_CMD 19
#define CREATE_WAVETBL_CMD 20
#define DELETE_BANK_CMD 21
#define DELETE_INST_CMD 22
#define DELETE_SND_CMD 23
#define DELETE_KMAP_CMD 24
#define DELETE_ENVLP_CMD 25
#define DELETE_WAVETBL_CMD 26
#define CLEAN_MEMORY_CMD 27
#define COMPACT_MEMORY_CMD 28
#define SELECT_BANK_CMD 29
#define SAVE_BANKS_CMD 30
#define DUMP_PRESETS_CMD 31
#define BANK_STR_LEN 4
#define INST_STR_LEN 6
#define SOUND_STR_LEN 10
#define KMAP_STR_LEN 6
#define ENVLP_STR_LEN 8
array32 gBankStrList[MAX_BANK_STRS] = {
"default",
"percussion",
"instCount",
"sampleRate",
"instrument" };
array32 gInstStrList[MAX_INST_STRS] = {
"volume",
"pan",
"priority",
"soundCount",
"sound" };
array32 gSoundStrList[MAX_SOUND_STRS] = {
"wavetable",
"keymap",
"envelope",
"pan",
"gain" };
array32 gEnvlpStrList[MAX_ENVLP_STRS] = {
"attackTime",
"attackLevel",
"decayTime",
"decayLevel",
"releaseTime" };
array32 gKmapStrList[MAX_KMAP_STRS] = {
"velocityMin",
"velocityMax",
"keyMin",
"keyMax",
"keyBase",
"detune" };
/******************************************************************
* ProcessSysEx Check to see if the sysex is SGI format, and that
* this isn't one we sent out. Parse by commandID, and call subroutines
* Check to make sure symbolfile is true.
*******************************************************************/
void ProcessSysEx(MDevent *mdv)
{
double dvalue;
char commandID;
char *data;
char *parameter,*ptr;
int strType;
char isSGI;
int sgiID;
isSGI = suIsSGISynthSystemExclusive(mdv);
if(!isSGI)
{
mdFree(mdv->sysexmsg);
return;
}
sgiID = suGetOriginID(mdv);
if(sgiID!=_SYNTH_NINTENDO_ID)
{
commandID = suGetCommandID(mdv);
parameter = suGetParameter(mdv);
ptr = parameter;
strType = CheckString(&ptr,gCmmdStrList,MAX_CHECK_STRS);
if(verbose)
{
int c;
fprintf(stderr,"%s: SGI SysEx msg, origin %d, command %d type %d\n",gAppName,
sgiID,commandID,strType);
for(c = 0; c < mdv->msglen; c++)
printf("%c ",mdv->sysexmsg[c]);
printf("\n");
}
switch (commandID)
{
case _AP_GET_BOOLEAN:
if(strType == PRESENT_STR)
{
AckPresent(parameter);
CreateObjectFiles();
}
break;
case _AP_GET_STRING:
HandleGetString(parameter,strType);
break;
case _AP_GET_NUMBER:
HandleGetNumber(parameter,strType);
break;
case _AP_SET_NUMBER:
data = suGetData(mdv);
dvalue = suNibblesToDouble(data);
HandleSetNumber(ptr,strType,dvalue);
break;
case _AP_SET_STRING:
data = suGetData(mdv);
HandleSetString(ptr,strType,data);
case _AP_TELL:
HandleTell(parameter,strType);
break;
}
}
mdFree(mdv->sysexmsg);
}
void HandleTell(char *param,int strType)
{
ALBankFile *myBankFile;
ALBank *defBank;
ALInstrument *defInst;
u32 defBankOffset,defInstOffset;
ALSymObj *instSymObj;
char *instName;
switch(strType)
{
case DUMP_PRESETS_CMD:
printf("Found a dump presets command\n");
myBankFile = (ALBankFile*)gMirror;
defBankOffset = (u32)myBankFile->bankArray[0];
defBank = (ALBank*)&gMirror[defBankOffset];
defInstOffset = (u32)defBank->instArray[0];
DumpInstFromOffset(defInstOffset);
break;
}
}
void DumpInstFromOffset(u32 offset)
{
char *instName,*sndName,*tmpPtr;
char tmpStr[256];
int c = 0;
instName = GetStrFromOffset(offset);
ReplyString("preset(default) path",instName); /* AP_SET_STRING "preset(default) path" "Piano44K" */
sprintf(tmpStr,"preset%s oscillators",instName);
sndName = BuildSoundList(instName);
ReplyString(tmpStr,sndName); /* AP_SET_STRING "presetPiano44K oscillators"
"Piano44K00 Piano44K01 Piano44K02 Piano44K03
Piano44K04 Piano44K05 Piano44K06 Piano44K07" */
while(sndName[c] != ' ')
c++;
sndName[c] = 0;
ReplyString("oscillator(default) path",tmpStr); /* AP_SET_STRING 'oscillator(default) path' 'Piano44K00' */
sprintf(tmpStr,"oscillator%s gain",sndName);
HandleGetSnd(tmpStr); /* AP_SET_NUMBER 'oscillatorPiano44K00 gain' '1.000000' */
free(sndName);
}
void HandleGetNumber(char *param,int strType)
{
switch(strType)
{
case BANK_CMD:
HandleGetBank(param);
break;
case INST_CMD:
HandleGetInst(param);
break;
case SOUND_CMD:
HandleGetSnd(param);
break;
case ENVLP_CMD:
HandleGetEnvlp(param);
break;
case KMAP_CMD:
HandleGetKmap(param);
break;
}
}
void HandleSetNumber(char *param,int strType,double dvalue)
{
switch(strType)
{
case BANK_CMD:
HandleSetBank(param,(char *)NULL,dvalue);
break;
case INST_CMD:
HandleSetInst(param,(char *)NULL,dvalue);
break;
case SOUND_CMD:
HandleSetSnd(param,(char *)NULL,dvalue);
break;
case ENVLP_CMD:
HandleSetEnvlp(param,dvalue);
break;
case KMAP_CMD:
HandleSetKmap(param,dvalue);
break;
}
}
void HandleGetString(char *param,int strType)
{
switch(strType)
{
case BANK_CMD:
HandleGetBank(param);
break;
case INST_CMD:
HandleGetInst(param);
break;
case SOUND_CMD:
HandleGetSnd(param);
break;
case LIST_ALL_BANK:
SendClassList(AL_BANK_CLASS,param);
break;
case LIST_ALL_INST:
SendClassList(AL_INST_CLASS,param);
break;
case LIST_ALL_SNDS:
SendClassList(AL_SOUND_CLASS,param);
break;
case LIST_ALL_ENV:
SendClassList(AL_ENVLP_CLASS,param);
break;
case LIST_ALL_KMAP:
SendClassList(AL_KEYMAP_CLASS,param);
break;
case LIST_ALL_WAVETBL:
SendClassList(AL_WAVETBL_CLASS,param);
break;
case LIST_INSTS:
SendInstList(param);
break;
case LIST_SNDS:
SendSoundList(param);
break;
}
}
void HandleSetString(char *param,int strType,char *data)
{
switch(strType)
{
case BANK_CMD:
HandleSetBank(param,data,(double)0);
break;
case INST_CMD:
HandleSetInst(param,data,(double)0);
break;
case SOUND_CMD:
HandleSetSnd(param,data,(double)0);
break;
case CREATE_BANK_CMD:
CreateBankObj(param,data);
break;
case CREATE_INST_CMD:
CreateInstObj(param,data);
break;
case CREATE_SND_CMD:
CreateSndObj(param,data);
break;
case CREATE_KMAP_CMD:
CreateKmapObj(param,data);
break;
case CREATE_ENVLP_CMD:
CreateEnvlpObj(param,data);
break;
case CREATE_WAVETBL_CMD:
CreateWavetblObj(param,data);
break;
case DELETE_BANK_CMD:
case DELETE_INST_CMD:
case DELETE_SND_CMD:
case DELETE_KMAP_CMD:
case DELETE_ENVLP_CMD:
case DELETE_WAVETBL_CMD:
DeleteObject(param);
break;
case CLEAN_MEMORY_CMD:
CleanMemory(0,0);
sleep(2); /* precautionary */
break;
case COMPACT_MEMORY_CMD:
CompactMemory();
sleep(2); /* precautionary */
break;
case SELECT_BANK_CMD:
SelectBank(data);
break;
case SAVE_BANKS_CMD:
SaveBanks(data);
break;
}
}
void HandleGetBank(char *param)
{
char *ptr = param + BANK_STR_LEN;
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry;
int paramValue,count;
u32 value;
ALBank *bankPtr;
ptr = parsename(ptr,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(&ptr,gBankStrList,MAX_BANK_STRS);
bankPtr = (ALBank*) &gMirror[entry->SFObj.bankFileOffset];
switch(paramValue)
{
case BANK_PERC_PARAM:
value = (u32) bankPtr->percussion;
ptr = GetStrFromOffset(value);
ReplyString(param,ptr);
break;
case BANK_INST_CT_PARAM:
value = (u32) bankPtr->instCount;
ReplyValue(param,value);
break;
case BANK_RATE_PARAM:
value = (u32) bankPtr->sampleRate;
ReplyValue(param,value);
break;
case BANK_INST_PARAM:
count = GetNumber(&ptr);
value = (u32) bankPtr->instArray[count];
ptr = GetStrFromOffset(value);
ReplyString(param,ptr);
break;
}
}
void HandleSetBank(char *param,char *data,double dvalue)
{
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry,*target;
int paramValue,count;
u32 offset,value,newOffset,oldObjOffset, blkVal;
ALBank *bankPtr;
value = (u32) dvalue;
param = parsename(param,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unable to match object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(¶m,gBankStrList,MAX_BANK_STRS);
bankPtr = (ALBank*)&gMirror[entry->SFObj.bankFileOffset];
offset = entry->SFObj.bankFileOffset + BANK_RDRAM_ADDR;
switch(paramValue)
{
case BANK_PERC_PARAM:
oldObjOffset = (u32)bankPtr->percussion;
DecRefCtFromOffset(oldObjOffset);
target = MatchHashName(data);
if(!target)
{
fprintf(stderr,"%s: Unknown target name %s\n",gAppName,data);
break;
}
target->SFObj.refCount++;
newOffset = target->SFObj.bankFileOffset;
bankPtr->percussion = (ALInstrument*)newOffset;
offset = (u32) &((ALBank*)offset)->percussion;
SetValue(offset,SET_32,newOffset+BANK_RDRAM_ADDR);
break;
case BANK_INST_CT_PARAM:
bankPtr->instCount = (s16)value;
offset = (u32) &((ALBank*)offset)->instCount;
SetValue(offset,SET_16,value);
break;
case BANK_RATE_PARAM:
bankPtr->sampleRate = (s32)value;
offset = (u32) &((ALBank*)offset)->sampleRate;
SetValue(offset,SET_32,value);
break;
case BANK_INST_PARAM:
count = GetNumber(¶m);
oldObjOffset = (u32)bankPtr->instArray[count];
DecRefCtFromOffset(oldObjOffset);
target = MatchHashName(data);
if(!target)
{
fprintf(stderr,"%s: Unknown target name %s\n",gAppName,data);
break;
}
target->SFObj.refCount++;
newOffset = target->SFObj.bankFileOffset;
bankPtr->instArray[count] = (ALInstrument*)newOffset;
offset = (u32) &((ALBank*)offset)->instArray[count];
SetValue(offset,SET_32,newOffset+BANK_RDRAM_ADDR);
FakeProgChnge(count);
break;
}
}
void HandleGetInst(char *param)
{
char *ptr = param + INST_STR_LEN;
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry;
int paramValue,count;
u32 value;
ALInstrument *instPtr;
ptr = parsename(ptr,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(&ptr,gInstStrList,MAX_INST_STRS);
instPtr = (ALInstrument*) &gMirror[entry->SFObj.bankFileOffset];
switch(paramValue)
{
case INST_VOLUME_PARAM:
value = (u32)instPtr->volume;
ReplyValue(param,value);
break;
case INST_PAN_PARAM:
value = (u32)instPtr->pan;
ReplyValue(param,value);
break;
case INST_PRIOR_PARAM:
value = (u32)instPtr->priority;
ReplyValue(param,value);
break;
case INST_SNDCOUNT_PARAM:
value = (u32)instPtr->soundCount;
ReplyValue(param,value);
break;
case INST_SNDARRAY_PARAM:
count = GetNumber(&ptr);
value = (u32)instPtr->soundArray[count];
ptr = GetStrFromOffset(value);
ReplyString(param,ptr);
break;
}
}
void HandleSetInst(char *param,char *data,double dvalue)
{
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry,*target;
int paramValue,count;
u32 offset,value,newOffset,oldObjOffset;
ALInstrument *instPtr;
value = (u32) dvalue;
param = parsename(param,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(¶m,gInstStrList,MAX_INST_STRS);
instPtr = (ALInstrument*)&gMirror[entry->SFObj.bankFileOffset];
offset = entry->SFObj.bankFileOffset + BANK_RDRAM_ADDR;
switch(paramValue)
{
case INST_VOLUME_PARAM:
instPtr->volume = (u8)value;
offset = (u32) &((ALInstrument*)offset)->volume;
SetValue(offset,SET_8,value);
break;
case INST_PAN_PARAM:
instPtr->pan = (u8)value;
offset = (u32) &((ALInstrument*)offset)->pan;
SetValue(offset,SET_8,value);
break;
case INST_PRIOR_PARAM:
instPtr->priority = (u8)value;
offset = (u32) &((ALInstrument*)offset)->priority;
SetValue(offset,SET_8,value);
break;
case INST_SNDCOUNT_PARAM:
instPtr->soundCount = (u32)value;
offset = (u32) &((ALInstrument*)offset)->soundCount;
SetValue(offset,SET_32,value);
break;
case INST_SNDARRAY_PARAM:
count = GetNumber(¶m);
oldObjOffset = (u32)instPtr->soundArray[count];
DecRefCtFromOffset(oldObjOffset);
target = MatchHashName(data);
if(!target)
{
fprintf(stderr,"%s: Unknown target name %s\n",gAppName,data);
break;
}
target->SFObj.refCount++;
newOffset = target->SFObj.bankFileOffset;
instPtr->soundArray[count] = (ALSound*)newOffset;
offset = (u32) &((ALInstrument*)offset)->soundArray[count];
SetValue(offset,SET_32,newOffset+BANK_RDRAM_ADDR);
break;
}
}
void HandleGetSnd(char *param)
{
char *ptr = param + SOUND_STR_LEN;
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry;
int paramValue;
u32 value;
ALSound *sndPtr;
ptr = parsename(ptr,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(&ptr,gSoundStrList,MAX_SOUND_STRS);
sndPtr = (ALSound*) &gMirror[entry->SFObj.bankFileOffset];
switch(paramValue)
{
case SND_SAMPLE_PARAM:
value = (u32)sndPtr->wavetable;
ptr = GetStrFromOffset(value);
ReplyString(param,ptr);
break;
case SND_KEYMAP_PARAM:
value = (u32)sndPtr->keyMap;
ptr = GetStrFromOffset(value);
ReplyString(param,ptr);
break;
case SND_ENVLP_PARAM:
value = (u32)sndPtr->envelope;
ptr = GetStrFromOffset(value);
ReplyString(param,ptr);
break;
case SND_PAN_PARAM:
value = (u32)sndPtr->samplePan;
ReplyValue(param,value);
break;
case SND_VOLUME_PARAM:
value = (u32)sndPtr->sampleVolume;
ReplyValue(param,value);
break;
}
printf("Done HandleGetSnd\n");
}
void HandleSetSnd(char *param,char *data,double dvalue)
{
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry,*target;
int paramValue;
u32 offset,value,newOffset,oldObjOffset;
ALSound *sndPtr;
printf("HandleSetSnd\n");
value = (u32) dvalue;
param = parsename(param,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(¶m,gSoundStrList,MAX_SOUND_STRS);
sndPtr = (ALSound*)&gMirror[entry->SFObj.bankFileOffset];
offset = entry->SFObj.bankFileOffset + BANK_RDRAM_ADDR;
switch(paramValue)
{
case SND_SAMPLE_PARAM:
oldObjOffset = (u32)sndPtr->wavetable;
DecRefCtFromOffset(oldObjOffset);
target = MatchHashName(data);
if(!target)
{
fprintf(stderr,"%s: Unknown target name %s\n",gAppName,data);
break;
}
target->SFObj.refCount++;
newOffset = target->SFObj.bankFileOffset;
sndPtr->wavetable = (ALWaveTable*)newOffset;
offset = (u32) &((ALSound*)offset)->wavetable;
newOffset+=BANK_RDRAM_ADDR;
SetValue(offset,SET_32,newOffset);
break;
case SND_KEYMAP_PARAM:
oldObjOffset = (u32)sndPtr->keyMap;
DecRefCtFromOffset(oldObjOffset);
target = MatchHashName(data);
if(!target)
{
fprintf(stderr,"%s: Unknown target name %s\n",gAppName,data);
break;
}
target->SFObj.refCount++;
newOffset = target->SFObj.bankFileOffset;
sndPtr->keyMap = (ALKeyMap*)newOffset;
offset = (u32) &((ALSound*)offset)->keyMap;
SetValue(offset,SET_32,newOffset+BANK_RDRAM_ADDR);
break;
case SND_ENVLP_PARAM:
oldObjOffset = (u32)sndPtr->envelope;
DecRefCtFromOffset(oldObjOffset);
target = MatchHashName(data);
if(!target)
{
fprintf(stderr,"%s: Unknown target name %s\n",gAppName,data);
break;
}
target->SFObj.refCount++;
newOffset = target->SFObj.bankFileOffset;
sndPtr->envelope = (ALEnvelope*)newOffset;
offset = (u32) &((ALSound*)offset)->envelope;
SetValue(offset,SET_32,newOffset+BANK_RDRAM_ADDR);
break;
case SND_PAN_PARAM:
sndPtr->samplePan = (u8)value;
offset = (u32) &((ALSound*)offset)->samplePan;
SetValue(offset,SET_8,value);
break;
case SND_VOLUME_PARAM:
sndPtr->sampleVolume = (u8)value;
offset = (u32) &((ALSound*)offset)->sampleVolume;
SetValue(offset,SET_8,value);
break;
}
}
void HandleGetEnvlp(char *param)
{
char *ptr = param + ENVLP_STR_LEN;
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry;
int paramValue;
u32 value;
ALEnvelope *envlpPtr;
ptr = parsename(ptr,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(&ptr,gEnvlpStrList,MAX_ENVLP_STRS);
envlpPtr = (ALEnvelope*) &gMirror[entry->SFObj.bankFileOffset];
switch(paramValue)
{
case ENVLP_ATTCK_TIME:
value = (u32)envlpPtr->attackTime;
break;
case ENVLP_ATTCK_LVL:
value = (u32)envlpPtr->attackVolume;
break;
case ENVLP_DECAY_TIME:
value = (u32)envlpPtr->decayTime;
break;
case ENVLP_DECAY_LVL:
value = (u32)envlpPtr->decayVolume;
break;
case ENVLP_REL_TIME:
value = (u32)envlpPtr->releaseTime;
break;
}
ReplyValue(param,value);
}
void HandleSetEnvlp(char *param,double dvalue)
{
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry;
int paramValue;
u32 offset,value;
ALEnvelope *envlpPtr;
printf("HandleSetEnvlp\n");
value = (u32)dvalue;
param = parsename(param,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(¶m,gEnvlpStrList,MAX_ENVLP_STRS);
envlpPtr = (ALEnvelope*)&gMirror[entry->SFObj.bankFileOffset];
offset = entry->SFObj.bankFileOffset + BANK_RDRAM_ADDR;
switch(paramValue)
{
case ENVLP_ATTCK_TIME:
envlpPtr->attackTime = value;
offset = (u32) &((ALEnvelope*)offset)->attackTime;
SetValue(offset,SET_32,value);
break;
case ENVLP_ATTCK_LVL:
envlpPtr->attackVolume = (u8)value;
offset = (u32) &((ALEnvelope*)offset)->attackVolume;
SetValue(offset,SET_8,value);
break;
case ENVLP_DECAY_TIME:
envlpPtr->decayTime = value;
offset = (u32) &((ALEnvelope*)offset)->decayTime;
SetValue(offset,SET_32,value);
break;
case ENVLP_DECAY_LVL:
envlpPtr->decayVolume = (u8)value;
offset = (u32) &((ALEnvelope*)offset)->decayVolume;
SetValue(offset,SET_8,value);
break;
case ENVLP_REL_TIME:
envlpPtr->releaseTime = value;
offset = (u32) &((ALEnvelope*)offset)->releaseTime;
SetValue(offset,SET_32,value);
break;
}
}
void HandleGetKmap(char *param)
{
char *ptr = param + KMAP_STR_LEN;
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry;
int paramValue;
u32 value;
ALKeyMap *kmapPtr;
ptr = parsename(ptr,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(&ptr,gKmapStrList,MAX_KMAP_STRS);
kmapPtr = (ALKeyMap*) &gMirror[entry->SFObj.bankFileOffset];
switch(paramValue)
{
case KMAP_VEL_MIN:
value = (u32)kmapPtr->velocityMin;
break;
case KMAP_VEL_MAX:
value = (u32)kmapPtr->velocityMax;
break;
case KMAP_KEY_MIN:
value = (u32)kmapPtr->keyMin;
break;
case KMAP_KEY_MAX:
value = (u32)kmapPtr->keyMax;
break;
case KMAP_KEYBASE:
value = (u32)kmapPtr->keyBase;
break;
case KMAP_DETUNE:
value = (u32)kmapPtr->detune;
break;
}
ReplyValue(param,value);
}
void HandleSetKmap(char *param,double dvalue)
{
char hashName[MAX_HASH_NAME_SIZE];
ALSymObj *entry;
int paramValue;
u32 offset,value;
ALKeyMap *kmapPtr;
value = (u32)dvalue;
param = parsename(param,hashName);
entry = MatchHashName(hashName);
if(!entry)
{
fprintf(stderr,"%s: Unknown object name %s\n",gAppName,hashName);
return;
}
paramValue = CheckString(¶m,gKmapStrList,MAX_KMAP_STRS);
kmapPtr = (ALKeyMap*)&gMirror[entry->SFObj.bankFileOffset];
offset = entry->SFObj.bankFileOffset + BANK_RDRAM_ADDR;
switch(paramValue)
{
case KMAP_VEL_MIN:
kmapPtr->velocityMin = (u8)value;
offset = (u32) &((ALKeyMap*)offset)->velocityMin;
break;
case KMAP_VEL_MAX:
kmapPtr->velocityMax = (u8)value;
offset = (u32) &((ALKeyMap*)offset)->velocityMax;
break;
case KMAP_KEY_MIN:
kmapPtr->keyMin = (u8)value;
offset = (u32) &((ALKeyMap*)offset)->keyMin;
break;
case KMAP_KEY_MAX:
kmapPtr->keyMax = (u8)value;
offset = (u32) &((ALKeyMap*)offset)->keyMax;
break;
case KMAP_KEYBASE:
kmapPtr->keyBase = (u8)value;
offset = (u32) &((ALKeyMap*)offset)->keyBase;
break;
case KMAP_DETUNE:
kmapPtr->detune = (u8)value;
offset = (u32) &((ALKeyMap*)offset)->detune;
break;
}
SetValue(offset,SET_8,value);
}
void SelectBank(char *data)
{
ALSymObj *target;
ALBankFile *bnkfPtr;
u32 i,offset;
int found = FALSE;
target = MatchHashName(data);
if(!target)
{
fprintf(stderr,"%s: Unknown bank name %s\n",gAppName,data);
return;
}
offset = target->SFObj.bankFileOffset;
bnkfPtr = (ALBankFile*)gMirror;
for(i=0;i<bnkfPtr->bankCount;i++)
{
if((u32)bnkfPtr->bankArray[i] == offset)
{
gCurBank = i;
found = TRUE;
break;
}
}
if(found == TRUE)
{
offset += BANK_RDRAM_ADDR;
SendSetBank(offset);
}
else
fprintf(stderr,"%s: Unable to identify bank in bankfile\n",gAppName);
sleep(3); /* safety precaution. if you do some stuff immediately following this, can cause crash */
}
void CreateObjectFiles(void)
{
int i;
mode_t myMode = 0xFFF;
mode_t oldMask;
oldMask = umask(0);
mkdir("/var/tmp/midiDmon",myMode);
mkdir("/var/tmp/midiDmon/instruments",myMode);
mkdir("/var/tmp/midiDmon/sounds",myMode);
mkdir("/var/tmp/midiDmon/keymaps",myMode);
mkdir("/var/tmp/midiDmon/envelopes",myMode);
for(i=0; i<gObjCt; i++)
{
switch(gSymObj[i].SFObj.objectClass)
{
case AL_INST_CLASS:
CreateInstrumentFile(&gNameBuffer[gSymObj[i].SFObj.stringOffset]);
break;
case AL_SOUND_CLASS:
CreateSoundFile(&gNameBuffer[gSymObj[i].SFObj.stringOffset]);
break;
case AL_KEYMAP_CLASS:
CreateKeymapFile(&gNameBuffer[gSymObj[i].SFObj.stringOffset]);
break;
case AL_ENVLP_CLASS:
CreateEnvelopeFile(&gNameBuffer[gSymObj[i].SFObj.stringOffset]);
break;
}
}
umask(oldMask);
printf("Done writing names\n");
}
void CreateInstrumentFile(char *instName)
{
char fName[256];
char dName[] = {"/var/tmp/midiDmon/instruments/"};
FILE *fHandle;
sprintf(fName,"%s%s",dName,instName);
fHandle = fopen(fName, "w");
if(!fHandle)
fprintf(stderr,"Instrument:Failed to open %s for writing preset\n",instName);
else
{
fprintf(fHandle, "#Synth Preset v1.0\n\n");
fprintf(fHandle, "PRESET\n");
fprintf(fHandle, "# INFORMATION\n");
fprintf(fHandle, "Information\n");
fprintf(fHandle, "\tPresetName:\t\"%s\"\n", instName);
fclose(fHandle);
}
}
void CreateSoundFile(char *soundName)
{
char fName[256];
char dName[] = {"/var/tmp/midiDmon/sounds/"};
FILE *fHandle;
sprintf(fName,"%s%s",dName,soundName);
fHandle = fopen(fName, "w");
if(!fHandle)
fprintf(stderr,"Sound:Failed to open %s for writing sound\n",soundName);
else
{
fprintf(fHandle, "#Synth Preset v1.0\n\n");
fprintf(fHandle, "PRESET\n");
fprintf(fHandle, "# INFORMATION\n");
fprintf(fHandle, "Information\n");
fprintf(fHandle, "\tPresetName:\t\"%s\"\n", soundName);
fclose(fHandle);
}
}
void CreateKeymapFile(char *keyMapName)
{
char fName[256];
char dName[] = {"/var/tmp/midiDmon/keymaps/"};
FILE *fHandle;
sprintf(fName,"%s%s",dName,keyMapName);
fHandle = fopen(fName, "w");
if(!fHandle)
fprintf(stderr,"Keymap:Failed to open %s for writing keymap\n",keyMapName);
else
{
fprintf(fHandle, "#Synth Preset v1.0\n\n");
fprintf(fHandle, "PRESET\n");
fprintf(fHandle, "# INFORMATION\n");
fprintf(fHandle, "Information\n");
fprintf(fHandle, "\tPresetName:\t\"%s\"\n", keyMapName);
fclose(fHandle);
}
}
void CreateEnvelopeFile(char *envlpName)
{
char fName[256];
char dName[] = {"/var/tmp/midiDmon/envelopes/"};
FILE *fHandle;
sprintf(fName,"%s%s",dName,envlpName);
fHandle = fopen(fName, "w");
if(!fHandle)
fprintf(stderr,"Envelope:Failed to open %s for writing envelope\n",envlpName);
else
{
fprintf(fHandle, "#Synth Preset v1.0\n\n");
fprintf(fHandle, "PRESET\n");
fprintf(fHandle, "# INFORMATION\n");
fprintf(fHandle, "Information\n");
fprintf(fHandle, "\tPresetName:\t\"%s\"\n", envlpName);
fclose(fHandle);
}
}
#endif /* SYSEX_IMPL */