1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2  * Copyright (C) 2011-2017 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU Lesser General Public License as published by
6  *  the Free Software Foundation, either version 2.1 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MT32EMU_ROMINFO_H
19 #define MT32EMU_ROMINFO_H
20 
21 #include <cstddef>
22 
23 #include "globals.h"
24 #include "File.h"
25 
26 namespace MT32Emu {
27 
28 // Defines vital info about ROM file to be used by synth and applications
29 
30 struct ROMInfo {
31 public:
32 	size_t fileSize;
33 	const File::SHA1Digest &sha1Digest;
34 	enum Type {PCM, Control, Reverb} type;
35 	const char *shortName;
36 	const char *description;
37 	enum PairType {Full, FirstHalf, SecondHalf, Mux0, Mux1} pairType;
38 	ROMInfo *pairROMInfo;
39 
40 	// Returns a ROMInfo struct by inspecting the size and the SHA1 hash
41 	MT32EMU_EXPORT static const ROMInfo* getROMInfo(File *file);
42 
43 	// Currently no-op
44 	MT32EMU_EXPORT static void freeROMInfo(const ROMInfo *romInfo);
45 
46 	// Allows retrieving a NULL-terminated list of ROMInfos for a range of types and pairTypes
47 	// (specified by bitmasks)
48 	// Useful for GUI/console app to output information on what ROMs it supports
49 	MT32EMU_EXPORT static const ROMInfo** getROMInfoList(Bit32u types, Bit32u pairTypes);
50 
51 	// Frees the list of ROMInfos given
52 	MT32EMU_EXPORT static void freeROMInfoList(const ROMInfo **romInfos);
53 };
54 
55 // Synth::open() is to require a full control ROMImage and a full PCM ROMImage to work
56 
57 class ROMImage {
58 private:
59 	File * const file;
60 	const ROMInfo * const romInfo;
61 
62 	ROMImage(File *file);
63 	~ROMImage();
64 
65 public:
66 	// Creates a ROMImage object given a ROMInfo and a File. Keeps a reference
67 	// to the File and ROMInfo given, which must be freed separately by the user
68 	// after the ROMImage is freed
69 	MT32EMU_EXPORT static const ROMImage* makeROMImage(File *file);
70 
71 	// Must only be done after all Synths using the ROMImage are deleted
72 	MT32EMU_EXPORT static void freeROMImage(const ROMImage *romImage);
73 
74 	MT32EMU_EXPORT File *getFile() const;
75 	MT32EMU_EXPORT const ROMInfo *getROMInfo() const;
76 };
77 
78 } // namespace MT32Emu
79 
80 #endif // #ifndef MT32EMU_ROMINFO_H
81