Coverage Report

Created: 2026-08-13 07:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/contrib-build/game-music-emu/gme/Gme_File.h
Line
Count
Source
1
// Common interface to game music file loading and information
2
3
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
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_type_t_
16
{
17
  const char* system;         /* name of system this music file type is generally for */
18
  int track_count;            /* non-zero for formats with a fixed number of tracks */
19
  Music_Emu* (*new_emu)();    /* Create new emulator for this type (useful in C++ only) */
20
  Music_Emu* (*new_info)();   /* Create new info reader for this type */
21
22
  /* internal */
23
  const char* extension_;
24
  int flags_;
25
};
26
27
struct track_info_t
28
{
29
  long track_count;
30
31
  /* times in milliseconds; -1 if unknown */
32
  long length;
33
  long intro_length;
34
  long loop_length;
35
  long fade_length;
36
  long repeat_count;
37
38
  /* Length if available, otherwise intro_length+loop_length*2 if available,
39
   * otherwise a default of 150000 (2.5 minutes) */
40
  long play_length;
41
42
  /* empty string if not available */
43
  char system    [256];
44
  char game      [256];
45
  char song      [256];
46
  char author    [256];
47
  char composer  [256];
48
  char engineer  [256];
49
  char sequencer [256];
50
  char tagger    [256];
51
  char copyright [256];
52
  char date      [256];
53
  char comment   [256];
54
  char dumper    [256];
55
  char disc      [256];
56
  char track     [256];
57
  char ost       [256];
58
};
59
enum { gme_max_field = 255 };
60
61
struct Gme_File {
62
public:
63
// File loading
64
65
  // Each loads game music data from a file and returns an error if
66
  // file is wrong type or is seriously corrupt. They also set warning
67
  // string for minor problems.
68
69
  // Load from file on disk
70
  blargg_err_t load_file( const char* path );
71
72
  // Load from custom data source (see Data_Reader.h)
73
  blargg_err_t load( Data_Reader& );
74
75
  // Load from file already read into memory. Keeps pointer to data, so you
76
  // must not free it until you're done with the file.
77
  blargg_err_t load_mem( void const* data, long size );
78
79
  // Load from multiple files already read into memory.
80
  // Should only be used for file types with a fixed track count of 1.
81
  blargg_err_t load_tracks( void const* in, long* sizes, int count );
82
83
  // Load an m3u playlist. Must be done after loading main music file.
84
  blargg_err_t load_m3u( const char* path );
85
  blargg_err_t load_m3u( Data_Reader& in );
86
87
  // Clears any loaded m3u playlist and any internal playlist that the music
88
  // format supports (NSFE for example).
89
  void clear_playlist();
90
91
// Informational
92
93
  // Type of emulator. For example if this returns gme_nsfe_type, this object
94
  // is an NSFE emulator, and you can cast to an Nsfe_Emu* if necessary.
95
  gme_type_t type() const;
96
97
  // Most recent warning string, or NULL if none. Clears current warning after
98
  // returning.
99
  const char* warning();
100
101
  // Number of tracks or 0 if no file has been loaded
102
  int track_count() const;
103
104
  // Get information for a track (length, name, author, etc.)
105
  // See gme.h for definition of struct track_info_t.
106
  blargg_err_t track_info( track_info_t* out, int track ) const;
107
108
// User data/cleanup
109
110
  // Set/get pointer to data you want to associate with this emulator.
111
  // You can use this for whatever you want.
112
0
  void set_user_data( void* p )       { user_data_ = p; }
113
0
  void* user_data() const             { return user_data_; }
114
115
  // Register cleanup function to be called when deleting emulator, or NULL to
116
  // clear it. Passes user_data to cleanup function.
117
0
  void set_user_cleanup( gme_user_cleanup_t func ) { user_cleanup_ = func; }
118
119
public:
120
  // deprecated
121
  int error_count() const; // use warning()
122
public:
123
  Gme_File();
124
  virtual ~Gme_File();
125
  BLARGG_DISABLE_NOTHROW
126
  typedef uint8_t byte;
127
protected:
128
  // Services
129
2.46k
  void set_track_count( int n )       { track_count_ = raw_track_count_ = n; }
130
175M
  void set_warning( const char* s )   { warning_ = s; }
131
2.45k
  void set_type( gme_type_t t )       { type_ = t; }
132
  blargg_err_t load_remaining_( void const* header, long header_size, Data_Reader& remaining );
133
134
318
  const byte* track_pos( int i ) { return &file_data[tracks[i]]; }
135
318
  long track_size( int i ) { return tracks[i + 1] - tracks[i]; }
136
137
  // Overridable
138
  virtual void unload();  // called before loading file and if loading fails
139
  virtual blargg_err_t load_( Data_Reader& ); // default loads then calls load_mem_()
140
  virtual blargg_err_t load_mem_( byte const* data, long size ); // use data in memory
141
  virtual blargg_err_t track_info_( track_info_t* out, int track ) const = 0;
142
  virtual void pre_load();
143
  virtual void post_load_();
144
8.31k
  virtual void clear_playlist_() { }
145
146
public:
147
  blargg_err_t remap_track_( int* track_io ) const; // need by Music_Emu
148
private:
149
  // noncopyable
150
  Gme_File( const Gme_File& );
151
  Gme_File& operator = ( const Gme_File& );
152
153
  gme_type_t type_;
154
  int track_count_;
155
  int raw_track_count_;
156
  const char* warning_;
157
  void* user_data_;
158
  gme_user_cleanup_t user_cleanup_;
159
  M3u_Playlist playlist;
160
  char playlist_warning [64];
161
  blargg_vector<byte> file_data; // only if loaded into memory using default load
162
  blargg_vector<long> tracks;    // file start indexes of `file_data`
163
164
  blargg_err_t load_m3u_( blargg_err_t );
165
  blargg_err_t post_load( blargg_err_t err );
166
public:
167
  // track_info field copying
168
  enum { max_field_ = 255 };
169
  static void copy_field_( char* out, const char* in );
170
  static void copy_field_( char* out, const char* in, int len );
171
};
172
173
Music_Emu* gme_new_( Music_Emu*, long sample_rate );
174
175
#define GME_COPY_FIELD( in, out, name ) \
176
22.0k
  { Gme_File::copy_field_( out->name, in.name, sizeof in.name ); }
177
178
#ifndef GME_FILE_READER
179
0
  #define GME_FILE_READER Std_File_Reader
180
#elif defined (GME_FILE_READER_INCLUDE)
181
  #include GME_FILE_READER_INCLUDE
182
#endif
183
184
20.6k
inline gme_type_t Gme_File::type() const            { return type_; }
185
0
inline int Gme_File::error_count() const            { return warning_ != 0; }
186
44.8k
inline int Gme_File::track_count() const            { return track_count_; }
187
188
inline const char* Gme_File::warning()
189
15.9k
{
190
15.9k
  const char* s = warning_;
191
15.9k
  warning_ = 0;
192
15.9k
  return s;
193
15.9k
}
194
195
#endif