Fixed Ardour support
[klaudia.git] / src / tb_apps.py
blob357d06633b7cc15679a54f715e36cd99e864b09c
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.kdeui import KIcon
12 import shared, tb_main, ui_tb_apps, find_plugins
15 # Main Window
16 class AppsW(QWidget, ui_tb_apps.Ui_AppsW):
17 def __init__(self, *args):
18 QWidget.__init__(self, *args)
19 self.setupUi(self)
21 self.b_add.setEnabled(False)
22 self.b_add.setIcon(KIcon("list-add"))
23 #self.b_addc.setEnabled(False)
24 self.b_addc.setIcon(KIcon("list-add"))
25 self.b_refresh.setIcon(KIcon("view-refresh"))
27 self.listDAW.setColumnWidth(0, 32)
28 self.listDAW.setColumnWidth(1, 400)
29 self.listDAW.setColumnWidth(2, 100)
30 self.listDAW.setColumnWidth(3, 75)
31 self.listDAW.setColumnWidth(4, 75)
32 self.listVST.setColumnWidth(0, 200)
34 self.connect(self.b_refresh, SIGNAL("clicked()"), self.refreshFull)
35 self.connect(self.b_add, SIGNAL("clicked()"), self.addApplication)
36 self.connect(self.b_addc, SIGNAL("clicked()"), self.addCustom)
37 self.connect(self.tabWidget, SIGNAL("currentChanged(int)"), self.disableButtons)
38 self.connect(self.listDAW, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
39 self.connect(self.listVST, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
41 self.refreshLists()
44 def addApplication(self):
45 tab = self.tabWidget.currentIndex()
46 if (tab == 0):
47 listSel = self.listDAW
48 elif (tab == 1):
49 listSel = self.listHosts
50 elif (tab == 2):
51 listSel = self.listSynths
52 elif (tab == 3):
53 listSel = self.listEffects
54 elif (tab == 4):
55 listSel = self.listTools
56 elif (tab == 5):
57 listSel = self.listBristol
58 elif (tab == 6):
59 listSel = self.listVST
61 app = listSel.item(listSel.currentRow(), 1).text()
63 if (tab == 6): #VST
64 vst_name = str(self.listVST.item(self.listVST.currentRow(), 0).text()).replace("%20"," ")
65 vst_path = str(self.listVST.item(self.listVST.currentRow(), 1).text()).replace("%20"," ")
66 vst_file = str(shared.p_folder)+"/"+vst_name+"_"+str(randint(1, 99999))
67 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'"
68 shared.appBus.RunCustom(False, command, vst_name, 1)
69 elif (app == "Ardour"):
70 ran_check = str(randint(1, 99999))
71 sample_rate = int(shared.jackBus.GetSampleRate())
72 proj_folder = shared.p_folder+"/Ardour_"+ran_check
73 os.mkdir(proj_folder)
74 os.system("cp "+shared.Path+"/../templates/Ardour/* "+proj_folder)
75 os.system('sed -i "s/X_BPM_X-KLAUDIA-X_BPM_X/'+str(shared.p_bpm)+'/" '+proj_folder+'/Ardour.ardour')
76 os.system('sed -i "s/X_SR_X-KLAUDIA-X_SR_X/'+str(sample_rate)+'/" '+proj_folder+'/Ardour.ardour')
77 os.system("mv "+proj_folder+"/Ardour.ardour "+proj_folder+"/Ardour_"+ran_check+".ardour")
78 os.mkdir(proj_folder+"/analysis")
79 os.mkdir(proj_folder+"/dead_sounds")
80 os.mkdir(proj_folder+"/export")
81 os.mkdir(proj_folder+"/interchange")
82 os.mkdir(proj_folder+"/interchange/Ardour")
83 os.mkdir(proj_folder+"/interchange/Ardour/audiofiles")
84 os.mkdir(proj_folder+"/peaks")
85 shared.appBus.RunCustom(False, "ardour2 "+proj_folder, "Ardour", 1)
86 elif (app == "Renoise"):
87 ran_check = str(randint(1, 99999))
88 os.mkdir(shared.p_folder+"/tmp_bu")
89 os.system("cp "+shared.Path+"/../templates/Renoise.xml "+shared.p_folder+"/tmp_bu")
90 os.system('sed -i "s/X_BPM_X-KLAUDIA-X_BPM_X/'+str(shared.p_bpm)+'/" '+str(shared.p_folder)+'/tmp_bu/Renoise.xml')
91 os.system("cd "+str(shared.p_folder)+"/tmp_bu && mv Renoise.xml Song.xml && zip ../Renoise_"+ran_check+".xrns Song.xml")
92 os.system("rm -rf "+str(shared.p_folder)+"/tmp_bu")
93 shared.appBus.RunCustom(False, "renoise "+str(shared.p_folder)+"/Renoise_"+ran_check+".xrns", "Renoise", 0)
95 def addCustom(self):
96 tb_main.NewAppW().exec_()
98 def refreshFull(self):
99 find_plugins.AppsWrite()
100 self.refreshLists()
102 def refreshLists(self):
103 self.listDAW.clearContents()
104 self.listVST.clearContents()
105 for i in range(1000):
106 self.listDAW.removeRow(0)
107 self.listVST.removeRow(0)
109 plugins = find_plugins.AppsRead()
110 #print plugins
112 lastpos = 0
113 for h in range(len(plugins)):
114 if (plugins[h][5] == "DAW"):
115 name = QTableWidgetItem(plugins[h][0])
116 binary = QTableWidgetItem(plugins[h][1])
117 icon = QTableWidgetItem("")
118 icon.setIcon(KIcon(plugins[h][2]))
119 version = QTableWidgetItem(plugins[h][3])
120 level = QTableWidgetItem(plugins[h][4])
121 path = QTableWidgetItem(plugins[h][6])
122 self.listDAW.insertRow(h)
123 self.listDAW.setItem(lastpos, 0, icon)
124 self.listDAW.setItem(lastpos, 1, name)
125 self.listDAW.setItem(lastpos, 2, path)
126 self.listDAW.setItem(lastpos, 3, binary)
127 self.listDAW.setItem(lastpos, 4, version)
128 self.listDAW.setItem(lastpos, 5, level)
129 lastpos += 1
131 lastpos = 0
132 for h in range(len(plugins)):
133 if (plugins[h][5] == "VST"):
134 name = QTableWidgetItem(plugins[h][0].replace("%20", " "))
135 folder = QTableWidgetItem(plugins[h][1].replace("%20", " "))
136 self.listVST.insertRow(lastpos)
137 self.listVST.setItem(lastpos, 0, name)
138 self.listVST.setItem(lastpos, 1, folder)
139 lastpos += 1
141 self.listDAW.sortByColumn(1, Qt.AscendingOrder)
142 self.listVST.sortByColumn(0, Qt.AscendingOrder)
143 self.listVST.sortByColumn(1, Qt.AscendingOrder)
146 def updateButtons(self, a, b, c, d):
147 if (a >= 0):
148 self.b_add.setEnabled(True)
149 else:
150 self.b_add.setEnabled(False)
152 def disableButtons(self, tab):
153 self.listDAW.setCurrentCell(-1, -1)
154 self.listHosts.setCurrentCell(-1, -1)
155 self.listSynths.setCurrentCell(-1, -1)
156 self.listEffects.setCurrentCell(-1, -1)
157 self.listTools.setCurrentCell(-1, -1)
158 self.listBristol.setCurrentCell(-1, -1)
159 self.listVST.setCurrentCell(-1, -1)