Newbie help, API
-
:confused::confused:Hi, I am building a wind synth that uses the API midi functions of a soundcard. m_Note2 is an int value according to the keys pressed and m_PBAD_2 is an int value ranging from 0-127 according to the airflow thru the synth, updated according to the timer set at 250 millisec. When I blow into the synth a note is played every 25msec but does not stop, because the m_note in stopnote() outdated. I have no idea what to add to the playnote() function. Any suggestions appreciated, my knowledge of VC++ is very limited. Cheers, Rob robert.harrington2@mail.dcu.ie void CAD_mouthDlg::PlayNote() { UpdateData(TRUE); MidiOutMessage (hMidiOut, 0x00, 0x90, m_Note2,m_PBAD_2) ; } void CAD_mouthDlg::StopNote() { if(m_Key_Press == FALSE) { MidiOutMessage (hMidiOut, 0x00, 0x90, m_Note2,0) ; } else { } } void CAD_mouthDlg::OnTimer(UINT nIDEvent) { CAD_mouthDlg::read_analog(); CAD_mouthDlg::SetPortChigh(); CAD_mouthDlg::OnButtonReadPort(); CAD_mouthDlg::PlayNote(); CAD_mouthDlg::StopNote(); CDialog::OnTimer(nIDEvent); }
-
:confused::confused:Hi, I am building a wind synth that uses the API midi functions of a soundcard. m_Note2 is an int value according to the keys pressed and m_PBAD_2 is an int value ranging from 0-127 according to the airflow thru the synth, updated according to the timer set at 250 millisec. When I blow into the synth a note is played every 25msec but does not stop, because the m_note in stopnote() outdated. I have no idea what to add to the playnote() function. Any suggestions appreciated, my knowledge of VC++ is very limited. Cheers, Rob robert.harrington2@mail.dcu.ie void CAD_mouthDlg::PlayNote() { UpdateData(TRUE); MidiOutMessage (hMidiOut, 0x00, 0x90, m_Note2,m_PBAD_2) ; } void CAD_mouthDlg::StopNote() { if(m_Key_Press == FALSE) { MidiOutMessage (hMidiOut, 0x00, 0x90, m_Note2,0) ; } else { } } void CAD_mouthDlg::OnTimer(UINT nIDEvent) { CAD_mouthDlg::read_analog(); CAD_mouthDlg::SetPortChigh(); CAD_mouthDlg::OnButtonReadPort(); CAD_mouthDlg::PlayNote(); CAD_mouthDlg::StopNote(); CDialog::OnTimer(nIDEvent); }
bob_000 wrote:_
void CAD_mouthDlg::StopNote()
{
if(m_Key_Press == FALSE)
{
MidiOutMessage (hMidiOut, 0x00, 0x90, m_Note2,0) ;
}
else
{
}
}_Well, one of your problems is that the MIDI note off message code is 0x80 (to 0x8F for different channels), not 0x90 (0x90 - 0x9F are note-on messages for channels 0-15)). As you probably know, MIDI uses a Note On message to start a note and a Note Off message to stop it. [Edit] Oops - I just checked a MIDI spec, and a Note On message with velocity zero, which is what you're doing, should also work as a Note Off. Sorry![/Edit] However, you're still going to run into problems. Calling StopNote() immediately after PlayNote() (assuming m_Key_Press == FALSE) will result in a note too short for you to hear. But if m_Key_Press is TRUE (so the stop message doesn't get sent), the next time your timer triggers another note on will be sent (maybe with the same pitch) without you having sent a stop message. You might get the same note played again, which will sound wierd, or the previous note might stop - it kinda depends on the synth you're sending the MIDI messages to. Anyway, wind instruments are normally monophonic so you'd want to stop the previous note before starting the new one. But that's more an app-logic problem, and that all depends on what you're trying to do!
"We are the knights who say Ni" (The Knights Who Say Ni)