|
Packit |
1470ea |
#!/usr/bin/python
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
from gi.repository import Gtk, Gst, GObject
|
|
Packit |
1470ea |
import os, sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#Comment the first line and uncomment the second before installing
|
|
Packit |
1470ea |
#or making the tarball (alternatively, use project variables)
|
|
Packit |
1470ea |
UI_FILE = "src/guitar_tuner.ui"
|
|
Packit |
1470ea |
#UI_FILE = "/usr/local/share/guitar_tuner_py/ui/guitar_tuner.ui"
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class GUI:
|
|
Packit |
1470ea |
LENGTH = 500
|
|
Packit |
1470ea |
# Frequencies of the strings
|
|
Packit |
1470ea |
frequencies = {
|
|
Packit |
1470ea |
'E': 329.63,
|
|
Packit |
1470ea |
'A': 440,
|
|
Packit |
1470ea |
'D': 587.33,
|
|
Packit |
1470ea |
'G': 783.99,
|
|
Packit |
1470ea |
'B': 987.77,
|
|
Packit |
1470ea |
'e': 1318.5
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
self.builder = Gtk.Builder()
|
|
Packit |
1470ea |
self.builder.add_from_file(UI_FILE)
|
|
Packit |
1470ea |
self.builder.connect_signals(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
window = self.builder.get_object('window')
|
|
Packit |
1470ea |
window.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def on_button_clicked (self, button):
|
|
Packit |
1470ea |
label = button.get_child()
|
|
Packit |
1470ea |
text = label.get_label()
|
|
Packit |
1470ea |
self.play_sound (self.frequencies[text])
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def destroy(window, self):
|
|
Packit |
1470ea |
Gtk.main_quit()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def pipeline_stop(self, pipeline):
|
|
Packit |
1470ea |
pipeline.set_state(Gst.State.NULL)
|
|
Packit |
1470ea |
return False
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def play_sound(self, frequency):
|
|
Packit |
1470ea |
pipeline = Gst.Pipeline(name='note')
|
|
Packit |
1470ea |
source = Gst.ElementFactory.make('audiotestsrc', 'src')
|
|
Packit |
1470ea |
sink = Gst.ElementFactory.make('autoaudiosink', 'output')
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
source.set_property('freq', frequency)
|
|
Packit |
1470ea |
pipeline.add(source)
|
|
Packit |
1470ea |
pipeline.add(sink)
|
|
Packit |
1470ea |
source.link(sink)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
pipeline.set_state(Gst.State.PLAYING)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GObject.timeout_add(self.LENGTH, self.pipeline_stop, pipeline)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def main():
|
|
Packit |
1470ea |
Gst.init_check(sys.argv)
|
|
Packit |
1470ea |
app = GUI()
|
|
Packit |
1470ea |
Gtk.main()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
if __name__ == "__main__":
|
|
Packit |
1470ea |
sys.exit(main())
|
|
Packit |
1470ea |
|