2016-06-05 14:55:17 +00:00
|
|
|
# encoding: utf8
|
|
|
|
|
|
|
|
from kivy.app import App
|
|
|
|
from kivy.core.audio import SoundLoader
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.uix.button import Button
|
|
|
|
|
|
|
|
from sys import version_info
|
|
|
|
|
|
|
|
|
|
|
|
NOTES = (
|
2016-12-13 19:15:49 +00:00
|
|
|
('Do', 1),
|
|
|
|
('Ré', 9 / 8.),
|
|
|
|
('Mi', 5 / 4.),
|
|
|
|
('Fa', 4 / 3.),
|
|
|
|
('Sol', 3 / 2.),
|
|
|
|
('La', 5 / 3.),
|
|
|
|
('Si', 15 / 8.),
|
2016-06-05 14:55:17 +00:00
|
|
|
)
|
|
|
|
|
2016-12-13 19:15:49 +00:00
|
|
|
|
2016-06-05 14:55:17 +00:00
|
|
|
class Test(App):
|
|
|
|
def build(self):
|
|
|
|
self.sound = SoundLoader.load(
|
|
|
|
'/usr/lib64/python{}.{}/test/audiodata/pluck-pcm32.wav'
|
|
|
|
.format(*version_info[0:2])
|
|
|
|
)
|
|
|
|
root = BoxLayout()
|
2016-06-05 15:12:52 +00:00
|
|
|
for octave in range(-2, 3):
|
2016-06-05 14:55:17 +00:00
|
|
|
for note, pitch in NOTES:
|
|
|
|
button = Button(text=note)
|
|
|
|
button.pitch = pitch * 2 ** octave
|
|
|
|
button.bind(on_release=self.play_note)
|
|
|
|
root.add_widget(button)
|
|
|
|
return root
|
|
|
|
|
|
|
|
def play_note(self, button):
|
|
|
|
self.sound.pitch = button.pitch
|
|
|
|
self.sound.play()
|
|
|
|
|
2016-12-17 07:50:52 +00:00
|
|
|
|
2016-06-05 14:55:17 +00:00
|
|
|
Test().run()
|