1
0
Fork 0

(svn r2682) Static, casts, misc.

release/0.4.5
tron 2005-07-22 18:19:06 +00:00
parent c50223526c
commit a13d515d5e
2 changed files with 63 additions and 62 deletions

22
w32dm.c
View File

@ -60,14 +60,11 @@ extern void StopSegment (void);
extern bool IsSegmentPlaying (void); extern bool IsSegmentPlaying (void);
extern void SetVolume (long); extern void SetVolume (long);
bool seeking = false; static bool seeking = false;
static const char * DMusicMidiStart(const char * const *parm) static const char * DMusicMidiStart(const char * const *parm)
{ {
if (InitDirectMusic() == true) return InitDirectMusic() ? NULL : "Unable to initialize DirectMusic";
return(0);
return("Unable to initialize DirectMusic");
} }
static void DMusicMidiStop(void) static void DMusicMidiStop(void)
@ -85,8 +82,7 @@ static void DMusicMidiPlaySong(const char *filename)
ttd_strlcpy(dir, filename, MAX_PATH); ttd_strlcpy(dir, filename, MAX_PATH);
pos = strrchr(dir, '\\') + 1; pos = strrchr(dir, '\\') + 1;
ttd_strlcpy(file, pos, MAX_PATH); ttd_strlcpy(file, pos, MAX_PATH);
//strchr(file, ' ')[0] = 0; *pos = '\0';
*pos = 0;
LoadMIDI(dir, file); LoadMIDI(dir, file);
PlaySegment(); PlaySegment();
@ -100,14 +96,12 @@ static void DMusicMidiStopSong(void)
static bool DMusicMidiIsSongPlaying(void) static bool DMusicMidiIsSongPlaying(void)
{ {
if ((IsSegmentPlaying() == 0) && (seeking == true)) // Not the nicest code, but there is a /* Not the nicest code, but there is a short delay before playing actually
return(true); // short delay before playing actually * starts. OpenTTD makes no provision for this. */
// starts. OpenTTD makes no provision for if (!IsSegmentPlaying() && seeking) return true;
if (IsSegmentPlaying() == 1) // this. if (IsSegmentPlaying()) seeking = false;
seeking = false;
return IsSegmentPlaying();
return(IsSegmentPlaying());
} }
static void DMusicMidiSetVolume(byte vol) static void DMusicMidiSetVolume(byte vol)

View File

@ -54,22 +54,24 @@
#include <dmusicc.h> #include <dmusicc.h>
#include <dmusicf.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 // 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 // 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 // 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) // 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); extern "C" bool LoadLibraryList(void **proc, const char *dll);
@ -127,11 +129,12 @@ bool InitDirectMusic (void)
// Create the performance object via CoCreateInstance // Create the performance object via CoCreateInstance
if (FAILED(_proc.CoCreateInstance( if (FAILED(_proc.CoCreateInstance(
(REFCLSID)CLSID_DirectMusicPerformance, CLSID_DirectMusicPerformance,
NULL, NULL,
CLSCTX_INPROC, CLSCTX_INPROC,
(REFIID)IID_IDirectMusicPerformance, IID_IDirectMusicPerformance,
(LPVOID *)&performance))) { (LPVOID*)&performance
))) {
MSGBOX("Failed to create the performance object"); MSGBOX("Failed to create the performance object");
return false; return false;
} }
@ -151,10 +154,13 @@ bool InitDirectMusic (void)
// now we'll create the loader object. This will be used to load the // 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 // midi file for our demo. Again, we need to use CoCreateInstance
// and pass the appropriate ID parameters // and pass the appropriate ID parameters
if (FAILED(_proc.CoCreateInstance((REFCLSID)CLSID_DirectMusicLoader, if (FAILED(_proc.CoCreateInstance(
NULL, CLSCTX_INPROC, CLSID_DirectMusicLoader,
(REFIID)IID_IDirectMusicLoader, NULL,
(LPVOID *)&loader))) { CLSCTX_INPROC,
IID_IDirectMusicLoader,
(LPVOID*)&loader
))) {
MSGBOX("Failed to create loader object"); MSGBOX("Failed to create loader object");
return false; return false;
} }
@ -173,6 +179,7 @@ void ReleaseSegment (void)
segment = NULL; segment = NULL;
} }
} }
void ShutdownDirectMusic(void) void ShutdownDirectMusic(void)
{ {
// release everything but the segment, which the performance // release everything but the segment, which the performance
@ -184,8 +191,7 @@ void ShutdownDirectMusic (void)
loader = NULL; loader = NULL;
} }
if (NULL != performance) if (NULL != performance) {
{
performance->CloseDown(); performance->CloseDown();
performance->Release(); performance->Release();
performance = NULL; performance = NULL;
@ -198,7 +204,7 @@ void ShutdownDirectMusic (void)
} }
// Load MIDI file for playing // Load MIDI file for playing
bool LoadMIDI (char *directory, char *filename) bool LoadMIDI(const char *directory, const char *filename)
{ {
DMUS_OBJECTDESC obj_desc; DMUS_OBJECTDESC obj_desc;
WCHAR w_directory[_MAX_PATH]; // utf-16 version of the directory name. WCHAR w_directory[_MAX_PATH]; // utf-16 version of the directory name.
@ -207,10 +213,11 @@ bool LoadMIDI (char *directory, char *filename)
if (NULL == performance) if (NULL == performance)
return false; return false;
MULTI_TO_WIDE(w_directory,directory); MultiToWide(w_directory, directory);
if (FAILED(loader->SetSearchDirectory((REFGUID) GUID_DirectMusicAllTypes, if (FAILED(loader->SetSearchDirectory(
w_directory, FALSE))) { GUID_DirectMusicAllTypes, w_directory, FALSE
))) {
MSGBOX("LoadMIDI: SetSearchDirectory failed"); MSGBOX("LoadMIDI: SetSearchDirectory failed");
return false; return false;
} }
@ -219,7 +226,7 @@ bool LoadMIDI (char *directory, char *filename)
ZeroMemory(&obj_desc, sizeof(obj_desc)); ZeroMemory(&obj_desc, sizeof(obj_desc));
obj_desc.dwSize = sizeof(obj_desc); obj_desc.dwSize = sizeof(obj_desc);
MULTI_TO_WIDE(w_filename,filename); MultiToWide(w_filename, filename);
obj_desc.guidClass = CLSID_DirectMusicSegment; obj_desc.guidClass = CLSID_DirectMusicSegment;
wcscpy(obj_desc.wszFileName, w_filename); wcscpy(obj_desc.wszFileName, w_filename);
@ -230,24 +237,24 @@ bool LoadMIDI (char *directory, char *filename)
ReleaseSegment(); ReleaseSegment();
// and make a new segment // and make a new segment
if (FAILED(loader->GetObject(&obj_desc, if (FAILED(loader->GetObject(
(REFIID)IID_IDirectMusicSegment, &obj_desc, IID_IDirectMusicSegment, (LPVOID*)&segment
(LPVOID *) &segment))) { ))) {
MSGBOX("LoadMIDI: Get object failed"); 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 // next we need to tell the segment what kind of data it contains. We do this
// with the IDirectMusicSegment::SetParam function. // with the IDirectMusicSegment::SetParam function.
if (FAILED(segment->SetParam((REFGUID)GUID_StandardMIDIFile, if (FAILED(segment->SetParam(
0xFFFFFFFF, 0, 0, (LPVOID)performance))) { GUID_StandardMIDIFile, 0xFFFFFFFF, 0, 0, performance
))) {
MSGBOX("LoadMIDI: SetParam (MIDI file) failed"); MSGBOX("LoadMIDI: SetParam (MIDI file) failed");
return false; return false;
} }
// finally, we need to tell the segment to 'download' the instruments // finally, we need to tell the segment to 'download' the instruments
if (FAILED(segment->SetParam((REFGUID)GUID_Download, if (FAILED(segment->SetParam(GUID_Download, 0xFFFFFFFF, 0, 0, performance))) {
0xFFFFFFFF, 0, 0, (LPVOID)performance))) {
MSGBOX("LoadMIDI: Failed to download instruments"); MSGBOX("LoadMIDI: Failed to download instruments");
return false; return false;
} }
@ -282,10 +289,10 @@ void StopSegment (void)
bool IsSegmentPlaying(void) bool IsSegmentPlaying(void)
{ {
if (NULL == performance || NULL == segment) if (NULL == performance || NULL == segment)
return FALSE; return false;
// IsPlaying return S_OK if the segment is currently playing // 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) void SetVolume(long vol)