虚拟钢琴的问题 [英] Problem with Virtual piano

查看:103
本文介绍了虚拟钢琴的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一架虚拟钢琴.这会根据组合框中列出的所选乐器产生不同的声音.我有一个编辑框,当我执行鼠标按下或向下键操作或基于高亮键的鼠标移动时会显示注释.
当我单击录制"按钮时,声音将被录制为sound.wav并在需要时播放.

现在我有一个要求,那就是当我播放录制的音乐时,我应该使相应的键高亮显示并显示相应的音符.
我按下OnLButton时可以执行此操作,但是按下Keydown时则无法执行.
因为一次可以按下多个键,所以我可以记录时间,但是不能同时播放键和播放声音.

我已尽力做到了,但我不了解如何使这项工作有效.

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.

推荐答案

将事件与操作分开.您应该以三种方式来重构代码:按键向上/向下事件,按键的视觉反馈:按下和正常状态,点亮的按键是可选的,按键的声音效果:开始/停止播放音符. br/>
不要在事件处理程序中对这两个关键操作进行硬编码,而应将它们设置为单独的方法.这样,您可以从不同的地方调用它们:例如,从键处理程序和播放的序列中.

用两个词,使用松散耦合,请参见 http://en.wikipedia.org/wiki/Loose_coupling [^ ].

现在,您只需要注意一下播放顺序中的哪些内容?或者您可以添加额外的信息来表示键?没关系,琴键和音符(音乐音调)之间是一一对应的,因此从录制的序列中找到琴键根本不是问题.

—SA
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


//我有一架虚拟钢琴.
:)

//现在我有一个要求,就是我要播放录制的音乐
//我应该使相应的键突出显示,并显示相应的注释.

如果您不打算为保存的文件构建序列分析器
您可以尝试保存注释逻辑" +键" n暂停映射"-
以您自己的格式(除了wav文件).

当然
两个转储(wav和映射)对于每个项目"应具有相同的持续时间
(可以在播放时动态地扫描"它,也可以从编辑框对其进行静态扫描"):)
// 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) :)


对于每个按键,您将获得按键信息,对于每个发行版,您将获得键入消息.
因此,只需检查按下和释放的位置即可.

您将需要发布一些代码,并指出出现问题的位置.
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.


这篇关于虚拟钢琴的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆