Jump to content
  • Advertisement
Sign in to follow this  
Akks_3

help me with this single click event on a button

This topic is 4328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'am trying to generate midi sounds using low level functions(not using DirectX). The program works fine but with a hitch. The goal is to play midi notes on the click of a button. I can play the notes on a single click of a button.But on the second click the notes don't play at all. I used a button refresh attribute, even then the problem persists. Since I could explain the problem better, I didn't feel the need to paste my code. Please indicate what is going wrong, and what needs to be done. A [Edited by - Akks_3 on November 15, 2006 12:31:36 PM]

Share this post


Link to post
Share on other sites
Advertisement
How are you sending the MIDI events? Are you sending a key release message when your button is released? As far as I'm aware, sending two key down messages to the same channel will only play the first note.

Have you tried setting a breakpoint to ensure that the button's event handler is being called at all?

Also, what language/API/… are you using?

Share this post


Link to post
Share on other sites
My code is n VC++.NET, windows forms (CLR). I don't use a key press event to generate notes. I only use messages.
Here is my code:

private: System::Void singleInstru_Click(System::Object^ sender, System::EventArgs^ e)
{
HMIDIOUT hdev;
if ( midiOutOpen(&hdev, MIDI_MAPPER , NULL, NULL,CALLBACK_NULL ) == MMSYSERR_NOERROR )
{
//initializing the notes for the twenty alphabets
int noteK = 45, noteE = 46, noteD = 47, noteR = 48;
int noteS = 49, noteT = 50, noteN = 51, noteQ = 52;
int noteA = 53, noteG = 54, noteY = 55, noteC = 56, noteW = 57;
int noteL = 58, noteV = 59, noteI = 60, noteF = 61, noteM = 62;

//this->singleInstru->Refresh();
// #define MAKE_MSG(X, Y, Z) (X + (Y<<8) + (Z<<16)): for the MAKE_MSG

//play a piano by default
midiOutShortMsg(hdev,MAKE_MSG((0xC0),00,00)); //to change the instrument : piano
midiOutSetVolume(hdev, 0xffff);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteK, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteK, 65));
Sleep(1000);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteE, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteE, 65));
Sleep(1000);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteD, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteD, 65));
Sleep(1000);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteR, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteR, 65));
Sleep(1000);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteS, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteS, 65));
Sleep(1000);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteT, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteT, 65));
Sleep(1000);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteN, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteN, 65));
Sleep(1000);
midiOutShortMsg(hdev, MAKE_MSG(0x90, noteQ, 65));
Sleep(500);
midiOutShortMsg(hdev, MAKE_MSG(0x80, noteQ, 65));

}
else
{
return;
}
}

Share this post


Link to post
Share on other sites
Opening the device each time without closing it afterwards seems like it could be part of the problem. Open the device once, probably as part of the form's constructor, storing the HMIDIOUT hdev; as a member variable.
Sleep is a blocking call, so the application will lock up during those calls. If you insist on using Sleep to time delays, I'd recommend shunting the playback into a seperate thread. The BackgroundWorker control makes this very simple.

Share this post


Link to post
Share on other sites
I think benryves is on the right track. However, if these notes are just for a transient effect, I would probably simply close the device after the notes have played. I would still move this into a background worker thread however.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!