comparison src/console/Gme_File.h @ 316:fb513e10174e trunk

[svn] - merge libconsole-blargg into mainline libconsole: + obsoletes plugins-ugly:sapplug
author nenolod
date Thu, 30 Nov 2006 19:54:33 -0800
parents
children 986f098da058
comparison
equal deleted inserted replaced
315:2294f3a6f136 316:fb513e10174e
1 // Common interface to game music file loading and information
2
3 // Game_Music_Emu 0.5.1
4 #ifndef GME_FILE_H
5 #define GME_FILE_H
6
7 #include "gme.h"
8 #include "blargg_common.h"
9 #include "Data_Reader.h"
10 #include "M3u_Playlist.h"
11
12 // Error returned if file is wrong type
13 //extern const char gme_wrong_file_type []; // declared in gme.h
14
15 struct Gme_File {
16 public:
17 // File loading
18
19 // Each loads game music data from a file and returns an error if
20 // file is wrong type or is seriously corrupt. They also set warning
21 // string for minor problems.
22
23 // Load from file on disk
24 blargg_err_t load_file( const char* path );
25
26 // Load from custom data source (see Data_Reader.h)
27 blargg_err_t load( Data_Reader& );
28
29 // Load from file already read into memory. Keeps pointer to data, so you
30 // must not free it until you're done with the file.
31 blargg_err_t load_mem( void const* data, long size );
32
33 // Load an m3u playlist. Must be done after loading main music file.
34 blargg_err_t load_m3u( const char* path );
35 blargg_err_t load_m3u( Data_Reader& in );
36
37 // Clears any loaded m3u playlist and any internal playlist that the music
38 // format supports (NSFE for example).
39 void clear_playlist();
40
41 // Informational
42
43 // Type of emulator. For example if this returns gme_nsfe_type, this object
44 // is an NSFE emulator, and you can cast to an Nsfe_Emu* if necessary.
45 gme_type_t type() const;
46
47 // Most recent warning string, or NULL if none. Clears current warning after
48 // returning.
49 const char* warning();
50
51 // Number of tracks or 0 if no file has been loaded
52 int track_count() const;
53
54 // Get information for a track (length, name, author, etc.)
55 // See gme.h for definition of struct track_info_t.
56 blargg_err_t track_info( track_info_t* out, int track ) const;
57
58 public:
59 // deprecated
60 int error_count() const; // use warning()
61 public:
62 Gme_File();
63 virtual ~Gme_File();
64 BLARGG_DISABLE_NOTHROW
65 typedef BOOST::uint8_t byte;
66 protected:
67 // Services
68 void set_track_count( int n ) { track_count_ = raw_track_count_ = n; }
69 void set_warning( const char* s ) { warning_ = s; }
70 void set_type( gme_type_t t ) { type_ = t; }
71 blargg_err_t load_remaining_( void const* header, long header_size, Data_Reader& remaining );
72
73 // Overridable
74 virtual void unload(); // called before loading file and if loading fails
75 virtual blargg_err_t load_( Data_Reader& ); // default loads then calls load_mem_()
76 virtual blargg_err_t load_mem_( byte const* data, long size ); // use data in memory
77 virtual blargg_err_t track_info_( track_info_t* out, int track ) const = 0;
78 virtual void pre_load();
79 virtual void post_load_();
80 virtual void clear_playlist_() { }
81
82 protected:
83 blargg_err_t remap_track( int* track_io ) const; // need by Music_Emu
84 private:
85 // noncopyable
86 Gme_File( const Gme_File& );
87 Gme_File& operator = ( const Gme_File& );
88
89 gme_type_t type_;
90 int track_count_;
91 int raw_track_count_;
92 const char* warning_;
93 M3u_Playlist playlist;
94 blargg_vector<byte> file_data; // only if loaded into memory using default load
95
96 blargg_err_t load_m3u_( blargg_err_t );
97 blargg_err_t post_load( blargg_err_t err );
98 public:
99 // track_info field copying
100 enum { max_field_ = 255 };
101 static void copy_field_( char* out, const char* in );
102 static void copy_field_( char* out, const char* in, int len );
103 };
104
105 Music_Emu* gme_new_( Music_Emu*, long sample_rate );
106
107 #define GME_COPY_FIELD( in, out, name ) \
108 { Gme_File::copy_field_( out->name, in.name, sizeof in.name ); }
109
110 #ifndef GME_FILE_READER
111 #ifdef HAVE_ZLIB_H
112 #define GME_FILE_READER Gzip_File_Reader
113 #else
114 #define GME_FILE_READER Std_File_Reader
115 #endif
116 #endif
117
118 inline gme_type_t Gme_File::type() const { return type_; }
119 inline int Gme_File::error_count() const { return warning_ != 0; }
120 inline int Gme_File::track_count() const { return track_count_; }
121
122 inline const char* Gme_File::warning()
123 {
124 const char* s = warning_;
125 warning_ = 0;
126 return s;
127 }
128
129 #endif