Hello!
I'm newly registered, but I have taken a look here before. More precisely, here, a thread which helped me a lot, as I were a total beginner in working with MIDI.

My problem is that, though I don't get any errors, I don't hear any sound. The funny thing is that it has worked all right, until I tried toying around with "midiOutGetDevCaps". From that point on, no matter what I've tried, no sound, no error.

My code is this:

#include<windows.h>
#pragma comment(lib, "Winmm.lib")
#include<stdio.h>
#include<conio.h>

int main(void){
	HMIDIOUT x;
	if(midiOutOpen(&x,-1,NULL,NULL,CALLBACK_NULL)==MMSYSERR_NOERROR ){
		printf("No error\n");
	}

	switch(midiOutShortMsg(x,0x9062565)){
		case MMSYSERR_NOERROR:
			printf("No error");
			break;
		case MIDIERR_BADOPENMODE:
			printf("Bad open mode");
			break;
		case MIDIERR_NOTREADY:
			printf("Busy");
			break;
		case MMSYSERR_INVALHANDLE:
			printf("Invalid handle");
			break;
	}
	_getch();
	return 1;
}

I wonder if anyone could tell me if I'm doing something wrong and I'm not able to see it. Maybe test the code on your computer... My supposition so far is that I've messed up something about the MIDI device. Maybe you know what could have caused this. Please help me...

Later Edit:
For avoiding questions like "What have you written exactly", I mention that in the moment I've noticed the problem, I have [CTRL]+[Z]-ed until the code was exactly as when it was working. Yet, no result.

Recommended Answers

All 6 Replies

Well, by playing with the code from the link I got this:

#include<windows.h>
#include<stdio.h>
#include<conio.h>

#pragma comment(lib, "Winmm.lib")

//command, note, velocity
#define MAKE_MSG(X, Y, Z) (X + (Y<<8) + (Z<<16))
#define NOTE_ON 0x90
#define NOTE_OFF 0x80

int main(void){
  HMIDIOUT x;
  if(midiOutOpen(&x,-1,NULL,NULL,CALLBACK_NULL)!=MMSYSERR_NOERROR ){
    printf("ERRORS ahoy\n");
  }

  midiOutShortMsg(x, MAKE_MSG(NOTE_ON, 62, 65));

  _getch();
  return 0;
}

I don't know if your code should play anything.

1. Your printf() statements in your switches need to have a trailing \n (or a call to fflush(stdout) ) to guarantee being able to see them.
2. You should really have a default case in your switch, to catch all other possible errors.

Thanks guys for answering so quickly.

@twomers
Yes, I know, I tried that thing too. I have posted the shortest variant. My question to you is if you hear anything after you execute that code, because I don't. And I mean the code you posted. I have copied it and executed, and nothing.

@Salem
Believe me, that's not a problem. Before, it worked without a switch at all.

I see no one answered yet.
I'll try to be more explicit. What I want to do is a little program which can "make" sounds, "play" musical notes. Could anyone give me a piece of code that generates only one sound? I mean, it works correctly on that person's computer, so I can see if it works on mine. This way I could tell if the problem is in my computer or not.

How about checking all the dumb stuff, like
- speakers not switched on
- speaker volume down low
- MIDI device not enabled
- MIDI device on mute

> Believe me, that's not a problem. Before, it worked without a switch at all.
Funny, sloppy or non-existent error checking is always a problem on the message boards.
Success yesterday doesn't count for much.
Success for other people doesn't count for much.

After some digging...
http://www.borg.com/~jglatt/tech/lowmidi.htm
Those examples seem to work, even when adapted into your code.

Thank you very much. Now it works, though I don't know why. Maybe it's because of turning the notes off, or maybe because I've reinstalled my sound card driver.
In any case, I've got myself an useful source of information through your link. Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.