Jump to content

  • Log In with Google      Sign In   
  • Create Account

Default Port for MIDI using DirectMusic7


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 chris1962   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2000 - 05:30 AM

Hello all, I am currently incorporating MIDI files into my game using the Lamothe technique from his "Tricks Of The Windows" book. I noticed that when the MIDI file is played in my game, it sounds slightly different than when I play the MIDI file with the Windows Media Player, or Anvil (the software I used to create the MIDI file). I would prefer the game to sound the same as it does coming from Anvil (the way I created it). After some messing around, I''ve determined that it sounds different because I am adding the default port (Microsoft Software Synthesizer) within my game. if (FAILED(dm_perf->AddPort(NULL))) { return(0); //terminate application } According to the DirectX7 documentation, under win95 or win98, the default port is always the Microsoft Software Synthesizer. It would make more sense to me if the default port was selected from the one defined in the MIDI tab of the MultiMedia icon of the Control Panel. I am quite sure that is where the WindowsMediaPlayer gets its ouptut port from for MIDI files. That is what I would like my program to do. Any ideas as to how I could do this within my program? Any thoughts as to the wisdom of doing it this way? How will this affect the sound on other PC''s with different sound cards? My sound card is a SoundBlaster AWE64. Thanks for the help.

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 13 July 2000 - 10:52 AM


Hi, i have your exact same problem
The solution i found was a hack, but i havent heard of any other way to do it. I basically find the media tab setting in the registry, then do a strcmp against all dmusic enumerated caps strings until it matches, then return that guid for dmusic to initialize with


GUID *FindDefaultPort()
{
DMUS_PORTCAPS caps;
DWORD size = 256;
HKEY key;
static GUID guid;
GUID * guidptr = NULL;
char name[256];
HRESULT hr;
int count;

// get the default device out of the registry
hr = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Multimedia\\MIDIMap", 0, KEY_QUERY_VALUE , &key);
if (hr != ERROR_SUCCESS)
return NULL;
RegQueryValueEx(key, "CurrentInstrument", 0, NULL, (LPBYTE)&name, &size);
RegCloseKey(key);

count = 0;
do
{
char newname[256];

memset(&caps, 0, sizeof(DMUS_PORTCAPS));
caps.dwSize = sizeof(DMUS_PORTCAPS);

hr = pDirectMusic->lpVtbl->EnumPort(pDirectMusic, count, &caps);

WideCharToMultiByte(CP_ACP, 0, caps.wszDescription, -1, newname, 256, NULL, NULL);

if (!strcmp(newname, name))
{
memcpy(&guid, &caps.guidPort, sizeof(GUID));
guidptr = &guid;
break;
}

count++;
}
while (hr != S_FALSE);


if (!guidptr)
{
pDirectMusic->lpVtbl->GetDefaultPort(pDirectMusic, &guid);
guidptr = &guid;
}

return guidptr;
}




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS