Debian Codegraph @

src/Scripts/Koenig-Essay/Koenig-Essay.py

raw symbols SCIP
1 # By Andres Cabrera 2011
2 # License: Same as QuteCsound
3 # This script simplifies the rendering of Marco Gasperini's
4 # realization of G. M. Koenig's "Essay" for Csound using
5 # QuteCsound's python scripting facilities
6 # You need a version of QuteCsound compiled with PythonQt support
7 # to run this. Check the About box for the text "Built with PythonQt support"
8
9 import PythonQt.QtGui as pqt
10 import PythonQt.QtCore as pqtc
11 import glob, os
12
13 running = 0
14 csdFiles = []
15 sectionBox = 0
16 partBox = 0
17 parts = ['A', 'B', 'C', 'D', 'E', 'F', 'G', "Complete"]
18 srBox = 0
19 statusLabel = 0
20 renderDir = "Rendered" #Remember no slash at the end
21
22 def stop():
23 global running
24 global statusLabel
25 statusLabel.setText("Stopped.")
26 running = 0
27
28 def renderFile(csdFile):
29 global srBox
30 sr = srBox.currentText
31 ret = os.system("csound " + csdFile + " -d -r" + sr + " -k" + sr )
32 if ret != 0:
33 print("Error! File: " + csdFile + " returned: " + str(ret))
34 return ret
35
36 def renderFiles():
37 global running
38 global statusLabel
39 if not os.access(renderDir, os.F_OK):
40 os.mkdir(renderDir)
41 os.chdir(renderDir)
42 counter = 0
43 number = len(csdFiles)
44 running = 1
45 for csdFile in csdFiles:
46 counter += 1
47 statusLabel.setText("Rendering:" + csdFile)
48 print("Rendering (" + str(counter) + "/" + str(number) + "):" + csdFile)
49 renderFile(csdFile)
50 pqtc.QCoreApplication.instance().processEvents() # Needed to avoid blocking the application
51 if running == 0:
52 break
53 os.chdir("..") # Go back to original directory
54
55 def partChanged(index):
56 global sectionBox, parts
57 wavFiles = glob.glob(renderDir + "/*.wav") # Get list of csd files
58 wavFiles.sort() # Sort the list alphabetically
59 sectionBox.clear()
60 initialIndex = len(renderDir) + 1
61 initial = parts[index]
62 if parts[index] == "Complete":
63 initial = "X"
64 for file in wavFiles:
65 if file[9] == initial:
66 sectionBox.addItem(file) # Fill ComboBox with file list
67
68
69 def edit():
70 global sectionBox
71 name = sectionBox.currentText
72 if not os.access(name, os.F_OK):
73 pqt.QMessageBox.warning(0, "Koenig-Essay", "Part has not been rendered!")
74 else:
75 ret = os.system("audacity " + name + "&")
76 if ret != 0:
77 print("Error opening audacity")
78
79 q.loadDocument("Koenig-Essay.py")
80 filepath = q.getFilePath()
81
82 os.chdir(filepath) # Move to the directory of this file
83
84 csdFiles = glob.glob("csds/*.csd") # Get list of csd files
85 csdFiles.sort() # Sort the list alphabetically
86
87 w = pqt.QWidget() # Create main widget
88 w.setGeometry(50,50, 400,500)
89 l = pqt.QGridLayout(w) # Layout to organize widgets
90 w.setLayout(l)
91 w.setWindowTitle("Koenig's Essay Renderer")
92
93 partBox = pqt.QComboBox(w)
94 srBox = pqt.QComboBox(w)
95 srBox.addItem("44100")
96 srBox.addItem("48000")
97 srBox.addItem("96000")
98 srBox.addItem("192000")
99 sectionBox = pqt.QComboBox(w)
100 renderButton = pqt.QPushButton("Render All",w)
101 stopButton = pqt.QPushButton("Stop Render",w)
102 editButton = pqt.QPushButton("Open in Audacity",w)
103 text = pqt.QTextBrowser(w)
104 statusLabel = pqt.QLabel(w)
105 l.addWidget(pqt.QLabel("Sample Rate"), 0, 0)
106 l.addWidget(srBox, 0, 1)
107 l.addWidget(renderButton, 1, 0)
108 l.addWidget(stopButton, 1, 1)
109 l.addWidget(pqt.QLabel("Select Part"), 2, 0)
110 l.addWidget(partBox, 2, 1)
111 l.addWidget(sectionBox, 3, 0)
112 l.addWidget(editButton, 3, 1)
113 l.addWidget(statusLabel, 4, 0, 1, 2)
114 l.addWidget(text, 5,0,1,2)
115 stopButton.connect("clicked()", stop)
116 renderButton.connect("clicked()", renderFiles)
117 partBox.connect("currentIndexChanged(int)", partChanged)
118 editButton.connect("clicked()", edit)
119
120 f = open("readme.txt")
121 text.setText(f.read())
122
123 for part in parts:
124 partBox.addItem(part)
125
126 for file in csdFiles:
127 sectionBox.addItem(file) # Fill ComboBox with file list
128
129 w.show() # Show main widget
130
131
132