Changeset - r2168:e2d4a81ef7a9
[Not reviewed]
master
0 2 0
tron - 19 years ago 2005-07-22 18:19:06
tron@openttd.org
(svn r2682) Static, casts, misc.
2 files changed with 46 insertions and 45 deletions:
w32dm.c
8
14
w32dm2.cpp
38
31
0 comments (0 inline, 0 general)
w32dm.c
Show inline comments
 
@@ -57,20 +57,17 @@ extern void ShutdownDirectMusic (void);
 
extern bool LoadMIDI (char *directory, char *filename);
 
extern void PlaySegment (void);
 
extern void StopSegment (void);
 
extern bool IsSegmentPlaying (void);
 
extern void SetVolume (long);
 

	
 
bool seeking = false;
 
static bool seeking = false;
 

	
 
static const char * DMusicMidiStart(const char * const *parm)
 
{
 
	if (InitDirectMusic() == true)
 
		return(0);
 

	
 
  return("Unable to initialize DirectMusic");
 
	return InitDirectMusic() ? NULL : "Unable to initialize DirectMusic";
 
}
 

	
 
static void DMusicMidiStop(void)
 
{
 
	StopSegment();
 
}
 
@@ -82,14 +79,13 @@ static void DMusicMidiPlaySong(const cha
 
	char file[MAX_PATH];
 

	
 
	// split full path into directory and file components
 
	ttd_strlcpy(dir, filename, MAX_PATH);
 
	pos = strrchr(dir, '\\') + 1;
 
	ttd_strlcpy(file, pos, MAX_PATH);
 
	//strchr(file, ' ')[0] = 0;
 
	*pos = 0;
 
	*pos = '\0';
 

	
 
	LoadMIDI(dir, file);
 
	PlaySegment();
 
	seeking = true;
 
}
 

	
 
@@ -97,20 +93,18 @@ static void DMusicMidiStopSong(void)
 
{
 
	StopSegment();
 
}
 

	
 
static bool DMusicMidiIsSongPlaying(void)
 
{
 
	if ((IsSegmentPlaying() == 0) && (seeking == true)) // Not the nicest code, but there is a
 
		return(true);                                   // short delay before playing actually
 
                                                        // starts. OpenTTD makes no provision for
 
	if (IsSegmentPlaying() == 1)                        // this.
 
		seeking = false;
 
	/* Not the nicest code, but there is a short delay before playing actually 
 
	 * starts. OpenTTD makes no provision for this. */
 
	if (!IsSegmentPlaying() && seeking) return true;
 
	if (IsSegmentPlaying()) seeking = false;
 

	
 

	
 
	return(IsSegmentPlaying());
 
	return IsSegmentPlaying();
 
}
 

	
 
static void DMusicMidiSetVolume(byte vol)
 
{
 
	SetVolume(vol);
 
}
w32dm2.cpp
Show inline comments
 
@@ -51,28 +51,30 @@
 

	
 
#include <dmksctrl.h>
 
#include <dmusici.h>
 
#include <dmusicc.h>
 
#include <dmusicf.h>
 

	
 
#define VARIANT int
 
#define MSGBOX(output)	DEBUG(misc, 0) ("DirectMusic driver: %s\n", output); //MessageBox(NULL, output, "dxmci",MB_OK);
 

	
 
#define MSGBOX(output)	DEBUG(misc, 0) ("DirectMusic driver: %s\n", output); //MessageBox(NULL, output, "dxmci",MB_OK);
 
#define MULTI_TO_WIDE( x,y )  MultiByteToWideChar( CP_ACP,MB_PRECOMPOSED, y,-1,x,_MAX_PATH);
 
static void MultiToWide(WCHAR* to, const char* from)
 
{
 
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, from, -1, to, _MAX_PATH);
 
}
 

	
 
// the performance object controls manipulation of  the segments
 
IDirectMusicPerformance *performance = NULL;
 
static IDirectMusicPerformance *performance = NULL;
 

	
 
// the segment object is where the MIDI data is stored for playback
 
IDirectMusicSegment *segment = NULL;
 
static IDirectMusicSegment *segment = NULL;
 

	
 
// the loader bject can load many types of DMusic related files
 
IDirectMusicLoader *loader = NULL;
 
static IDirectMusicLoader *loader = NULL;
 

	
 
// whether we've initialized COM or not (when deciding whether to shut down)
 
int COMInitialized = 0;
 
static int COMInitialized = 0;
 

	
 

	
 
extern "C" bool LoadLibraryList(void **proc, const char *dll);
 

	
 
// Use lazy linking
 
struct ProcPtrs {
 
@@ -124,17 +126,18 @@ bool InitDirectMusic (void)
 
		_proc.CoInitialize(NULL);
 
		COMInitialized = 1;
 
	}
 

	
 
	// Create the performance object via CoCreateInstance
 
	if (FAILED(_proc.CoCreateInstance(
 
			(REFCLSID)CLSID_DirectMusicPerformance,
 
				CLSID_DirectMusicPerformance,
 
			NULL,
 
			CLSCTX_INPROC,
 
			(REFIID)IID_IDirectMusicPerformance,
 
			(LPVOID *)&performance))) {
 
				IID_IDirectMusicPerformance,
 
				(LPVOID*)&performance
 
			))) {
 
		MSGBOX ("Failed to create the performance object");
 
		return false;
 
	}
 

	
 
	// Initialize it
 
	if (FAILED(performance->Init(NULL, NULL, NULL))) {
 
@@ -148,16 +151,19 @@ bool InitDirectMusic (void)
 
		return false;
 
	}
 

	
 
	// now we'll create the loader object. This will be used to load the
 
	// midi file for our demo. Again, we need to use CoCreateInstance
 
	// and pass the appropriate ID parameters
 
	if (FAILED(_proc.CoCreateInstance((REFCLSID)CLSID_DirectMusicLoader,
 
			NULL, CLSCTX_INPROC,
 
			(REFIID)IID_IDirectMusicLoader,
 
			(LPVOID *)&loader))) {
 
	if (FAILED(_proc.CoCreateInstance(
 
				CLSID_DirectMusicLoader,
 
				NULL,
 
				CLSCTX_INPROC,
 
				IID_IDirectMusicLoader,
 
				(LPVOID*)&loader
 
			))) {
 
		MSGBOX("Failed to create loader object");
 
		return false;
 
	}
 

	
 
	// that's it for initialization. If we made it this far we
 
	// were successful.
 
@@ -170,87 +176,88 @@ void ReleaseSegment (void)
 
{
 
	if (NULL != segment) {
 
		segment->Release ();
 
		segment = NULL;
 
	}
 
}
 

	
 
void ShutdownDirectMusic (void)
 
{
 
	// release everything but the segment, which the performance
 
	// will release automatically (and it'll crash if it's been
 
	// released already)
 

	
 
	if (NULL != loader) {
 
		loader->Release ();
 
		loader = NULL;
 
	}
 

	
 
	if (NULL != performance)
 
	{
 
	if (NULL != performance) {
 
 		performance->CloseDown ();
 
		performance->Release ();
 
		performance = NULL;
 
	}
 

	
 
	if (COMInitialized) {
 
		_proc.CoUninitialize();
 
		COMInitialized = 0;
 
	}
 
}
 

	
 
// Load MIDI file for playing
 
bool LoadMIDI (char *directory, char *filename)
 
bool LoadMIDI(const char *directory, const char *filename)
 
{
 
	DMUS_OBJECTDESC obj_desc;
 
	WCHAR w_directory[_MAX_PATH];	// utf-16 version of the directory name.
 
	WCHAR w_filename[_MAX_PATH];	// utf-16 version of the file name
 

	
 
	if (NULL == performance)
 
		return false;
 

	
 
	MULTI_TO_WIDE(w_directory,directory);
 
	MultiToWide(w_directory, directory);
 

	
 
	if (FAILED(loader->SetSearchDirectory((REFGUID) GUID_DirectMusicAllTypes,
 
				w_directory, FALSE))) {
 
	if (FAILED(loader->SetSearchDirectory(
 
				GUID_DirectMusicAllTypes, w_directory, FALSE
 
			))) {
 
		MSGBOX("LoadMIDI: SetSearchDirectory failed");
 
		return false;
 
	}
 

	
 
	// set up the loader object info
 
	ZeroMemory (&obj_desc, sizeof (obj_desc));
 
	obj_desc.dwSize = sizeof (obj_desc);
 

	
 
	MULTI_TO_WIDE(w_filename,filename);
 
	MultiToWide(w_filename, filename);
 
	obj_desc.guidClass = CLSID_DirectMusicSegment;
 

	
 
	wcscpy (obj_desc.wszFileName,w_filename);
 
	obj_desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
 

	
 
	// release the existing segment if we have any
 
	if (NULL != segment)
 
		ReleaseSegment();
 

	
 
	// and make a new segment
 
	if (FAILED(loader->GetObject(&obj_desc,
 
			(REFIID)IID_IDirectMusicSegment,
 
			(LPVOID *) &segment))) {
 
	if (FAILED(loader->GetObject(
 
				&obj_desc, IID_IDirectMusicSegment, (LPVOID*)&segment
 
			))) {
 
		MSGBOX("LoadMIDI: Get object failed");
 
		return FALSE;
 
		return false;
 
	}
 

	
 
	// next we need to tell the segment what kind of data it contains. We do this
 
	// with the IDirectMusicSegment::SetParam function.
 
	if (FAILED(segment->SetParam((REFGUID)GUID_StandardMIDIFile,
 
			0xFFFFFFFF, 0, 0, (LPVOID)performance))) {
 
	if (FAILED(segment->SetParam(
 
				GUID_StandardMIDIFile, 0xFFFFFFFF, 0, 0, performance
 
			))) {
 
		MSGBOX("LoadMIDI: SetParam (MIDI file) failed");
 
		return false;
 
	}
 

	
 
	// finally, we need to tell the segment to 'download' the instruments
 
	if (FAILED(segment->SetParam((REFGUID)GUID_Download,
 
			0xFFFFFFFF, 0, 0, (LPVOID)performance))) {
 
	if (FAILED(segment->SetParam(GUID_Download, 0xFFFFFFFF, 0, 0, performance))) {
 
		MSGBOX("LoadMIDI: Failed to download instruments");
 
		return false;
 
	}
 

	
 
	// at this point, the MIDI file is loaded and ready to play!
 
	return true;
 
@@ -279,16 +286,16 @@ void StopSegment (void)
 
}
 

	
 
// Find out whether playing has started or stopped
 
bool IsSegmentPlaying (void)
 
{
 
	if (NULL == performance || NULL == segment)
 
		return FALSE;
 
		return false;
 

	
 
	// IsPlaying return S_OK if the segment is currently playing
 
	return performance->IsPlaying(segment, NULL) == S_OK ? TRUE : FALSE;
 
	return performance->IsPlaying(segment, NULL) == S_OK;
 
}
 

	
 
void SetVolume(long vol)
 
{
 
	long db;
 

	
0 comments (0 inline, 0 general)