Distribute pyjack with freewheel-related functionality
[jack_freewheel_button.git] / pyjack-0.5.2 / demos / qtransport.py
blob1e9991f94631e6817b76eb6b835b5179bb8b4815
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 import jack, os, sys
5 from PyQt4.QtGui import QApplication, QDialog
6 from PyQt4.QtCore import QTimer, SIGNAL, SLOT
7 from PyQt4.uic import loadUi
9 jack.attach("qtransport")
11 class MainW(QDialog):
12 def __init__(self, *args):
13 QDialog.__init__(self, *args)
14 loadUi(sys.path[0]+"/qtransport_gui.ui", self)
16 self.timer = QTimer()
17 self.timer.start(100)
19 self.connect(self.b_back, SIGNAL("clicked()"), self.goBack)
20 self.connect(self.b_play, SIGNAL("clicked()"), self.play)
21 self.connect(self.b_stop, SIGNAL("clicked()"), self.stop)
22 self.connect(self.b_forward, SIGNAL("clicked()"), self.goForward)
23 self.connect(self.timer, SIGNAL("timeout()"), self.refreshUi)
25 def goBack(self):
26 pos = int(jack.get_current_transport_frame()) - 100000
27 if pos < 0:
28 jack.transport_locate(0)
29 else:
30 jack.transport_locate(pos)
32 def goForward(self):
33 jack.transport_locate(jack.get_current_transport_frame()+100000)
35 def play(self):
36 if (self.b_play.isChecked()):
37 jack.transport_start()
38 else:
39 jack.transport_stop()
41 def stop(self):
42 jack.transport_stop()
43 jack.transport_locate(0)
44 self.b_play.setChecked(False)
46 def refreshUi(self):
47 state = jack.get_transport_state()
48 frame = jack.get_current_transport_frame()
49 rate = jack.get_sample_rate()
51 # Jack State
52 if (state == 0):
53 self.l_state.setText("Stopped")
54 self.b_play.setChecked(False)
55 elif (state == 1):
56 self.l_state.setText("Rolling")
57 self.b_play.setChecked(True)
58 elif (state == 3): self.l_state.setText("Starting")
59 else: self.l_state.setText("Unknown (%i)" % state)
61 # Current Time
62 time = frame / rate
63 secs = time % 60
64 mins = (time / 60) % 60
65 hrs = (time / 3600) % 60
66 secH = minH = hrsH = ""
67 if secs < 10: secH = "0"
68 if mins < 10: minH = "0"
69 if hrs < 10: hrsH = "0"
70 self.l_time.setText(hrsH+str(hrs)+":"+minH+str(mins)+":"+secH+str(secs))
72 # Current Frame
73 self.l_frame.setText(str(frame))
75 #--------------- main ------------------
76 if __name__ == '__main__':
78 app = QApplication(sys.argv)
79 gui = MainW()
80 gui.show()
81 app.exec_()
82 jack.detach()