2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2008 Simon Peter, <dn.tlp@gmx.net>, et al.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * MIDI & MIDI-like file player - Last Update: 10/15/2005
21 * by Phil Hassey - www.imitationpickles.org
22 * philhassey@hotmail.com
24 * Can play the following
25 * .LAA - a raw save of a Lucas Arts Adlib music
27 * a raw save of a LucasFilm Adlib music
28 * .MID - a "midi" save of a Lucas Arts Adlib music
29 * - or general MIDI files
30 * .CMF - Creative Music Format
31 * .SCI - the sierra "midi" format.
32 * Files must be in the form
34 * So that the loader can load the right patch file:
35 * xxxPATCH.003 (patch.003 must be saved from the
36 * sierra resource from each game.)
38 * 6/2/2000: v1.0 relased by phil hassey
39 * Status: LAA is almost perfect
40 * - some volumes are a bit off (intrument too quiet)
41 * MID is fine (who wants to listen to MIDI vid adlib anyway)
42 * CMF is okay (still needs the adlib rythm mode implemented
45 * Status: SCI: there are two SCI formats, orginal and advanced.
46 * original: (Found in SCI/EGA Sierra Adventures)
47 * played almost perfectly, I believe
48 * there is one mistake in the instrument
49 * loader that causes some sounds to
50 * not be quite right. Most sounds are fine.
51 * advanced: (Found in SCI/VGA Sierra Adventures)
52 * These are multi-track files. (Thus the
53 * player had to be modified to work with
54 * them.) This works fine.
55 * There are also multiple tunes in each file.
56 * I think some of them are supposed to be
57 * played at the same time, but I'm not sure
60 * Status: LAA: now EGA and VGA lucas games work pretty well
62 * 10/15/2005: Changes by Simon Peter
63 * Added rhythm mode support for CMF format.
65 * 09/13/2008: Changes by Adam Nielsen (malvineous@shikadi.net)
66 * Fixed a couple of CMF rhythm mode bugs
67 * Disabled note velocity for CMF files
68 * Added support for nonstandard CMF AM+VIB controller (for VGFM CMFs)
70 * Other acknowledgements:
71 * Allegro - for the midi instruments and the midi volume table
72 * SCUMM Revisited - for getting the .LAA / .MIDs out of those
74 * FreeSCI - for some information on the sci music files
75 * SD - the SCI Decoder (to get all .sci out of the Sierra files)
87 #define midiprintf printf
89 void CmidPlayer::midiprintf(const char *format, ...)
97 #define SIERRA_STYLE 8
99 // AdLib melodic and rhythm mode defines
100 #define ADLIB_MELODIC 0
101 #define ADLIB_RYTHM 1
107 #define FILE_SIERRA 4
108 #define FILE_ADVSIERRA 5
109 #define FILE_OLDLUCAS 6
111 // AdLib standard operator table
112 const unsigned char CmidPlayer::adlib_opadd[] = {0x00 ,0x01 ,0x02 ,0x08 ,0x09 ,0x0A ,0x10 ,0x11 ,0x12};
114 // map CMF drum channels 12 - 15 to corresponding AdLib drum operators
115 // bass drum (channel 11) not mapped, cause it's handled like a normal instrument
116 const int CmidPlayer::map_chan[] = { 0x14, 0x12, 0x15, 0x11 };
118 // Standard AdLib frequency table
119 const int CmidPlayer::fnums[] = { 0x16b,0x181,0x198,0x1b0,0x1ca,0x1e5,0x202,0x220,0x241,0x263,0x287,0x2ae };
121 // Map CMF drum channels 11 - 15 to corresponding AdLib drum channels
122 const int CmidPlayer::percussion_map[] = { 6, 7, 8, 8, 7 };
124 CPlayer *CmidPlayer::factory(Copl *newopl)
126 return new CmidPlayer(newopl);
129 CmidPlayer::CmidPlayer(Copl *newopl)
130 : CPlayer(newopl), author(&emptystr), title(&emptystr), remarks(&emptystr),
131 emptystr('\0'), flen(0), data(0)
135 unsigned char CmidPlayer::datalook(long pos)
137 if (pos<0 || pos >= flen) return(0);
141 unsigned long CmidPlayer::getnexti(unsigned long num)
146 for (i=0; i<num; i++)
148 v+=(datalook(pos)<<(8*i)); pos++;
153 unsigned long CmidPlayer::getnext(unsigned long num)
158 for (i=0; i<num; i++)
161 v+=datalook(pos); pos++;
166 unsigned long CmidPlayer::getval()
171 b=(unsigned char)getnext(1);
175 b=(unsigned char)getnext(1);
176 v = (v << 7) + (b & 0x7F);
181 bool CmidPlayer::load_sierra_ins(const std::string &fname, const CFileProvider &fp)
184 unsigned char ins[28];
188 pfilename = (char *)malloc(fname.length()+9);
189 strcpy(pfilename,fname.c_str());
191 for(i=strlen(pfilename)-1; i >= 0; i--)
192 if(pfilename[i] == '/' || pfilename[i] == '\\') {
196 sprintf(pfilename+j+3,"patch.003");
198 f = fp.open(pfilename);
209 midiprintf ("\n%2d: ",l);
211 ins[j] = f->readInt(1);
214 (ins[9]*0x80) + (ins[10]*0x40) +
215 (ins[5]*0x20) + (ins[11]*0x10) +
218 (ins[22]*0x80) + (ins[23]*0x40) +
219 (ins[18]*0x20) + (ins[24]*0x10) +
222 myinsbank[l][2]=(ins[0]<<6)+ins[8];
223 myinsbank[l][3]=(ins[13]<<6)+ins[21];
225 myinsbank[l][4]=(ins[3]<<4)+ins[6];
226 myinsbank[l][5]=(ins[16]<<4)+ins[19];
227 myinsbank[l][6]=(ins[4]<<4)+ins[7];
228 myinsbank[l][7]=(ins[17]<<4)+ins[20];
230 myinsbank[l][8]=ins[26];
231 myinsbank[l][9]=ins[27];
233 myinsbank[l][10]=((ins[2]<<1))+(1-(ins[12]&1));
234 //(ins[12] ? 0:1)+((ins[2]<<1));
237 midiprintf ("%02X ",myinsbank[l][j]);
244 memcpy(smyinsbank, myinsbank, 128 * 16);
248 void CmidPlayer::sierra_next_section()
255 midiprintf("\n\nnext adv sierra section:\n");
263 track[curtrack].on=1;
264 track[curtrack].spos = getnext(1);
265 track[curtrack].spos += (getnext(1) << 8) + 4; //4 best usually +3? not 0,1,2 or 5
266 // track[curtrack].spos=getnext(1)+(getnext(1)<<8)+4; // dynamite!: doesn't optimize correctly!!
267 track[curtrack].tend=flen; //0xFC will kill it
268 track[curtrack].iwait=0;
269 track[curtrack].pv=0;
270 midiprintf ("track %d starts at %lx\n",curtrack,track[curtrack].spos);
284 bool CmidPlayer::load(const std::string &filename, const CFileProvider &fp)
286 binistream *f = fp.open(filename); if(!f) return false;
290 f->readString((char *)s, 6);
296 if (s[1]=='D' && s[2]=='L') good=FILE_LUCAS;
299 if (s[1]=='T' && s[2]=='h' && s[3]=='d') good=FILE_MIDI;
302 if (s[1]=='T' && s[2]=='M' && s[3]=='F') good=FILE_CMF;
305 if (s[1]==0x00 && load_sierra_ins(filename, fp)) {
313 if (s[4]=='A' && s[5]=='D') good=FILE_OLDLUCAS;
326 flen = fp.filesize(f);
327 data = new unsigned char [flen];
328 f->readString((char *)data, flen);
335 void CmidPlayer::midi_write_adlib(unsigned int r, unsigned char v)
341 void CmidPlayer::midi_fm_instrument(int voice, unsigned char *inst)
343 if ((adlib_style&SIERRA_STYLE)!=0)
344 midi_write_adlib(0xbd,0); //just gotta make sure this happens..
345 //'cause who knows when it'll be
349 midi_write_adlib(0x20+adlib_opadd[voice],inst[0]);
350 midi_write_adlib(0x23+adlib_opadd[voice],inst[1]);
352 if (adlib_style & LUCAS_STYLE) {
353 midi_write_adlib(0x43+adlib_opadd[voice],0x3f);
354 if ((inst[10] & 1)==0)
355 midi_write_adlib(0x40+adlib_opadd[voice],inst[2]);
357 midi_write_adlib(0x40+adlib_opadd[voice],0x3f);
359 } else if ((adlib_style & SIERRA_STYLE) || (adlib_style & CMF_STYLE)) {
360 midi_write_adlib(0x40+adlib_opadd[voice],inst[2]);
361 midi_write_adlib(0x43+adlib_opadd[voice],inst[3]);
364 midi_write_adlib(0x40+adlib_opadd[voice],inst[2]);
365 if ((inst[10] & 1)==0)
366 midi_write_adlib(0x43+adlib_opadd[voice],inst[3]);
368 midi_write_adlib(0x43+adlib_opadd[voice],0);
371 midi_write_adlib(0x60+adlib_opadd[voice],inst[4]);
372 midi_write_adlib(0x63+adlib_opadd[voice],inst[5]);
373 midi_write_adlib(0x80+adlib_opadd[voice],inst[6]);
374 midi_write_adlib(0x83+adlib_opadd[voice],inst[7]);
375 midi_write_adlib(0xe0+adlib_opadd[voice],inst[8]);
376 midi_write_adlib(0xe3+adlib_opadd[voice],inst[9]);
378 midi_write_adlib(0xc0+voice,inst[10]);
381 void CmidPlayer::midi_fm_percussion(int ch, unsigned char *inst)
383 int opadd = map_chan[ch - 12];
385 midi_write_adlib(0x20 + opadd, inst[0]);
386 midi_write_adlib(0x40 + opadd, inst[2]);
387 midi_write_adlib(0x60 + opadd, inst[4]);
388 midi_write_adlib(0x80 + opadd, inst[6]);
389 midi_write_adlib(0xe0 + opadd, inst[8]);
390 if (opadd < 0x13) // only output this for the modulator, not the carrier, as it affects the entire channel
391 midi_write_adlib(0xc0 + percussion_map[ch - 11], inst[10]);
394 void CmidPlayer::midi_fm_volume(int voice, int volume)
398 if ((adlib_style&SIERRA_STYLE)==0) //sierra likes it loud!
402 if ((adlib_style&LUCAS_STYLE)!=0)
404 if ((adlib_data[0xc0+voice]&1)==1)
405 midi_write_adlib(0x40+adlib_opadd[voice], (unsigned char)((63-vol) |
406 (adlib_data[0x40+adlib_opadd[voice]]&0xc0)));
407 midi_write_adlib(0x43+adlib_opadd[voice], (unsigned char)((63-vol) |
408 (adlib_data[0x43+adlib_opadd[voice]]&0xc0)));
412 if ((adlib_data[0xc0+voice]&1)==1)
413 midi_write_adlib(0x40+adlib_opadd[voice], (unsigned char)((63-vol) |
414 (adlib_data[0x40+adlib_opadd[voice]]&0xc0)));
415 midi_write_adlib(0x43+adlib_opadd[voice], (unsigned char)((63-vol) |
416 (adlib_data[0x43+adlib_opadd[voice]]&0xc0)));
421 void CmidPlayer::midi_fm_playnote(int voice, int note, int volume)
423 int freq=fnums[note%12];
427 midi_fm_volume(voice,volume);
428 midi_write_adlib(0xa0+voice,(unsigned char)(freq&0xff));
430 c=((freq&0x300) >> 8)+((oct&7)<<2) + (adlib_mode == ADLIB_MELODIC || voice < 6 ? (1<<5) : 0);
431 midi_write_adlib(0xb0+voice,(unsigned char)c);
434 void CmidPlayer::midi_fm_endnote(int voice)
436 //midi_fm_volume(voice,0);
437 //midi_write_adlib(0xb0+voice,0);
439 midi_write_adlib(0xb0+voice,(unsigned char)(adlib_data[0xb0+voice]&(255-32)));
442 void CmidPlayer::midi_fm_reset()
448 for (i=0; i<256; i++)
449 midi_write_adlib(i,0);
451 midi_write_adlib(0x01, 0x20);
452 midi_write_adlib(0xBD,0xc0);
455 bool CmidPlayer::update()
457 long w,v,note,vel,ctrl,nv,x,l,lnum;
464 // just get the first wait and ignore it :>
465 for (curtrack=0; curtrack<16; curtrack++)
466 if (track[curtrack].on)
468 pos=track[curtrack].pos;
469 if (type != FILE_SIERRA && type !=FILE_ADVSIERRA)
470 track[curtrack].iwait+=getval();
472 track[curtrack].iwait+=getnext(1);
473 track[curtrack].pos=pos;
481 while (iwait==0 && ret==1)
483 for (curtrack=0; curtrack<16; curtrack++)
484 if (track[curtrack].on && track[curtrack].iwait==0 &&
485 track[curtrack].pos < track[curtrack].tend)
487 pos=track[curtrack].pos;
491 // This is to do implied MIDI events.
492 if (v<0x80) {v=track[curtrack].pv; pos--;}
493 track[curtrack].pv=(unsigned char)v;
496 midiprintf ("[%2X]",v);
499 case 0x80: /*note off*/
500 note=getnext(1); vel=getnext(1);
502 if (chp[i][0]==c && chp[i][1]==note)
508 case 0x90: /*note on*/
510 note=getnext(1); vel=getnext(1);
512 if(adlib_mode == ADLIB_RYTHM)
522 if(c < 11 || adlib_mode == ADLIB_MELODIC) {
525 for (i=0; i<numchan; i++)
526 if (chp[i][0]==-1 && chp[i][2]>onl)
527 { onl=chp[i][2]; on=i; j=1; }
532 for (i=0; i<numchan; i++)
534 { onl=chp[i][2]; on=i; }
540 on = percussion_map[c - 11];
542 if (vel!=0 && ch[c].inum>=0 && ch[c].inum<128) {
543 if (adlib_mode == ADLIB_MELODIC || c < 12) // 11 == bass drum, handled like a normal instrument, on == channel 6 thanks to percussion_map[] above
544 midi_fm_instrument(on,ch[c].ins);
546 midi_fm_percussion(c, ch[c].ins);
548 if (adlib_style & MIDI_STYLE) {
549 nv=((ch[c].vol*vel)/128);
550 if ((adlib_style&LUCAS_STYLE)!=0) nv*=2;
552 nv=my_midi_fm_vol_table[nv];
553 if ((adlib_style&LUCAS_STYLE)!=0)
554 nv=(int)((float)sqrt((float)nv)*11);
555 } else if (adlib_style & CMF_STYLE) {
556 // CMF doesn't support note velocity (even though some files have them!)
562 midi_fm_playnote(on,note+ch[c].nshift,nv*2); // sets freq in rhythm mode
567 if(adlib_mode == ADLIB_RYTHM && c >= 11) {
568 // Still need to turn off the perc instrument before playing it again,
569 // as not all songs send a noteoff.
570 midi_write_adlib(0xbd, adlib_data[0xbd] & ~(0x10 >> (c - 11)));
571 // Play the perc instrument
572 midi_write_adlib(0xbd, adlib_data[0xbd] | (0x10 >> (c - 11)));
576 if (vel==0) { //same code as end note
577 if (adlib_mode == ADLIB_RYTHM && c >= 11) {
578 // Turn off the percussion instrument
579 midi_write_adlib(0xbd, adlib_data[0xbd] & ~(0x10 >> (c - 11)));
580 //midi_fm_endnote(percussion_map[c]);
581 chp[percussion_map[c - 11]][0]=-1;
583 for (i=0; i<9; i++) {
584 if (chp[i][0]==c && chp[i][1]==note) {
585 // midi_fm_volume(i,0); // really end the note
592 // i forget what this is for.
597 midiprintf(" [%d:%d:%d:%d]\n",c,ch[c].inum,note,vel);
602 case 0xa0: /*key after touch */
603 note=getnext(1); vel=getnext(1);
604 /* //this might all be good
606 if (chp[i][0]==c & chp[i][1]==note)
608 midi_fm_playnote(i,note+cnote[c],my_midi_fm_vol_table[(cvols[c]*vel)/128]*2);
611 case 0xb0: /*control change .. pitch bend? */
612 ctrl=getnext(1); vel=getnext(1);
617 midiprintf ("(pb:%d: %d %d)",c,ctrl,vel);
622 if (adlib_style & CMF_STYLE) {
623 // Custom extension to allow CMF files to switch the
624 // AM+VIB depth on and off (officially this is on,
625 // and there's no way to switch it off.) Controller
631 midi_write_adlib(0xbd, (adlib_data[0xbd] & ~0xC0) | (vel << 6));
632 midiprintf(" AM+VIB depth change - AM %s, VIB %s\n",
633 (adlib_data[0xbd] & 0x80) ? "on" : "off",
634 (adlib_data[0xbd] & 0x40) ? "on" : "off"
639 midiprintf("Rhythm mode: %d\n", vel);
640 if ((adlib_style&CMF_STYLE)!=0) {
642 if(adlib_mode == ADLIB_RYTHM)
643 midi_write_adlib(0xbd, adlib_data[0xbd] | (1 << 5));
645 midi_write_adlib(0xbd, adlib_data[0xbd] & ~(1 << 5));
650 case 0xc0: /*patch change*/
654 ch[c].ins[j]=myinsbank[ch[c].inum][j];
656 case 0xd0: /*chanel touch*/
659 case 0xe0: /*pitch wheel*/
669 if (datalook(pos+l)==0xf7)
671 midiprintf("{%d}",l);
674 if (datalook(pos)==0x7d &&
675 datalook(pos+1)==0x10 &&
678 adlib_style=LUCAS_STYLE|MIDI_STYLE;
681 midiprintf ("%x ",datalook(pos+i));
682 if ((i-3)%10 == 0) midiprintf("\n");
690 // getnext(22); //temp
691 ch[c].ins[0]=(unsigned char)((getnext(1)<<4)+getnext(1));
692 ch[c].ins[2]=(unsigned char)(0xff-(((getnext(1)<<4)+getnext(1))&0x3f));
693 ch[c].ins[4]=(unsigned char)(0xff-((getnext(1)<<4)+getnext(1)));
694 ch[c].ins[6]=(unsigned char)(0xff-((getnext(1)<<4)+getnext(1)));
695 ch[c].ins[8]=(unsigned char)((getnext(1)<<4)+getnext(1));
697 ch[c].ins[1]=(unsigned char)((getnext(1)<<4)+getnext(1));
698 ch[c].ins[3]=(unsigned char)(0xff-(((getnext(1)<<4)+getnext(1))&0x3f));
699 ch[c].ins[5]=(unsigned char)(0xff-((getnext(1)<<4)+getnext(1)));
700 ch[c].ins[7]=(unsigned char)(0xff-((getnext(1)<<4)+getnext(1)));
701 ch[c].ins[9]=(unsigned char)((getnext(1)<<4)+getnext(1));
703 i=(getnext(1)<<4)+getnext(1);
706 //if ((i&1)==1) ch[c].ins[10]=1;
708 midiprintf ("\n%d: ",c);
710 midiprintf ("%2X ",ch[c].ins[i]);
717 midiprintf ("%2X ",getnext(1));
736 case 0xf6: /*something*/
741 //this ends the track for sierra.
742 if (type == FILE_SIERRA ||
743 type == FILE_ADVSIERRA)
745 track[curtrack].tend=pos;
746 midiprintf ("endmark: %ld -- %lx\n",pos,pos);
757 midiprintf("{%X_%X}",v,l);
761 msqtr=lnum; /*set tempo*/
762 midiprintf ("(qtr=%ld)",msqtr);
767 midiprintf ("%2X ",getnext(1));
772 default: midiprintf("!",v); /* if we get down here, a error occurred */
776 if (pos < track[curtrack].tend)
778 if (type != FILE_SIERRA && type !=FILE_ADVSIERRA)
782 track[curtrack].iwait=w;
786 midiprintf("\n<%d>",w);
788 ((float)w/(float)deltas)*((float)msqtr/(float)1000000);
789 if (doing==1) f=0; //not playing yet. don't wait yet
794 track[curtrack].iwait=0;
796 track[curtrack].pos=pos;
800 ret=0; //end of song.
802 for (curtrack=0; curtrack<16; curtrack++)
803 if (track[curtrack].on == 1 &&
804 track[curtrack].pos < track[curtrack].tend)
809 iwait=0xffffff; // bigger than any wait can be!
810 for (curtrack=0; curtrack<16; curtrack++)
811 if (track[curtrack].on == 1 &&
812 track[curtrack].pos < track[curtrack].tend &&
813 track[curtrack].iwait < iwait)
814 iwait=track[curtrack].iwait;
819 if (iwait !=0 && ret==1)
821 for (curtrack=0; curtrack<16; curtrack++)
822 if (track[curtrack].on)
823 track[curtrack].iwait-=iwait;
826 fwait=1.0f/(((float)iwait/(float)deltas)*((float)msqtr/(float)1000000));
829 fwait=50; // 1/50th of a second
834 if (track[i].pos < track[i].tend)
835 midiprintf ("<%d>",track[i].iwait);
841 if (ret==0 && type==FILE_ADVSIERRA)
842 if (datalook(sierra_pos-2)!=0xff)
844 midiprintf ("next sectoin!");
845 sierra_next_section(p);
857 float CmidPlayer::getrefresh()
859 return (fwait > 0.01f ? fwait : 0.01f);
862 void CmidPlayer::rewind(int subsong)
866 unsigned char ins[16];
869 adlib_style=MIDI_STYLE|CMF_STYLE;
870 adlib_mode=ADLIB_MELODIC;
871 for (i=0; i<128; i++)
873 myinsbank[i][j]=midi_fm_instruments[i][j];
878 ch[i].ins[j]=myinsbank[ch[i].inum][j];
891 deltas=250; // just a number, not a standard
893 fwait=123; // gotta be a small thing.. sorta like nothing
909 /* specific to file-type init */
916 getnext(24); //skip junk and get to the midi.
917 adlib_style=LUCAS_STYLE|MIDI_STYLE;
918 //note: no break, we go right into midi headers...
920 if (type != FILE_LUCAS)
922 getnext(11); /*skip header*/
924 midiprintf ("deltas:%ld\n",deltas);
928 track[curtrack].on=1;
929 track[curtrack].tend=getnext(4);
930 track[curtrack].spos=pos;
931 midiprintf ("tracklen:%ld\n",track[curtrack].tend);
935 getnexti(2); //version
936 n=getnexti(2); // instrument offset
937 m=getnexti(2); // music offset
938 deltas=getnexti(2); //ticks/qtr note
939 msqtr=1000000/getnexti(2)*deltas;
940 //the stuff in the cmf is click ticks per second..
943 if(i) title = (char *)data+i;
945 if(i) author = (char *)data+i;
947 if(i) remarks = (char *)data+i;
949 getnext(16); // channel in use table ..
950 i=getnexti(2); // num instr
951 if (i>128) i=128; // to ward of bad numbers...
952 getnexti(2); //basic tempo
954 midiprintf("\nioff:%d\nmoff%d\ndeltas:%ld\nmsqtr:%ld\nnumi:%d\n",
956 pos=n; // jump to instruments
960 midiprintf ("\n%d: ",j);
963 myinsbank[j][l]=(unsigned char)getnext(1);
964 midiprintf ("%2X ",myinsbank[j][l]);
971 adlib_style=CMF_STYLE;
974 track[curtrack].on=1;
975 track[curtrack].tend=flen; // music until the end of the file
976 track[curtrack].spos=m; //jump to midi music
984 pos=0x19; // jump to instruments
988 midiprintf ("\n%d: ",j);
990 ins[l]=(unsigned char)getnext(1);
992 myinsbank[j][10]=ins[2];
993 myinsbank[j][0]=ins[3];
994 myinsbank[j][2]=ins[4];
995 myinsbank[j][4]=ins[5];
996 myinsbank[j][6]=ins[6];
997 myinsbank[j][8]=ins[7];
998 myinsbank[j][1]=ins[8];
999 myinsbank[j][3]=ins[9];
1000 myinsbank[j][5]=ins[10];
1001 myinsbank[j][7]=ins[11];
1002 myinsbank[j][9]=ins[12];
1004 for (l=0; l<11; l++)
1005 midiprintf ("%2X ",myinsbank[j][l]);
1008 for (i=0; i<16; i++)
1013 for (j=0; j<11; j++)
1014 ch[i].ins[j]=myinsbank[ch[i].inum][j];
1018 adlib_style=LUCAS_STYLE|MIDI_STYLE;
1021 track[curtrack].on=1;
1022 track[curtrack].tend=flen; // music until the end of the file
1023 track[curtrack].spos=0x98; //jump to midi music
1025 case FILE_ADVSIERRA:
1026 memcpy(myinsbank, smyinsbank, 128 * 16);
1029 getnext(11); //worthless empty space and "stuff" :)
1031 o_sierra_pos=sierra_pos=pos;
1032 sierra_next_section();
1033 while (datalook(sierra_pos-2)!=0xff)
1035 sierra_next_section();
1039 if (subsong < 0 || subsong >= subsongs) subsong=0;
1041 sierra_pos=o_sierra_pos;
1042 sierra_next_section();
1044 while (i != subsong)
1046 sierra_next_section();
1050 adlib_style=SIERRA_STYLE|MIDI_STYLE; //advanced sierra tunes use volume
1053 memcpy(myinsbank, smyinsbank, 128 * 16);
1059 track[curtrack].on=1;
1060 track[curtrack].tend=flen; // music until the end of the file
1062 for (i=0; i<16; i++)
1065 ch[i].on=getnext(1);
1066 ch[i].inum=getnext(1);
1067 for (j=0; j<11; j++)
1068 ch[i].ins[j]=myinsbank[ch[i].inum][j];
1071 track[curtrack].spos=pos;
1072 adlib_style=SIERRA_STYLE|MIDI_STYLE;
1077 /* sprintf(info,"%s\r\nTicks/Quarter Note: %ld\r\n",info,deltas);
1078 sprintf(info,"%sms/Quarter Note: %ld",info,msqtr); */
1080 for (i=0; i<16; i++)
1083 track[i].pos=track[i].spos;
1092 std::string CmidPlayer::gettype()
1096 return std::string("LucasArts AdLib MIDI");
1098 return std::string("General MIDI");
1100 return std::string("Creative Music Format (CMF MIDI)");
1102 return std::string("Lucasfilm Adlib MIDI");
1103 case FILE_ADVSIERRA:
1104 return std::string("Sierra On-Line VGA MIDI");
1106 return std::string("Sierra On-Line EGA MIDI");
1108 return std::string("MIDI unknown");