More apps and fixes
[klaudia.git] / src / tb_apps.py
blobdd2dc5f16d63186323214b07179969bfcd83a373
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
5 # Imports
6 import os
7 from commands import getoutput
8 from random import randint
9 from PyQt4.QtCore import Qt, SIGNAL
10 from PyQt4.QtGui import QTableWidgetItem, QWidget
11 from PyKDE4.kdecore import i18n
12 from PyKDE4.kdeui import KIcon, KMessageBox
13 import shared, tb_main, ui_tb_apps, find_plugins
16 # Main Window
17 class AppsW(QWidget, ui_tb_apps.Ui_AppsW):
18 def __init__(self, *args):
19 QWidget.__init__(self, *args)
20 self.setupUi(self)
22 self.b_add.setEnabled(False)
23 self.b_add.setIcon(KIcon("list-add"))
24 #self.b_addc.setEnabled(False)
25 self.b_addc.setIcon(KIcon("list-add"))
26 self.b_refresh.setIcon(KIcon("view-refresh"))
28 sizes = [ 32, 350, 100, 90, 75 ]
29 for i in range(len(sizes)):
30 self.listDAWs.setColumnWidth(i, sizes[i])
31 self.listHosts.setColumnWidth(i, sizes[i])
32 self.listSynths.setColumnWidth(i, sizes[i])
33 self.listEffects.setColumnWidth(i, sizes[i])
34 self.listTools.setColumnWidth(i, sizes[i])
36 self.listVST.setColumnWidth(0, 200)
38 self.connect(self.b_refresh, SIGNAL("clicked()"), self.refreshFull)
39 self.connect(self.b_add, SIGNAL("clicked()"), self.addApplication)
40 self.connect(self.b_addc, SIGNAL("clicked()"), self.addCustom)
41 self.connect(self.tabWidget, SIGNAL("currentChanged(int)"), self.disableButtons)
42 self.connect(self.listDAWs, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
43 self.connect(self.listHosts, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
44 self.connect(self.listSynths, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
45 self.connect(self.listEffects, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
46 self.connect(self.listTools, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
47 self.connect(self.listBristol, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
48 self.connect(self.listVST, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
50 self.refreshLists()
53 def addApplication(self):
54 tab = self.tabWidget.currentIndex()
55 if (tab == 0):
56 listSel = self.listDAWs
57 elif (tab == 1):
58 listSel = self.listHosts
59 elif (tab == 2):
60 listSel = self.listSynths
61 elif (tab == 3):
62 listSel = self.listEffects
63 elif (tab == 4):
64 listSel = self.listTools
65 elif (tab == 5):
66 listSel = self.listBristol
67 elif (tab == 6):
68 listSel = self.listVST
70 app = listSel.item(listSel.currentRow(), 1).text()
72 if (tab == 0): #DAW
73 if (app == "Ardour" or app == "ArdourVST"):
74 if (app == "Ardour"):
75 binary = "ardour2"
76 elif (app == "ArdourVST"):
77 binary = "ardourvst"
78 ran_check = str(randint(1, 99999))
79 sample_rate = int(shared.jackBus.GetSampleRate())
80 proj_folder = shared.p_folder+"/Ardour_"+ran_check
81 os.mkdir(proj_folder)
82 os.system("cp "+shared.Path+"/../templates/Ardour/* "+proj_folder)
83 os.system('sed -i "s/X_BPM_X-KLAUDIA-X_BPM_X/'+str(shared.p_bpm)+'/" '+proj_folder+'/Ardour.ardour')
84 os.system('sed -i "s/X_SR_X-KLAUDIA-X_SR_X/'+str(sample_rate)+'/" '+proj_folder+'/Ardour.ardour')
85 os.system("mv "+proj_folder+"/Ardour.ardour "+proj_folder+"/Ardour_"+ran_check+".ardour")
86 os.mkdir(proj_folder+"/analysis")
87 os.mkdir(proj_folder+"/dead_sounds")
88 os.mkdir(proj_folder+"/export")
89 os.mkdir(proj_folder+"/interchange")
90 os.mkdir(proj_folder+"/interchange/Ardour")
91 os.mkdir(proj_folder+"/interchange/Ardour/audiofiles")
92 os.mkdir(proj_folder+"/peaks")
93 shared.appBus.RunCustom(False, binary+" "+proj_folder, str(app), 1)
94 elif (app == "Hydrogen"):
95 self.NIY()
96 elif (app == "Qtractor" or app == "QtractorVST" or app == "QtractorVST (32bit)"):
97 if (app == "Qtractor"):
98 binary = "tractor"
99 elif (app == "QtractorVST"):
100 binary = "qtractorvst"
101 elif (app == "QtractorVST (32bit)"):
102 binary = "qtractorvst-32bit"
103 ran_check = str(randint(1, 99999))
104 sample_rate = int(shared.jackBus.GetSampleRate())
105 os.system("cp "+shared.Path+"/../templates/Qtractor.qtr "+shared.p_folder+"/Qtractor_"+ran_check+".qtr")
106 os.system('sed -i "s/X_BPM_X-KLAUDIA-X_BPM_X/'+str(shared.p_bpm)+'/" '+shared.p_folder+'/Qtractor_'+ran_check+'.qtr')
107 os.system('sed -i "s/X_SR_X-KLAUDIA-X_SR_X/'+str(sample_rate)+'/" '+shared.p_folder+'/Qtractor_'+ran_check+'.qtr')
108 os.system('sed -i "s/X_FOLDER_X-KLAUDIA-X_FOLDER_X/'+str(shared.p_folder).replace("/","\/")+'/" '+shared.p_folder+'/Qtractor_'+ran_check+'.qtr')
109 shared.appBus.RunCustom(False, binary+" "+shared.p_folder+"/Qtractor_"+ran_check+".qtr", str(app), 1)
110 elif (app == "Renoise"):
111 ran_check = str(randint(1, 99999))
112 os.mkdir(shared.p_folder+"/tmp_bu")
113 os.system("cp "+shared.Path+"/../templates/Renoise.xml "+shared.p_folder+"/tmp_bu")
114 os.system('sed -i "s/X_BPM_X-KLAUDIA-X_BPM_X/'+str(shared.p_bpm)+'/" '+str(shared.p_folder)+'/tmp_bu/Renoise.xml')
115 os.system("cd "+str(shared.p_folder)+"/tmp_bu && mv Renoise.xml Song.xml && zip ../Renoise_"+ran_check+".xrns Song.xml")
116 os.system("rm -rf "+str(shared.p_folder)+"/tmp_bu")
117 shared.appBus.RunCustom(False, "renoise "+str(shared.p_folder)+"/Renoise_"+ran_check+".xrns", str(app), 0)
118 else:
119 self.NIY()
120 elif (tab == 1): #Host
121 if (app == "Calf Jack Host"):
122 ran_check = str(randint(1, 99999))
123 os.system("cp "+shared.Path+"/../templates/CalfJackHost "+shared.p_folder+"/CalfJackHost_"+ran_check)
124 shared.appBus.RunCustom(False, "calfjackhost --load "+shared.p_folder+"/CalfJackHost_"+ran_check, str(app), 1)
125 elif (app == "Ingen"):
126 self.NIY()
127 elif (app == "Ingen (SVN)"):
128 self.NIY()
129 elif (app == "Jack Rack"):
130 self.NIY()
131 elif (app == "LV2 Rack"):
132 self.NIY()
133 elif (app == "ZynJackU"):
134 self.NIY()
135 else:
136 shared.appBus.RunCustom(False, str(self.listHosts.item(self.listHosts.currentRow(), 3).text()), str(app), 0)
137 elif (tab == 2): #Synth
138 if (app == "Phasex"):
139 self.NIY()
140 elif (app == "QSampler"):
141 self.NIY()
142 elif (app == "Yoshimi"):
143 self.NIY()
144 elif (app == "ZynAddSubFx"):
145 self.NIY()
146 else:
147 shared.appBus.RunCustom(False, str(self.listSynths.item(self.listSynths.currentRow(), 3).text()), str(app), 0)
148 elif (tab == 3): #Effect
149 if (app == "Jamin"):
150 self.NIY()
151 elif (app == "Jack Mixer"):
152 ran_check = str(randint(1, 99999))
153 proj_file = "jack-mixer_"+ran_check+".xml"
154 os.system("cp "+shared.Path+"/../templates/jack-mixer.xml "+shared.p_folder+"/"+proj_file)
155 shared.appBus.RunCustom(False, "jack_mixer -c "+shared.p_folder+"/"+proj_file, str(app), 1)
156 else:
157 shared.appBus.RunCustom(False, str(self.listEffects.item(self.listEffects.currentRow(), 3).text()), str(app), 0)
158 elif (tab == 4): #Tool
159 #if (app == "Example"):
160 #self.NIY()
161 #else:
162 shared.appBus.RunCustom(False, str(self.listTools.item(self.listTools.currentRow(), 3).text()), str(app), 0)
163 elif (tab == 5): #Bristol
164 ran_check = str(randint(1, 1024))
165 command = "startBristol -audio jack -midi jack"
166 folder = shared.p_folder+"/Bristol"
167 if (not os.path.exists(folder)):
168 os.mkdir(folder)
169 shared.appBus.RunCustom(False, command+" -load "+ran_check+" -ladi "+ran_check+" -cache "+folder+" -"+str(self.listBristol.item(self.listBristol.currentRow(), 0).text()), str(app), 1)
170 elif (tab == 6): #VST
171 vst_name = str(self.listVST.item(self.listVST.currentRow(), 0).text()).replace("%20"," ")
172 vst_path = str(self.listVST.item(self.listVST.currentRow(), 1).text()).replace("%20"," ")
173 vst_file = str(shared.p_folder)+"/"+vst_name+"_"+str(randint(1, 99999))
174 command = "env WINEPREFIX="+shared.WinePrefix+" WINE_RT="+shared.Wine_RT+" WINESVR_RT="+shared.WineSVR_RT+" "+shared.Path+"/../bins/fst.exe '"+vst_file+"' '"+vst_path+vst_name+".dll'"
175 shared.appBus.RunCustom(False, command, vst_name, 1)
177 def NIY(self):
178 KMessageBox.sorry(self, i18n("NOT IMPLEMENTED YET"), i18n("Sorry"))
180 def addCustom(self):
181 tb_main.NewAppW().exec_()
183 def refreshFull(self):
184 find_plugins.AppsWrite()
185 self.refreshLists()
187 def refreshLists(self):
188 self.listDAWs.clearContents()
189 self.listVST.clearContents()
190 for i in range(1000):
191 self.listDAWs.removeRow(0)
192 self.listHosts.removeRow(0)
193 self.listSynths.removeRow(0)
194 self.listEffects.removeRow(0)
195 self.listTools.removeRow(0)
196 self.listVST.removeRow(0)
198 plugins = find_plugins.AppsRead()
199 #print plugins
201 lastpos = 0
202 for h in range(len(plugins)):
203 if (plugins[h][5] == "DAW"):
204 name = QTableWidgetItem(plugins[h][0].replace("%20"," "))
205 binary = QTableWidgetItem(plugins[h][1].replace("%20"," "))
206 icon = QTableWidgetItem("")
207 icon.setIcon(KIcon(plugins[h][2]))
208 version = QTableWidgetItem(plugins[h][3])
209 level = QTableWidgetItem(plugins[h][4])
210 path = QTableWidgetItem(plugins[h][6])
211 self.listDAWs.insertRow(lastpos)
212 self.listDAWs.setItem(lastpos, 0, icon)
213 self.listDAWs.setItem(lastpos, 1, name)
214 self.listDAWs.setItem(lastpos, 2, path)
215 self.listDAWs.setItem(lastpos, 3, binary)
216 self.listDAWs.setItem(lastpos, 4, version)
217 self.listDAWs.setItem(lastpos, 5, level)
218 lastpos += 1
220 lastpos = 0
221 for h in range(len(plugins)):
222 if (plugins[h][5] == "Host"):
223 name = QTableWidgetItem(plugins[h][0].replace("%20"," "))
224 binary = QTableWidgetItem(plugins[h][1].replace("%20"," "))
225 icon = QTableWidgetItem("")
226 icon.setIcon(KIcon(plugins[h][2]))
227 version = QTableWidgetItem(plugins[h][3])
228 level = QTableWidgetItem(plugins[h][4])
229 path = QTableWidgetItem(plugins[h][6])
230 self.listHosts.insertRow(lastpos)
231 self.listHosts.setItem(lastpos, 0, icon)
232 self.listHosts.setItem(lastpos, 1, name)
233 self.listHosts.setItem(lastpos, 2, path)
234 self.listHosts.setItem(lastpos, 3, binary)
235 self.listHosts.setItem(lastpos, 4, version)
236 self.listHosts.setItem(lastpos, 5, level)
237 lastpos += 1
239 lastpos = 0
240 for h in range(len(plugins)):
241 if (plugins[h][5] == "Synth"):
242 name = QTableWidgetItem(plugins[h][0].replace("%20"," "))
243 binary = QTableWidgetItem(plugins[h][1].replace("%20"," "))
244 icon = QTableWidgetItem("")
245 icon.setIcon(KIcon(plugins[h][2]))
246 version = QTableWidgetItem(plugins[h][3])
247 level = QTableWidgetItem(plugins[h][4])
248 path = QTableWidgetItem(plugins[h][6])
249 self.listSynths.insertRow(lastpos)
250 self.listSynths.setItem(lastpos, 0, icon)
251 self.listSynths.setItem(lastpos, 1, name)
252 self.listSynths.setItem(lastpos, 2, path)
253 self.listSynths.setItem(lastpos, 3, binary)
254 self.listSynths.setItem(lastpos, 4, version)
255 self.listSynths.setItem(lastpos, 5, level)
256 lastpos += 1
258 lastpos = 0
259 for h in range(len(plugins)):
260 if (plugins[h][5] == "Effect"):
261 name = QTableWidgetItem(plugins[h][0].replace("%20"," "))
262 binary = QTableWidgetItem(plugins[h][1].replace("%20"," "))
263 icon = QTableWidgetItem("")
264 icon.setIcon(KIcon(plugins[h][2]))
265 version = QTableWidgetItem(plugins[h][3])
266 level = QTableWidgetItem(plugins[h][4])
267 path = QTableWidgetItem(plugins[h][6])
268 self.listEffects.insertRow(lastpos)
269 self.listEffects.setItem(lastpos, 0, icon)
270 self.listEffects.setItem(lastpos, 1, name)
271 self.listEffects.setItem(lastpos, 2, path)
272 self.listEffects.setItem(lastpos, 3, binary)
273 self.listEffects.setItem(lastpos, 4, version)
274 self.listEffects.setItem(lastpos, 5, level)
275 lastpos += 1
277 lastpos = 0
278 for h in range(len(plugins)):
279 if (plugins[h][5] == "Tool"):
280 name = QTableWidgetItem(plugins[h][0].replace("%20"," "))
281 binary = QTableWidgetItem(plugins[h][1].replace("%20"," "))
282 icon = QTableWidgetItem("")
283 icon.setIcon(KIcon(plugins[h][2]))
284 version = QTableWidgetItem(plugins[h][3])
285 level = QTableWidgetItem(plugins[h][4])
286 path = QTableWidgetItem(plugins[h][6])
287 self.listTools.insertRow(lastpos)
288 self.listTools.setItem(lastpos, 0, icon)
289 self.listTools.setItem(lastpos, 1, name)
290 self.listTools.setItem(lastpos, 2, path)
291 self.listTools.setItem(lastpos, 3, binary)
292 self.listTools.setItem(lastpos, 4, version)
293 self.listTools.setItem(lastpos, 5, level)
294 lastpos += 1
296 lastpos = 0
297 for h in range(len(plugins)):
298 if (plugins[h][5] == "Bristol"):
299 short = QTableWidgetItem(plugins[h][2].replace("%20", " "))
300 name = QTableWidgetItem(plugins[h][0].replace("%20", " "))
301 self.listBristol.insertRow(lastpos)
302 self.listBristol.setItem(lastpos, 0, short)
303 self.listBristol.setItem(lastpos, 1, name)
304 lastpos += 1
306 lastpos = 0
307 for h in range(len(plugins)):
308 if (plugins[h][5] == "VST"):
309 name = QTableWidgetItem(plugins[h][0].replace("%20", " "))
310 folder = QTableWidgetItem(plugins[h][1].replace("%20", " "))
311 self.listVST.insertRow(lastpos)
312 self.listVST.setItem(lastpos, 0, name)
313 self.listVST.setItem(lastpos, 1, folder)
314 lastpos += 1
316 self.listDAWs.sortByColumn(3, Qt.AscendingOrder)
317 self.listHosts.sortByColumn(3, Qt.AscendingOrder)
318 self.listSynths.sortByColumn(3, Qt.AscendingOrder)
319 self.listEffects.sortByColumn(3, Qt.AscendingOrder)
320 self.listTools.sortByColumn(3, Qt.AscendingOrder)
321 self.listBristol.sortByColumn(1, Qt.AscendingOrder)
322 self.listVST.sortByColumn(0, Qt.AscendingOrder)
323 self.listVST.sortByColumn(1, Qt.AscendingOrder)
326 def updateButtons(self, a, b, c, d):
327 if (a >= 0):
328 self.b_add.setEnabled(True)
329 else:
330 self.b_add.setEnabled(False)
332 def disableButtons(self, tab):
333 self.listDAWs.setCurrentCell(-1, -1)
334 self.listHosts.setCurrentCell(-1, -1)
335 self.listSynths.setCurrentCell(-1, -1)
336 self.listEffects.setCurrentCell(-1, -1)
337 self.listTools.setCurrentCell(-1, -1)
338 self.listBristol.setCurrentCell(-1, -1)
339 self.listVST.setCurrentCell(-1, -1)