2 Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 Copyright (C) 1999 - 2003 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
19 mad.cpp - MAD loader by Riven the Mage <riven@ok.ru>
25 /* -------- Public Methods -------------------------------- */
27 CPlayer *CmadLoader::factory(Copl *newopl)
29 return new CmadLoader(newopl);
32 bool CmadLoader::load(const std::string &filename, const CFileProvider &fp)
34 binistream *f = fp.open(filename); if(!f) return false;
35 const unsigned char conv_inst[10] = { 2,1,10,9,4,3,6,5,8,7 };
36 unsigned int i, j, k, t = 0;
39 char id[4]; f->readString(id, 4);
40 if (strncmp(id,"MAD+",4)) { fp.close(f); return false; }
43 for(i = 0; i < 9; i++) {
44 f->readString(instruments[i].name, 8);
45 for(j = 0; j < 12; j++) instruments[i].data[j] = f->readInt(1);
50 // data for Protracker
51 length = f->readInt(1); nop = f->readInt(1); timer = f->readInt(1);
54 realloc_instruments(9);
55 realloc_order(length);
56 realloc_patterns(nop,32,9);
60 for(i = 0; i < nop; i++)
61 for(k = 0; k < 32; k++)
62 for(j = 0; j < 9; j++) {
66 unsigned char event = f->readInt(1);
70 tracks[t][k].note = event;
71 if (event == 0xFF) // 0xFF: Release note
72 tracks[t][k].command = 8;
73 if (event == 0xFE) // 0xFE: Pattern Break
74 tracks[t][k].command = 13;
78 for(i = 0; i < length; i++) order[i] = f->readInt(1) - 1;
82 // convert instruments
83 for(i = 0; i < 9; i++)
84 for(j = 0; j < 10; j++)
85 inst[i].data[conv_inst[j]] = instruments[i].data[j];
87 // data for Protracker
95 void CmadLoader::rewind(int subsong)
97 CmodPlayer::rewind(subsong);
99 // default instruments
100 for (int i=0;i<9;i++)
104 channel[i].vol1 = 63 - (inst[i].data[10] & 63);
105 channel[i].vol2 = 63 - (inst[i].data[9] & 63);
109 float CmadLoader::getrefresh()
114 std::string CmadLoader::gettype()
116 return std::string("Mlat Adlib Tracker");
119 std::string CmadLoader::getinstrument(unsigned int n)
121 return std::string(instruments[n].name,8);
124 unsigned int CmadLoader::getinstruments()