diff --git a/examples/audio/pitch.py b/examples/audio/pitch.py new file mode 100644 index 000000000..c977f456d --- /dev/null +++ b/examples/audio/pitch.py @@ -0,0 +1,44 @@ +# encoding: utf8 + +from kivy.app import App +from kivy.lang import Builder +from kivy.clock import Clock +from kivy.core.audio import SoundLoader +from kivy.uix.boxlayout import BoxLayout +from kivy.uix.button import Button + +from sys import version_info + + +NOTES = ( + ('Do', 1), + ('RĂ©', 9/8.), + ('Mi', 5/4.), + ('Fa', 4/3.), + ('Sol', 3/2.), + ('La', 5/3.), + ('Si', 15/8.), +) + +class Test(App): + def build(self): + self.sound = SoundLoader.load( + '/usr/lib64/python{}.{}/test/audiodata/pluck-pcm32.wav' + .format(*version_info[0:2]) + ) + print(self.sound.source) + root = BoxLayout() + for octave in range(3): + 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): + print(button.text, button.pitch) + self.sound.pitch = button.pitch + self.sound.play() + +Test().run()