annotate Plugins/Input/adplug/core/database.cpp @ 1280:6ad7eb96dd26 trunk

[svn] Sync with upstream. This adds Westwood ADL format support.
author chainsaw
date Sat, 17 Jun 2006 16:17:51 -0700
parents 2b06eb5e472d
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
1 /*
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
2 * AdPlug - Replayer for many OPL2/OPL3 audio file formats.
637
2b06eb5e472d [svn] Sync with upstream. Drop hardware OPL2/3 support, it throws warnings and is not used on most modern machines. Added var inits where GCC 4.0 thought it was a good idea.
chainsaw
parents: 387
diff changeset
3 * Copyright (c) 1999 - 2006 Simon Peter <dn.tlp@gmx.net>, et al.
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
4 *
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
9 *
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
13 * Lesser General Public License for more details.
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
14 *
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
18 *
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
19 * database.cpp - AdPlug database class
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
20 * Copyright (c) 2002 Riven the Mage <riven@ok.ru>
637
2b06eb5e472d [svn] Sync with upstream. Drop hardware OPL2/3 support, it throws warnings and is not used on most modern machines. Added var inits where GCC 4.0 thought it was a good idea.
chainsaw
parents: 387
diff changeset
21 * Copyright (c) 2002, 2003, 2006 Simon Peter <dn.tlp@gmx.net>
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
22 */
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
23
387
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 379
diff changeset
24 #include <binio.h>
7f0e78f42032 [svn] Disable adplug if the includes are missing (or in a very lame place). Stop blowing holes in my ship.
chainsaw
parents: 379
diff changeset
25 #include <binfile.h>
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
26 #include <string.h>
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
27
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
28 #include "database.h"
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
29
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
30 #define DB_FILEID_V10 "AdPlug Module Information Database 1.0\x10"
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
31
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
32 /***** CAdPlugDatabase *****/
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
33
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
34 const unsigned short CAdPlugDatabase::hash_radix = 0xfff1; // should be prime
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
35
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
36 CAdPlugDatabase::CAdPlugDatabase()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
37 : linear_index(0), linear_logic_length(0), linear_length(0)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
38 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
39 db_linear = new DB_Bucket * [hash_radix];
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
40 db_hashed = new DB_Bucket * [hash_radix];
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
41 memset(db_linear, 0, sizeof(DB_Bucket *) * hash_radix);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
42 memset(db_hashed, 0, sizeof(DB_Bucket *) * hash_radix);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
43 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
44
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
45 CAdPlugDatabase::~CAdPlugDatabase()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
46 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
47 unsigned long i;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
48
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
49 for(i = 0; i < linear_length; i++)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
50 delete db_linear[i];
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
51
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
52 delete [] db_linear;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
53 delete [] db_hashed;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
54 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
55
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
56 bool CAdPlugDatabase::load(std::string db_name)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
57 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
58 binifstream f(db_name);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
59 if(f.error()) return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
60 return load(f);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
61 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
62
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
63 bool CAdPlugDatabase::load(binistream &f)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
64 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
65 unsigned int idlen = strlen(DB_FILEID_V10);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
66 char *id = new char [idlen];
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
67 unsigned long length;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
68
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
69 // Open database as little endian with IEEE floats
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
70 f.setFlag(binio::BigEndian, false); f.setFlag(binio::FloatIEEE);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
71
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
72 f.readString(id,idlen);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
73 if(memcmp(id,DB_FILEID_V10,idlen)) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
74 delete [] id;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
75 return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
76 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
77 delete [] id;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
78 length = f.readInt(4);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
79
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
80 // read records
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
81 for(unsigned long i = 0; i < length; i++)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
82 insert(CRecord::factory(f));
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
83
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
84 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
85 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
86
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
87 bool CAdPlugDatabase::save(std::string db_name)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
88 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
89 binofstream f(db_name);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
90 if(f.error()) return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
91 return save(f);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
92 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
93
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
94 bool CAdPlugDatabase::save(binostream &f)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
95 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
96 unsigned long i;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
97
637
2b06eb5e472d [svn] Sync with upstream. Drop hardware OPL2/3 support, it throws warnings and is not used on most modern machines. Added var inits where GCC 4.0 thought it was a good idea.
chainsaw
parents: 387
diff changeset
98 // Save database as little endian with IEEE floats
2b06eb5e472d [svn] Sync with upstream. Drop hardware OPL2/3 support, it throws warnings and is not used on most modern machines. Added var inits where GCC 4.0 thought it was a good idea.
chainsaw
parents: 387
diff changeset
99 f.setFlag(binio::BigEndian, false); f.setFlag(binio::FloatIEEE);
2b06eb5e472d [svn] Sync with upstream. Drop hardware OPL2/3 support, it throws warnings and is not used on most modern machines. Added var inits where GCC 4.0 thought it was a good idea.
chainsaw
parents: 387
diff changeset
100
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
101 f.writeString(DB_FILEID_V10);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
102 f.writeInt(linear_logic_length, 4);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
103
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
104 // write records
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
105 for(i = 0; i < linear_length; i++)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
106 if(!db_linear[i]->deleted)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
107 db_linear[i]->record->write(f);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
108
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
109 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
110 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
111
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
112 CAdPlugDatabase::CRecord *CAdPlugDatabase::search(CKey const &key)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
113 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
114 if(lookup(key)) return get_record(); else return 0;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
115 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
116
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
117 bool CAdPlugDatabase::lookup(CKey const &key)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
118 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
119 unsigned long index = make_hash(key);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
120 if(!db_hashed[index]) return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
121
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
122 // immediate hit ?
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
123 DB_Bucket *bucket = db_hashed[index];
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
124
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
125 if(!bucket->deleted && bucket->record->key == key) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
126 linear_index = bucket->index;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
127 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
128 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
129
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
130 // in-chain hit ?
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
131 bucket = db_hashed[index]->chain;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
132
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
133 while(bucket) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
134 if(!bucket->deleted && bucket->record->key == key) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
135 linear_index = bucket->index;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
136 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
137 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
138
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
139 bucket = bucket->chain;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
140 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
141
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
142 return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
143 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
144
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
145 bool CAdPlugDatabase::insert(CRecord *record)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
146 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
147 long index;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
148
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
149 // sanity checks
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
150 if(!record) return false; // null-pointer given
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
151 if(linear_length == hash_radix) return false; // max. db size exceeded
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
152 if(lookup(record->key)) return false; // record already in db
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
153
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
154 // make bucket
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
155 DB_Bucket *bucket = new DB_Bucket(linear_length, record);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
156 if(!bucket) return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
157
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
158 // add to linear list
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
159 db_linear[linear_length] = bucket;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
160 linear_logic_length++; linear_length++;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
161
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
162 // add to hashed list
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
163 index = make_hash(record->key);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
164
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
165 if(!db_hashed[index]) // First entry in hashtable
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
166 db_hashed[index] = bucket;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
167 else { // Add entry in chained list
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
168 DB_Bucket *chain = db_hashed[index];
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
169
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
170 while(chain->chain) chain = chain->chain;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
171 chain->chain = bucket;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
172 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
173
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
174 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
175 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
176
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
177 void CAdPlugDatabase::wipe(CRecord *record)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
178 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
179 if(!lookup(record->key)) return;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
180 wipe();
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
181 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
182
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
183 void CAdPlugDatabase::wipe()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
184 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
185 if(!linear_length) return;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
186
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
187 DB_Bucket *bucket = db_linear[linear_index];
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
188
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
189 if(!bucket->deleted) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
190 delete bucket->record;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
191 linear_logic_length--;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
192 bucket->deleted = true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
193 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
194 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
195
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
196 CAdPlugDatabase::CRecord *CAdPlugDatabase::get_record()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
197 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
198 if(!linear_length) return 0;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
199 return db_linear[linear_index]->record;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
200 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
201
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
202 bool CAdPlugDatabase::go_forward()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
203 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
204 if(linear_index + 1 < linear_length) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
205 linear_index++;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
206 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
207 } else
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
208 return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
209 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
210
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
211 bool CAdPlugDatabase::go_backward()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
212 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
213 if(!linear_index) return false;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
214 linear_index--;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
215 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
216 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
217
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
218 void CAdPlugDatabase::goto_begin()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
219 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
220 if(linear_length) linear_index = 0;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
221 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
222
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
223 void CAdPlugDatabase::goto_end()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
224 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
225 if(linear_length) linear_index = linear_length - 1;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
226 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
227
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
228 inline unsigned long CAdPlugDatabase::make_hash(CKey const &key)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
229 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
230 return (key.crc32 + key.crc16) % hash_radix;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
231 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
232
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
233 /***** CAdPlugDatabase::DB_Bucket *****/
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
234
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
235 CAdPlugDatabase::DB_Bucket::DB_Bucket(unsigned long nindex, CRecord *newrecord, DB_Bucket *newchain)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
236 : index(nindex), deleted(false), chain(newchain), record(newrecord)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
237 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
238 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
239
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
240 CAdPlugDatabase::DB_Bucket::~DB_Bucket()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
241 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
242 if(!deleted) delete record;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
243 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
244
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
245 /***** CAdPlugDatabase::CRecord *****/
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
246
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
247 CAdPlugDatabase::CRecord *CAdPlugDatabase::CRecord::factory(RecordType type)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
248 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
249 switch(type) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
250 case Plain: return new CPlainRecord;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
251 case SongInfo: return new CInfoRecord;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
252 case ClockSpeed: return new CClockRecord;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
253 default: return 0;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
254 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
255 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
256
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
257 CAdPlugDatabase::CRecord *CAdPlugDatabase::CRecord::factory(binistream &in)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
258 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
259 RecordType type;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
260 unsigned long size;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
261 CRecord *rec;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
262
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
263 type = (RecordType)in.readInt(1); size = in.readInt(4);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
264 rec = factory(type);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
265
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
266 if(rec) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
267 rec->key.crc16 = in.readInt(2); rec->key.crc32 = in.readInt(4);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
268 rec->filetype = in.readString('\0'); rec->comment = in.readString('\0');
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
269 rec->read_own(in);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
270 return rec;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
271 } else {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
272 // skip this record, cause we don't know about it
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
273 in.seek(size, binio::Add);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
274 return 0;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
275 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
276 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
277
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
278 void CAdPlugDatabase::CRecord::write(binostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
279 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
280 out.writeInt(type, 1);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
281 out.writeInt(get_size() + filetype.length() + comment.length() + 8, 4);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
282 out.writeInt(key.crc16, 2); out.writeInt(key.crc32, 4);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
283 out.writeString(filetype); out.writeInt('\0', 1);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
284 out.writeString(comment); out.writeInt('\0', 1);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
285
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
286 write_own(out);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
287 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
288
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
289 bool CAdPlugDatabase::CRecord::user_read(std::istream &in, std::ostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
290 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
291 return user_read_own(in, out);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
292 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
293
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
294 bool CAdPlugDatabase::CRecord::user_write(std::ostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
295 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
296 out << "Record type: ";
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
297 switch(type) {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
298 case Plain: out << "Plain"; break;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
299 case SongInfo: out << "SongInfo"; break;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
300 case ClockSpeed: out << "ClockSpeed"; break;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
301 default: out << "*** Unknown ***"; break;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
302 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
303 out << std::endl;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
304 out << "Key: " << std::hex << key.crc16 << ":" << key.crc32 << std::dec << std::endl;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
305 out << "File type: " << filetype << std::endl;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
306 out << "Comment: " << comment << std::endl;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
307
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
308 return user_write_own(out);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
309 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
310
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
311 /***** CAdPlugDatabase::CRecord::CKey *****/
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
312
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
313 CAdPlugDatabase::CKey::CKey(binistream &buf)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
314 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
315 make(buf);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
316 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
317
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
318 bool CAdPlugDatabase::CKey::operator==(const CKey &key)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
319 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
320 return ((crc16 == key.crc16) && (crc32 == key.crc32));
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
321 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
322
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
323 void CAdPlugDatabase::CKey::make(binistream &buf)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
324 // Key is CRC16:CRC32 pair. CRC16 and CRC32 calculation routines (c) Zhengxi
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
325 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
326 static const unsigned short magic16 = 0xa001;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
327 static const unsigned long magic32 = 0xedb88320;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
328
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
329 crc16 = 0; crc32 = ~0;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
330
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
331 while(!buf.eof())
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
332 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
333 unsigned char byte = buf.readInt(1);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
334
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
335 for (int j=0;j<8;j++)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
336 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
337 if ((crc16 ^ byte) & 1)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
338 crc16 = (crc16 >> 1) ^ magic16;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
339 else
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
340 crc16 >>= 1;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
341
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
342 if ((crc32 ^ byte) & 1)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
343 crc32 = (crc32 >> 1) ^ magic32;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
344 else
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
345 crc32 >>= 1;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
346
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
347 byte >>= 1;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
348 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
349 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
350
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
351 crc16 &= 0xffff;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
352 crc32 = ~crc32;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
353 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
354
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
355 /***** CInfoRecord *****/
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
356
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
357 CInfoRecord::CInfoRecord()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
358 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
359 type = SongInfo;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
360 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
361
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
362 void CInfoRecord::read_own(binistream &in)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
363 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
364 title = in.readString('\0');
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
365 author = in.readString('\0');
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
366 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
367
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
368 void CInfoRecord::write_own(binostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
369 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
370 out.writeString(title); out.writeInt('\0', 1);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
371 out.writeString(author); out.writeInt('\0', 1);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
372 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
373
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
374 unsigned long CInfoRecord::get_size()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
375 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
376 return title.length() + author.length() + 2;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
377 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
378
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
379 bool CInfoRecord::user_read_own(std::istream &in, std::ostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
380 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
381 out << "Title: "; in >> title;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
382 out << "Author: "; in >> author;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
383 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
384 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
385
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
386 bool CInfoRecord::user_write_own(std::ostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
387 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
388 out << "Title: " << title << std::endl;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
389 out << "Author: " << author << std::endl;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
390 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
391 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
392
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
393 /***** CClockRecord *****/
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
394
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
395 CClockRecord::CClockRecord()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
396 : clock(0.0f)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
397 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
398 type = ClockSpeed;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
399 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
400
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
401 void CClockRecord::read_own(binistream &in)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
402 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
403 clock = in.readFloat(binio::Single);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
404 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
405
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
406 void CClockRecord::write_own(binostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
407 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
408 out.writeFloat(clock, binio::Single);
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
409 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
410
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
411 unsigned long CClockRecord::get_size()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
412 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
413 return 4;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
414 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
415
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
416 bool CClockRecord::user_read_own(std::istream &in, std::ostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
417 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
418 out << "Clockspeed: "; in >> clock;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
419 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
420 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
421
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
422 bool CClockRecord::user_write_own(std::ostream &out)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
423 {
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
424 out << "Clock speed: " << clock << " Hz" << std::endl;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
425 return true;
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
426 }