diff src/console/Nsfe_Emu.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 3da1b8942b8b
children 986f098da058
line wrap: on
line diff
--- a/src/console/Nsfe_Emu.h	Wed Nov 29 14:42:11 2006 -0800
+++ b/src/console/Nsfe_Emu.h	Thu Nov 30 19:54:33 2006 -0800
@@ -1,103 +1,68 @@
-
-// Nintendo Entertainment System (NES) NSFE-format game music file emulator
+// Nintendo NES/Famicom NSFE music file emulator
 
-// Game_Music_Emu 0.3.0
-
+// Game_Music_Emu 0.5.1
 #ifndef NSFE_EMU_H
 #define NSFE_EMU_H
 
 #include "blargg_common.h"
 #include "Nsf_Emu.h"
 
-// to do: eliminate dependence on bloated std vector
-#include <vector>
-
+// Allows reading info from NSFE file without creating emulator
 class Nsfe_Info {
 public:
-	struct header_t
-	{
-		char tag [4]; // 'N', 'S', 'F', 'E'
-	};
-	BOOST_STATIC_ASSERT( sizeof (header_t) == 4 );
+	blargg_err_t load( Data_Reader&, Nsf_Emu* );
 	
-	// Load NSFE info and optionally load file into Nsf_Emu
-	blargg_err_t load_file( const char* path, Nsf_Emu* = 0 );
-	
-	// Load NSFE info and optionally load file into Nsf_Emu
-	blargg_err_t load( Data_Reader&, Nsf_Emu* = 0 );
-	
-	// Load NSFE info and optionally load file into Nsf_Emu
-	blargg_err_t load( header_t const&, Data_Reader&, Nsf_Emu* = 0 );
-	
-	// Information about current file
 	struct info_t : Nsf_Emu::header_t
 	{
-		// These (longer) fields hide those in Nsf_Emu::header_t
-		char game [256];
-		char author [256];
+		char game      [256];
+		char author    [256];
 		char copyright [256];
-		char ripper [256];
-	};
-	const info_t& info() const { return info_; }
-	
-	// All track indicies are 0-based
+		char dumper    [256];
+	} info;
 	
-	// Name of track [i], or "" if none available
-	const char* track_name( unsigned i ) const;
+	void disable_playlist( bool = true );
 	
-	// Duration of track [i] in milliseconds, negative if endless, or 0 if none available
-	long track_time( unsigned i ) const;
+	blargg_err_t track_info_( track_info_t* out, int track ) const;
 	
-	// Optional playlist consisting of track indicies
-	int playlist_size() const { return playlist.size(); }
-	int playlist_entry( int i ) const { return playlist [i]; }
+	int remap_track( int i ) const;
 	
-	// If true and playlist is present in NSFE file, remap track numbers using it
-	void enable_playlist( bool = true );
+	void unload();
 	
-public:
 	Nsfe_Info();
 	~Nsfe_Info();
-	int track_count() const { return info_.track_count; }
 private:
-	std::vector<char> track_name_data;
-	std::vector<const char*> track_names;
-	std::vector<unsigned char> playlist;
-	std::vector<long> track_times;
-	int track_count_;
-	info_t info_;
-	bool playlist_enabled;
-	
-	int remap_track( int i ) const;
-	friend class Nsfe_Emu;
+	blargg_vector<char> track_name_data;
+	blargg_vector<const char*> track_names;
+	blargg_vector<unsigned char> playlist;
+	blargg_vector<char [4]> track_times;
+	int actual_track_count_;
+	bool playlist_disabled;
 };
 
-class Nsfe_Emu : public Nsf_Emu, public Nsfe_Info {
+class Nsfe_Emu : public Nsf_Emu {
 public:
-	// See Nsf_Emu.h for further information
-	
-	Nsfe_Emu( double gain = 1.4 ) : Nsf_Emu( gain ) { }
-	
-	typedef Nsfe_Info::header_t header_t;
-	
-	// Load NSFE data
-	blargg_err_t load( Emu_Reader& r ) { return Nsfe_Info::load( r, this ); }
-	
-	// Load NSFE using already-loaded header and remaining data
-	blargg_err_t load( header_t const& h, Emu_Reader& r ) { return Nsfe_Info::load( h, r, this ); }
+	static gme_type_t static_type() { return gme_nsfe_type; }
 	
 public:
-	Nsf_Emu::track_count;
-	Nsf_Emu::load_file;
-	void start_track( int );
-	void enable_playlist( bool = true );
+	// deprecated
+	struct header_t { char tag [4]; };
+	Music_Emu::load;
+	blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader
+			{ return load_remaining_( &h, sizeof h, in ); }
+	void disable_playlist( bool = true ); // use clear_playlist()
+
+public:
+	Nsfe_Emu();
+	~Nsfe_Emu();
+protected:
+	blargg_err_t load_( Data_Reader& );
+	blargg_err_t track_info_( track_info_t*, int track ) const;
+	blargg_err_t start_track_( int );
+	void unload();
+	void clear_playlist_();
+private:
+	Nsfe_Info info;
+	bool loading;
 };
 
-inline void Nsfe_Emu::enable_playlist( bool b )
-{
-	Nsfe_Info::enable_playlist( b );
-	set_track_count( info().track_count );
-}
-
 #endif
-