Debian Codegraph @

src/Scripts/WIP/ftable_viewer.py

raw symbols SCIP
1 # This script shows the f-table generated by Csound
2 # for the selected text in a csd file
3
4 import PythonQt.QtGui as pqt
5 import PythonQt.QtCore as pqtc
6 import csnd
7
8 ftable_text = q.getSelectedText().strip()
9
10 if not ftable_text.startswith('f'):
11 pqt.QMessageBox.critical(0,"ftable viewer script",
12 'Please select ftable text')
13 raise Exception('Please select ftable text')
14
15 parts = ftable_text.split(' ')
16 if parts[0] == 'f':
17 tabnum = abs(int(parts[1]))
18 else:
19 tabnum = abs(int(parts[0][1:]))
20 # create empty orchestra and score
21 orc = ''' sr = 44100
22 ksmps = 64
23 nchnls = 2
24
25 instr 1
26 endin
27 '''
28
29 sco = '''
30 %s
31 e 3600
32 '''%ftable_text
33
34 tabnum = 1
35 # start csound engine
36 c = csnd.CppSound()
37 c.setOrchestra(orc)
38 c.setScore(sco.encode())
39 c.setCommand("csound -odac -d tmp.orc tmp.sco")
40 c.exportForPerformance()
41 c.compile()
42 c.PerformKsmps() # Must perform one control block to have tables created
43 # There must be a better way to do this!
44 len = c.TableLength(tabnum)
45 tab = []
46 for i in range(len):
47 tab.append(-c.TableGet(tabnum, i))
48 c.Stop()
49 c.Cleanup()
50
51 w = pqt.QWidget() # Create main widget
52 w.setGeometry(50,50, 400,200)
53 l = pqt.QGridLayout(w) # Layout to organize widgets
54 w.setLayout(l)
55 w.setWindowTitle("f-table")
56 w.setWindowFlags(w.windowFlags() | pqtc.Qt.WindowStaysOnTopHint);
57
58 scene = pqt.QGraphicsScene(w)
59
60 view = pqt.QGraphicsView(scene, w)
61 l.addWidget(view)
62 view.show()
63 w.show()
64
65 path = pqt.QPainterPath()
66 # must switch y axis!
67 [path.lineTo(x,-y) for (x,y) in enumerate(tab)]
68 pathItem = scene.addPath(path)
69 view.fitInView(pathItem)
70 #def update():
71
72