]> 4ch.mooo.com Git - 16.git/blob - 16/adplug/adplug-2.2.1/src/xad.cpp
Please enter the commit message for your changes. Lines starting
[16.git] / 16 / adplug / adplug-2.2.1 / src / xad.cpp
1 /*
2   Adplug - Replayer for many OPL2/OPL3 audio file formats.
3   Copyright (C) 1999 - 2003 Simon Peter, <dn.tlp@gmx.net>, et al.
4
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.
9
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.
14
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
18
19   xad.cpp - XAD shell player by Riven the Mage <riven@ok.ru>
20 */
21
22 #include "xad.h"
23 #include "debug.h"
24
25 /* -------- Public Methods -------------------------------- */
26
27 CxadPlayer::CxadPlayer(Copl * newopl) : CPlayer(newopl)
28 {
29   tune = 0;
30 }
31
32 CxadPlayer::~CxadPlayer()
33 {
34   if (tune)
35     delete [] tune;
36 }
37
38 bool CxadPlayer::load(const std::string &filename, const CFileProvider &fp)
39 {
40   binistream *f = fp.open(filename); if(!f) return false;
41   bool ret = false;
42
43   // load header
44   xad.id = f->readInt(4);
45   f->readString(xad.title, 36);
46   f->readString(xad.author, 36);
47   xad.fmt = f->readInt(2);
48   xad.speed = f->readInt(1);
49   xad.reserved_a = f->readInt(1);
50
51   // 'XAD!' - signed ?
52   if(xad.id != 0x21444158) { fp.close(f); return false; }
53
54   // get file size
55   tune_size = fp.filesize(f) - 80;
56
57   // load()
58   tune = new unsigned char [tune_size];
59   f->readString((char *)tune, tune_size);
60   fp.close(f);
61
62   ret = xadplayer_load();
63
64   if (ret)
65     rewind(0);
66
67   return ret;
68 }
69
70 void CxadPlayer::rewind(int subsong)
71 {
72   opl->init();
73
74   plr.speed = xad.speed;
75   plr.speed_counter = 1;
76   plr.playing = 1;
77   plr.looping = 0;
78
79   // rewind()
80   xadplayer_rewind(subsong);
81
82 #ifdef DEBUG
83   AdPlug_LogWrite("-----------\n");
84 #endif
85 }
86
87 bool CxadPlayer::update()
88 {
89   if (--plr.speed_counter)
90     goto update_end;
91
92   plr.speed_counter = plr.speed;
93
94   // update()
95   xadplayer_update();
96
97 update_end:
98   return (plr.playing && (!plr.looping));
99 }
100
101 float CxadPlayer::getrefresh()
102 {
103   return xadplayer_getrefresh();
104 }
105
106 std::string CxadPlayer::gettype()
107 {
108   return xadplayer_gettype();
109 }
110
111 std::string CxadPlayer::gettitle()
112 {
113   return xadplayer_gettitle();
114 }
115
116 std::string CxadPlayer::getauthor()
117 {
118   return xadplayer_getauthor();
119 }
120
121 std::string CxadPlayer::getinstrument(unsigned int i)
122 {
123   return xadplayer_getinstrument(i);
124 }
125
126 unsigned int CxadPlayer::getinstruments()
127 {
128   return xadplayer_getinstruments();
129 }
130
131 /* -------- Protected Methods ------------------------------- */
132
133 void CxadPlayer::opl_write(int reg, int val)
134 {
135   adlib[reg] = val;
136 #ifdef DEBUG
137   AdPlug_LogWrite("[ %02X ] = %02X\n",reg,val);
138 #endif
139   opl->write(reg,val);
140 }