Click here to Skip to main content
15,881,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a virtual piano . This gives different sound based on the selected Instrument which is listed in a combobox.I have a edit box which displays Notes when i perform mousedown or keydown or mouse move based on the key high lighted.
When i click on Record button the sound what ever comes is recorded as sound.wav and played when required.

Now i have a requirement that is when i play the recorded one i should make the corresponding keys to highlight and the corresponding notes to display.
I am able to perform this when i do OnLButton down but not able to do when Keydown.
Because at a time more than one key can be pressed I am able to record the time but not able to play keys along with the playing sound.

I have tried my best to do but i am not understanding how to make this work.
Posted
Updated 13-Feb-12 19:28pm
v2

Separate events from actions. You should refactor you code the way you have three separate things: key up/down event, visual feedback of a key: pushed and normal state, which lighted key being optional, sound effect of the key: start/stop playing a note.

Don't hard code the two key action in the event handler, make them separate method. This way, you can call them from different places: for example, from the key handler and from the played sequence.

In two words, use loose coupling, see http://en.wikipedia.org/wiki/Loose_coupling[^].

Now, what do you stream in the play sequence, just notes? Or you can add extra information which would denote keys? No matter, there is one-to-one correspondence between keys and notes (musical tones), so finding a key from a recorded sequence is not a problem at all.

—SA
 
Share this answer
 
Comments
chaiein 15-Feb-12 7:05am    
thats a good example:) but i need example in code for better understanding.
chaiein 15-Feb-12 7:06am    
any links that have implemented this method in c++.
Sergey Alexandrovich Kryukov 15-Feb-12 11:08am    
I don't think I ever saw a C++ code, not with lighted keys, but this is not too difficult to implement, espesially of you already have part of functionality. Maybe you can find some -- such applications are relatively popular.
--SA
// I have a virtual piano .
:)

// Now i have a requirement that is when i play the recorded one
// i should make the corresponding keys to highlight and the corresponding notes to display.

If you do not plane on building of an sequence analyzer for a saved file
you could try to save the "notes logic"+"keys'n'pauses-mapping" -
in your own format, additionally to the wav-file.

Of course
the both dumps (wav and mapping) should have the same duration for each "item"
(it could be "scanned" dynamically at the play-time or statically from the edit box) :)
 
Share this answer
 
Comments
chaiein 15-Feb-12 0:09am    
i did not understand.
chaiein 1-Mar-12 23:18pm    
notes logic what is it please explain. for example?
Eugen Podsypalnikov 2-Mar-12 1:57am    
For example:
(ACE)99, (P)1, (DF)99, (P)1, (ACE)1000, ...
could meen:
ACE-chord plays for 99 milliseconds, then
Pause for 1 millisecond, then
DF-chord for 99 milliseconds, then
Pause for 1 millisecond, then
ACE-chord for 1 second, then ...
For each key press you will get the keydown message and for each release you will get the keyup message.
So its a matter of checking which is pressed and which is released.

You will need to post some code and indicate where the problem occurs.
 
Share this answer
 
Comments
chaiein 14-Feb-12 2:18am    
if(record==true)
{
recordNo++;
m_KeysRecord.push_back(m_CurrKey);
m_KeysChar.push_back(m_LowNote+m_CurrKey);
GetSystemTime(&m_KeysStartTime);
}

The above code is stores the key which is high lighted.
The below function is called after the recording complete and playing the recorded data.
void CPianoCtrl::Display_RecordNote()
{
CRect InvalidRect;
for(int recording=0;recording<=recordNo;recording++)
{
XSleep(Elapsed[recording]);

m_Keys[m_KeysRecord[recording]]->NoteOn(m_NoteOnColor, InvalidRect);

InvalidateRect(&InvalidRect);

findchords(m_KeysChar[recording]);
//InvalidateRect(&InvalidRect);


}
}
when i use record of keydown and which ever keydown when i play it plays one by one.i want to play the way i pressed the key that is when one keydown and keyup is pressed other key may be still keydown that is how may be the user have pressed the key while recording.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900