General Development

what is this midi code missing? – jari

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Hi all. I have this midi code that doesnt work, unless you have windows media player open and playing some music file(probably midi).
It makes sense that the media player should be active so that the midi sequencer is.
But what is this code missing?

#include "windows.h"

#include <iostream>

using namespace std;


MCI_OPEN_PARMS mciParams;


typedef unsigned short UTF16 ;
typedef unsigned char UTF8 ;

int main()
{

// this function is not fully tested with unicode

char buf[1024],filenameBuf[1024];
const char *filename = "allthing.mid";
MCIERROR ret;

UTF16 uniBuf[1024];

UTF16 cmdStr[1024];

memset(&mciParams,0,sizeof(mciParams));
mciParams.lpstrDeviceType = L"sequencer";

mciParams.lpstrElementName = L"allthing.mid";

sprintf_s(filenameBuf,"%s",filename);

ret = mciSendCommand(0,MCI_OPEN,MCI_WAIT | MCI_OPEN_ELEMENT,(DWORD)&mciParams);
if(ret != 0) {

/* if(mciGetErrorString(ret,uniBuf,1024))
{
convertUTF16toUTF8(uniBuf,buf,1024);
Con::errorf("Failed to open midi sequencer, %s",buf);
}*/


cout << "Playing midi '" << filename << "' failed." << endl;
return false;
}

MCI_PLAY_PARMS playPars;

// mciSendCommand(mciParams.wDeviceID,
// MCI_SEEK,MCI_WAIT | MCI_SEEK_TO_START,0);

ret = mciSendCommand(mciParams.wDeviceID,
MCI_PLAY,MCI_NOTIFY,(DWORD)(LPVOID)&playPars);

if(ret != 0) {
cout << "Unable to play the midi" << endl;
return false;
}


cout << "Playing the midi! "<< endl;

Sleep(3000);


}

It's UNICODE.

So again, its strange that the media player has to be playing so that the midi is played.

Any ideas?


------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)

[This message has been edited by jari (edited August 07, 2007).]

[This message has been edited by jari (edited August 07, 2007).]

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
first thing i though of is maybe the mixer volume for the midi synth is muted or turned all the way down?

I'm not sure how you change it though in code.

------------------
Sam Washburn

Check out my CCN SpeedGame 2 Blog

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Wow thanks for the fast reply Sam! And you said what the problem was, midi synth volume was turned down.
Heh, silly me. (I should have checked that)
What the media player actually does is that it drops down the volume bar when it's closed. I tested this, so a way set it back up in the code seems vital.

But thanks again, I will let you know when I find the solution.

------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)

[This message has been edited by jari (edited August 07, 2007).]

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Ok it required quite a lot of code but here's the clip if some one needs it:

MCIERROR ret;


Con: rintf("Setting midi volumes %d", midiOutGetNumDevs());
HMIDIOUT midis;

ret = midiOutOpen(&midis,MIDI_MAPPER, (DWORD)&midiCallback,0, CALLBACK_FUNCTION);
if(ret != 0) {
printMidiError(ret);
return false;
}

U32 devId;
ret = midiOutGetID(midis,&devId);
if(ret != 0) {
printMidiError(ret);
return false;
}

Con: rintf("getting caps %d",devId);

MIDIOUTCAPS caps;
dMemset(&caps,0,sizeof(caps));
ret = midiOutGetDevCaps(devId,&caps,sizeof(caps));

if(ret != 0) {
printMidiError(ret);
return false;
}

if(caps.dwSupport & MIDICAPS_VOLUME)
{
Con::errorf("no volume control support");
}

Con: rintf("getting volume ");

U32 volume;
ret = midiOutGetVolume((HMIDIOUT)devId,(LPDWORD)&volume);

if(ret != 0) {
printMidiError(ret);
return false;
}

Con: rintf("MIDI volume is currently: %d",volume);

ret = midiOutSetVolume((HMIDIOUT)devId,0xFFFF);

if(ret != 0) {
printMidiError(ret);
return false;
}

midiOutClose(midis);


just ignore the Con: rintf etc stuff.

Thanks to Lord for this.

------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)