简体   繁体   English

同时单击多个按钮时想要执行任务(Android Studio:java)

[英]Want to do task when multiple buttons are clicked simultaneously (Android Studio:java)

I am creating a music app(flute) which play sounds when buttons are clicked.我正在创建一个音乐应用程序(长笛),它在单击按钮时播放声音。 But i want to make a specific sound when multiple buttons are pressed simultaneously (example: playing c note when two buttons are pressed simultaneously).但是我想在同时按下多个按钮时发出特定的声音(例如:同时按下两个按钮时播放 c 音符)。

There are seven buttons which makes seven different notes or sounds(c, d, e, f, g, a, b)有七个按钮可以发出七种不同的音符或声音(c、d、e、f、g、a、b)

app should work as:应用程序应该作为:

->play note c when button 2 and 3 are pressed simultaneously. ->同时按下按钮 2 和 3 时播放音符 c。

->play note d when button 2 is pressed. ->按下按钮 2 时播放音符 d。

->play note e when button 1 is pressed. ->按下按钮 1 时播放音符 e。

->play note f when button 3, 4, 5, 6 and 7 are pressed simultaneously. ->同时按下按钮 3、4、5、6 和 7 时播放音符 f。

->play note g when button 2, 3,4,5 and 6 are pressed simultaneously. ->同时按下按钮 2、3、4、5 和 6 时播放音符 g。

->play note a when button 2, 3, 4 and 5 are pressed simultaneously. ->同时按下按钮 2、3、4 和 5 时播放音符 a。

->play note b when button 2, 3 and 4 are pressed simultaneously. ->同时按下按钮 2、3 和 4 时播放音符 b。

if anyone can help i would appreciate it.如果有人可以提供帮助,我将不胜感激。

button1down : a=1 play();
button1up : a=0 play();

button2down : b=1; play();
button2up : b=0; play();

.......
play(){
if(a&&b){
play_tone_ab();
}else
if(a){
play_tone_a();
}
}

the pseudocode will look like this.伪代码将如下所示。 But you may face some other problems while playing music.但是您在播放音乐时可能会遇到其他一些问题。 Playing many sound files may lead to some other problems.播放许多声音文件可能会导致一些其他问题。 Sometimes this is a hardware problem.有时这是硬件问题。 So, you may need to make that part stable by testing the algorithm if right functions are called.因此,如果调用了正确的函数,您可能需要通过测试算法来使该部分稳定。 Use system.log first to be sure.首先使用 system.log 来确定。 Still you may need a nice sound mixing library, which can remix the input sounds before output.您仍然可能需要一个不错的混音库,它可以在 output 之前重新混音输入的声音。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM