Zulko / pianoputer

Use your computer keyboard as a "piano".
http://zulko.github.io/blog/2014/03/29/soundstretching-and-pitch-shifting-in-python/
Other
324 stars 89 forks source link

请教您键盘布局图是怎么绘制的?(Ask you how to draw the keyboard layout) #26

Closed huasheng-yue closed 3 years ago

huasheng-yue commented 3 years ago

我用的键盘布局略有不同,想尝试绘制相合的键盘布局图且不影响程序的正常运行,另外,想尝试按键动作与用户界面上的键盘图互动,最好能够支持触控动作,方便在触控屏幕上运行,而且,可以尝试通过触控点的面积大小控制音量强弱,通过触摸动作控制音高等表现形式

spacether commented 3 years ago

English translation: Topic: Ask you how to draw the keyboard layout Message: The keyboard layout I use is slightly different. I want to try to draw a similar keyboard layout without affecting the normal operation of the program. In addition, I want to try to interact with the keyboard diagram on the user interface. It’s best to support touch actions to facilitate It runs on the touch screen, and you can try to control the volume of the volume through the area of ​​the touch point, and control the pitch through the touch action.

spacether commented 3 years ago

To draw a different keyboard layout you will need to do two things. In the keyboardlayout package file a PR with

  1. add your key constants for any keys that are unique to your keyboard
  2. add the new layout file in the layouts directory. Here is the azerty one
    • in it I define keys in each row. 'name' is the key name and the value must be in the constants in key.py. For each key there are 6 positions where text can be placed. tl = top-left, tc=top-center, tr=top-right, m = middle (ml/mc/mr), b = bottom (bl/bc/br)

Then when you have added that new layout, I can add it to pianoputer.

Which keyboard layout are you using? What python graphics backend do you want to use to detect the touch actions? (only tkinter and pygame are supported graphics backends in keyboardlayout).

Back to Chinese: 要绘制不同的键盘布局,您需要做两件事。在keyboardlayout程序包文件中,PR为 1.为键盘唯一的任何键添加键常数 2.在布局目录中添加新的布局文件。这是azerty one -在其中我在每一行中定义键。 “名称”是键名,值必须在key.py中的常量中。对于每个键,可以在6个位置放置文本。 tl =左上角,tc =顶部中心,tr =右上角,m =中间(ml / mc / mr),b =底部(bl / bc / br)

然后,当您添加了新布局后,我可以将其添加到pianoputer中。

您使用哪种键盘布局? 您想使用哪些python图形后端检测触摸动作? (键盘布局中仅支持tkinter和pygame图形后端)。

huasheng-yue commented 3 years ago

再次感谢Zulko的回信。

1) 我用的2个键盘,都是普通的104键布局,不过,Enter键与\键不大一样。附图给您看。

2) 请教您:如何在代码中指定触发键的名称?网上找了很多关于键盘按键的ASCII对应名称,并不完全一致,请问您用的是哪一种名称?目前主键位有CapsLock、LeftWin、RightWin、Menu四个按键无法指定。

3) 我尝试替换了您利用算法从敲碗声或任意生源演化生成的乐音,演奏感觉声音略好些。请教您在音色生成及完善方面您用的是怎样的算法?[cid:image003.png@01D70A9A.D806BAC0]

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Justin Blackmailto:notifications@github.com Sent: 2021年2月23日 7:12 To: Zulko/pianoputermailto:pianoputer@noreply.github.com Cc: huasheng-yuemailto:huashengle@outlook.com; Authormailto:author@noreply.github.com Subject: Re: [Zulko/pianoputer] 请教您键盘布局图是怎么绘制的? (#26)

To draw a different keyboard layout you will need to do two things. In the keyboardlayout package file a PR with

  1. add your key constantshttps://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/key.py for any keys that are unique to your keyboard
  2. add the new layout file in the layouts directory. Here is the azerty onehttps://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/layouts/azerty_laptop.yaml

    • in it I define keys in each row. 'name' is the key name and the value must be in the constants in key.py. For each key there are 6 positions where text can be placed. tl = top-left, tm=top-center, tr=top-right, m = middle (ml/mc/mr), b = bottom (bl/bc/br)

Then when you have added that new layout, I can add it to pianoputer.

Which keyboard layout are you using? What python graphics backend do you want to use to detect the touch actions? (only tkinter and pygame are supported graphics backends in keyboardlayout).

Back to Chinese: 要绘制不同的键盘布局,您需要做两件事。在keyboardlayout程序包文件中,PR为 1.为键盘唯一的任何键添加[键常数](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/key.pyhttps://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/key.py%EF%BC%89 2.在布局目录中添加新的布局文件。这是[azerty one](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/layouts/azerty_laptop.yamlhttps://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/layouts/azerty_laptop.yaml%EF%BC%89 -在其中我在每一行中定义键。 “名称”是键名,值必须在key.py中的常量中。对于每个键,可以在6个位置放置文本。 tl =左上角,tm =顶部中心,tr =右上角,m =中间(ml / mc / mr),b =底部(bl / bc / br)

然后,当您添加了新布局后,我可以将其添加到pianoputer中。

您使用哪种键盘布局? 您想使用哪些python图形后端检测触摸动作? (键盘布局中仅支持tkinter和pygame图形后端)。

― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Zulko/pianoputer/issues/26#issuecomment-783744893, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APTVWDB6OLT3Y65F4S73Q23TALQE3ANCNFSM4X6W3LEQ.

spacether commented 3 years ago

Hey so I am growing tired of translating from a language and back into a language. From now on can you translate your question into English and I will translate my answer back into Chinese? Also, your image is missing, can you try including it again? For me to see it the link here has to be browsable. Translated:


嘿,所以我对从一种语言再翻译回一种语言感到厌倦了。从现在开始,您可以将您的问题翻译成英文,然后我将我的答案翻译成中文吗?
另外,您的图片丢失了,您可以尝试再次添加它吗?对于我来说,这里的链接必须是可浏览的
huasheng-yue commented 3 years ago

Hi, Thank you for your reply.

I want know what about the correlation between the key numbers and the key sign in your program code just like: (I did some sort there)

QWERTY_SCANCODE_UNICODE = dict(zip([ # correspondance qwerty keyboard with its scancode(已知BUG:f和6无响应) 49,10,11,12,13,14,15,16,17,18,19,20,21,23, 24,25,26,27,28,29,30,31,32,33,38,39,40,41, 42,43,44,45,46,47,48,51,50,94,52,53,54, 55,56,57,58,59,60,61,62,63 ], [ '\','g','h','i','j','k','l','m','n','o','p','q','r','t', 'u','v','w','x','y','z','1','2','3','4','9','0','en','f', 'bc','ta','SP','-','=','[',']',';','6','K6','\'','`',',', '.','/','ca','F1','F2','F3','F4','s','rs' ]))

[cid:image003.png@01D70C49.99B5BF90] 发送自 Windows 10 版邮件https://go.microsoft.com/fwlink/?LinkId=550986应用

发件人: Justin Blackmailto:notifications@github.com 发送时间: 2021年2月25日 23:59 收件人: Zulko/pianoputermailto:pianoputer@noreply.github.com 抄送: huasheng-yuemailto:huashengle@outlook.com; Authormailto:author@noreply.github.com 主题: Re: [Zulko/pianoputer] 请教您键盘布局图是怎么绘制的? (#26)

Hey so I am growing tired of translating from a language and back into a language. From now on can you translate your question into English and I will translate my answer back into Chinese? Also, your image is missing, can you try including it again? For me to see it the link here has to be browsable. Translated:

嘿,所以我对从一种语言再翻译回一种语言感到厌倦了。从现在开始,您可以将您的问题翻译成英文,然后我将我的答案翻译成中文吗?

另外,您的图片丢失了,您可以尝试再次添加它吗?对于我来说,这里的链接必须是可浏览的

― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Zulko/pianoputer/issues/26#issuecomment-786008273, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APTVWDEWDD7FJE66IGCKRFDTAZXWPANCNFSM4X6W3LEQ.

spacether commented 3 years ago

Thanks for the translation.

So the correlation goes through pygame keys. here we input a pygame event.key and then we map from that to a keyboardlayout.key.Key here So now we have a keyboardlayout.key.Key but it might not be the actual physical key because with the 1 key I can type 1 and !. So for both of those values we need to return a constant key value. That's what this line does. And _key_to_actual_key has values assigned to it here Some keys don't have pygame key constants like here So if your keys are not working, you need to log the value of the pygame event.key, and add an entry for that key here

Translated to Chinese: 感谢您的翻译。

因此,相关性通过pygame键进行。 [此处](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/pygame/keyboardlayout.py#L213)我们输入pygame event.key,然后将其映射到keyboardlayout.key.Key [这里](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/pygame/key.py#L73) 因此,现在我们有了keyboardlayout.key.Key,但是它可能不是实际的物理键,因为使用1键,我可以键入1和!。因此,对于这两个值,我们需要返回一个恒定的键值。 这就是[此行的功能](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/pygame/keyboardlayout.py#L214)。 并且_key_to_actual_key为其分配了值[此处](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/common.py#L206) 某些键没有pygame键常量,例如[here](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/pygame/key.py#L56) 因此,如果您的键不起作用,则需要记录pygame event.key的值,并为该键添加一个条目[此处](https://github.com/spacether/keyboardlayout/blob/master/keyboardlayout/pygame/key.py#L56

spacether commented 3 years ago

Closing this issue because I answered the questions