简体   繁体   English

如何在Python中同时演奏两个音符?

[英]How can I make a play two musical notes simultaneously in Python?

I plan to do a music notation which allow the user to place the note where ever they want and allowed them to play the notes they placed. 我打算做一个音乐符号,使用户可以将音符放在他们想要的任何位置,并允许他们播放放置的音符。

If the user put the note in the same time which we have to play 2 or above notes together, any solution to solve that problem? 如果用户在同时演奏两个或以上音符的同时放置音符,那么有什么解决方案可以解决该问题?

Answer is really simple and straightforward in theory - use threads . 从理论上讲,答案非常简单明了-使用线程 Your code has to be executed asynchronously. 您的代码必须异步执行。

使用multiprocess winsoundwinsound模块来执行此操作。

import threading
....
....
....
threading.Thread(name='<thread_name>', target='<your_target>').start()

you can do it 2 times for 2 different targets 您可以针对2个不同的目标进行2次

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

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