| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 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" |
| 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() |
| 51 |
if running == 0: |
| 52 |
break |
| 53 |
os.chdir("..") |
| 54 |
|
| 55 |
def partChanged(index): |
| 56 |
global sectionBox, parts |
| 57 |
wavFiles = glob.glob(renderDir + "/*.wav") |
| 58 |
wavFiles.sort() |
| 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) |
| 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) |
| 83 |
|
| 84 |
csdFiles = glob.glob("csds/*.csd") |
| 85 |
csdFiles.sort() |
| 86 |
|
| 87 |
w = pqt.QWidget() |
| 88 |
w.setGeometry(50,50, 400,500) |
| 89 |
l = pqt.QGridLayout(w) |
| 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) |
| 128 |
|
| 129 |
w.show() |
| 130 |
|
| 131 |
|
| 132 |
|