1 |
#include "soundpagefinal.h" |
2 |
#include "ui_soundpagefinal.h" |
3 |
|
4 |
SoundPageFinal::SoundPageFinal(QString AppDir, QString soundsLocation, DropTableWidget *page2Table, Logger *myLogger, QHash<QString, QString> *commandMap, QWidget *parent) : |
5 |
QWizardPage(parent), |
6 |
ui(new Ui::soundpagefinal) |
7 |
{ |
8 |
ui->setupUi(this); |
9 |
this->soundsLocation=soundsLocation; |
10 |
this->page2Table=page2Table; |
11 |
this->myLogger=myLogger; |
12 |
this->commandMap=commandMap; |
13 |
|
14 |
this->xmlCommands = new QStringList(); |
15 |
this->oniSplitCommands = new QStringList(); |
16 |
this->myXmlProcessor = new XmlProcessor(AppDir, this->myLogger,this->xmlCommands); |
17 |
this->myConverter = new Converter(AppDir, this->myLogger,this->oniSplitCommands); |
18 |
|
19 |
ui->lbComplete->setText("<html>The wizard is now complete. The sounds have been converted. " |
20 |
"You can view all converted files clicking <a href=' '>here.</a><br />" |
21 |
"<br />Click restart to create more sounds from the wizard beggining, " |
22 |
"otherwise click finish.</html>"); // Don't use rich text in qtdesigner because it generates platform dependent code |
23 |
|
24 |
connectSlots(); |
25 |
} |
26 |
|
27 |
void SoundPageFinal::openSoundsFolder(){ |
28 |
QString outputFolder; |
29 |
|
30 |
if(field("rbOther").toBool()){ |
31 |
outputFolder=field("leOtherLocation").toString(); |
32 |
} |
33 |
else{ |
34 |
outputFolder=this->soundsLocation; |
35 |
} |
36 |
|
37 |
QDesktopServices::openUrl(QUrl("file:///"+outputFolder)); |
38 |
} |
39 |
|
40 |
void SoundPageFinal::initializePage(){ |
41 |
startProcessing(); |
42 |
} |
43 |
|
44 |
void SoundPageFinal::startProcessing(){ |
45 |
// Sample files names |
46 |
QString ambFile="OSBDsample_file.amb.xml"; |
47 |
QString grpFile="OSBDsample_file.grp.xml"; |
48 |
QString impFile="OSBDsample_file.imp.xml"; |
49 |
QString ambFileLocation=GlobalVars::VagoTemporaryDir+"/"+ambFile; |
50 |
QString grpFileLocation=GlobalVars::VagoTemporaryDir+"/"+grpFile; |
51 |
QString impFileLocation=GlobalVars::VagoTemporaryDir+"/"+impFile; |
52 |
|
53 |
// Page 2 variables |
54 |
QString outputFolder; |
55 |
|
56 |
// Page 3 variables |
57 |
QString sphereRadious, minElapsedTime, maxElapsedTime, minVolumeDistance, |
58 |
maxVolumeDistance, minOcclusion, treshold, priority; |
59 |
QStringList flags; |
60 |
bool priorityLow = false, priorityNormal = false, |
61 |
priorityHigh = false, priorityHighest = false; |
62 |
|
63 |
bool interruptOnStop=false; |
64 |
bool playOnce=false; |
65 |
bool canPan=false; |
66 |
|
67 |
// Page 4 variables |
68 |
QString volume, minVolume, maxVolume, pitch, minPitch, weight, maxPitch, |
69 |
numberChannels; |
70 |
bool preventRepeat=false; |
71 |
bool stereo22=false, mono22=false, mono44Pc=false; |
72 |
|
73 |
// Page 5 variables |
74 |
QString minVolumeDistanceImp, maxVolumeDistanceImp, minAngleImp, |
75 |
maxAngleImp, minAttenuationImp, impactVelocityImp, |
76 |
minOcclusionImp, priorityImp; |
77 |
bool priorityLowImp = false, priorityNormalImp = false, |
78 |
priorityHighImp = false, priorityHighestImp = false; |
79 |
|
80 |
// Create temp folder if it doesn't exist |
81 |
if(!QDir(GlobalVars::VagoTemporaryDir).exists()){ |
82 |
QDir().mkdir(GlobalVars::VagoTemporaryDir); |
83 |
} |
84 |
|
85 |
// Get data page 2 |
86 |
if(field("rbOther").toBool()){ |
87 |
outputFolder=field("leOtherLocation").toString(); |
88 |
} |
89 |
else{ |
90 |
outputFolder=this->soundsLocation; |
91 |
} |
92 |
|
93 |
// Get data page 3 |
94 |
|
95 |
priorityLow=field("rbPriorityLow").toBool(); |
96 |
priorityNormal=field("rbPriorityNormal").toBool(); |
97 |
priorityHigh=field("rbPriorityHigh").toBool(); |
98 |
priorityHighest=field("rbPriorityHighest").toBool(); |
99 |
interruptOnStop=field("cbInterruptOnStop").toBool(); |
100 |
playOnce=field("cbPlayOnce").toBool(); |
101 |
canPan=field("cbCanPan").toBool(); |
102 |
|
103 |
if(priorityNormal){ |
104 |
priority="Normal"; |
105 |
} |
106 |
else if(priorityLow){ |
107 |
priority="Low"; |
108 |
} |
109 |
else if(priorityHigh){ |
110 |
priority="High"; |
111 |
} |
112 |
else if(priorityHighest){ |
113 |
priority="Highest"; |
114 |
} |
115 |
|
116 |
if(interruptOnStop){ |
117 |
flags << "InterruptTracksOnStop"; |
118 |
} |
119 |
|
120 |
if(playOnce){ |
121 |
flags << "PlayOnce"; |
122 |
} |
123 |
|
124 |
if(canPan){ |
125 |
flags << "CanPan"; |
126 |
} |
127 |
|
128 |
sphereRadious=Util::normalizeDecimalSeparator(field("leSphereRadious").toString()); |
129 |
minElapsedTime=Util::normalizeDecimalSeparator(field("leMinElapsedTime").toString()); |
130 |
maxElapsedTime=Util::normalizeDecimalSeparator(field("leMaxElapsedTime").toString()); |
131 |
minVolumeDistance=Util::normalizeDecimalSeparator(field("leMinVolumeDistance").toString()); |
132 |
maxVolumeDistance=Util::normalizeDecimalSeparator(field("leMaxVolumeDistance").toString()); |
133 |
minOcclusion=Util::normalizeDecimalSeparator(field("leMinOcclusion").toString()); |
134 |
treshold=Util::normalizeDecimalSeparator(field("leTreshold").toString()); |
135 |
|
136 |
// Get data page 4 |
137 |
|
138 |
volume=Util::normalizeDecimalSeparator(field("leVolume").toString()); |
139 |
minVolume=Util::normalizeDecimalSeparator(field("leMinVolume").toString()); |
140 |
maxVolume=Util::normalizeDecimalSeparator(field("leMaxVolume").toString()); |
141 |
pitch=Util::normalizeDecimalSeparator(field("lePitch").toString()); |
142 |
minPitch=Util::normalizeDecimalSeparator(field("leMinPitch").toString()); |
143 |
maxPitch=Util::normalizeDecimalSeparator(field("leMaxPitch").toString()); |
144 |
weight=Util::normalizeDecimalSeparator(field("leWeight").toString()); |
145 |
|
146 |
preventRepeat=field("cbPreventRepeat").toBool(); |
147 |
|
148 |
stereo22=field("rbStereo22").toBool(); |
149 |
mono22=field("rbMono22").toBool(); |
150 |
mono44Pc=field("rbMono44Pc").toBool(); |
151 |
|
152 |
if(stereo22 || mono44Pc){ |
153 |
numberChannels="2"; |
154 |
} |
155 |
else if(mono22){ |
156 |
numberChannels="1"; |
157 |
} |
158 |
|
159 |
// Get data page 5 |
160 |
priorityLowImp=field("rbPriorityLowImp").toBool(); |
161 |
priorityNormalImp=field("rbPriorityNormalImp").toBool(); |
162 |
priorityHighImp=field("rbPriorityHighImp").toBool(); |
163 |
priorityHighestImp=field("rbPriorityHighestImp").toBool(); |
164 |
|
165 |
if(priorityNormalImp){ |
166 |
priorityImp="Normal"; |
167 |
} |
168 |
else if(priorityLowImp){ |
169 |
priorityImp="Low"; |
170 |
} |
171 |
else if(priorityHighImp){ |
172 |
priorityImp="High"; |
173 |
} |
174 |
else if(priorityHighestImp){ |
175 |
priorityImp="Highest"; |
176 |
} |
177 |
|
178 |
minVolumeDistanceImp=Util::normalizeDecimalSeparator(field("leMinVolumeDistanceImp").toString()); |
179 |
maxVolumeDistanceImp=Util::normalizeDecimalSeparator(field("leMaxVolumeDistanceImp").toString()); |
180 |
minAngleImp=Util::normalizeDecimalSeparator(field("leMinAngleImp").toString()); |
181 |
maxAngleImp=Util::normalizeDecimalSeparator(field("leMaxAngleImp").toString()); |
182 |
minAttenuationImp=Util::normalizeDecimalSeparator(field("leMinAttenuationImp").toString()); |
183 |
impactVelocityImp=Util::normalizeDecimalSeparator(field("leImpactVelocityImp").toString()); |
184 |
minOcclusionImp=Util::normalizeDecimalSeparator(field("leMinOcclusionImp").toString()); |
185 |
|
186 |
//######################################################### Starting xml processing |
187 |
|
188 |
// Clean tmp dir |
189 |
if(!Util::rmDir(GlobalVars::VagoTemporaryDir)){ |
190 |
UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't clean vago temp dir for complete sound wizard. Aborting.\n"+GlobalVars::VagoTemporaryDir); |
191 |
return; |
192 |
} |
193 |
|
194 |
if(!QDir(QDir::tempPath()).mkpath("VagoTemp")){ |
195 |
UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't reconstruct vago temp dir for complete sound wizard. Aborting.\n"+GlobalVars::VagoTemporaryDir); |
196 |
} |
197 |
|
198 |
// Copy sample xml files to tmp dir |
199 |
QFile::copy(":/new/sampleFiles/"+ambFile , ambFileLocation); |
200 |
QFile::copy(":/new/sampleFiles/"+grpFile , grpFileLocation); |
201 |
QFile::copy(":/new/sampleFiles/"+impFile , impFileLocation); |
202 |
QFile::setPermissions(ambFileLocation, QFile::ReadOwner | QFile::WriteOwner); //remove read only attribute that come from resources |
203 |
QFile::setPermissions(grpFileLocation, QFile::ReadOwner | QFile::WriteOwner); |
204 |
QFile::setPermissions(impFileLocation, QFile::ReadOwner | QFile::WriteOwner); |
205 |
|
206 |
(*this->xmlCommands) |
207 |
<< "--replace-all-values -e Priority -n "+Util::insertQuotes(priority)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
208 |
<< "--replace-all-values -e Flags -n "+(flags.join(" ").isEmpty() ? Util::insertQuotes("") : Util::insertQuotes(flags.join(" ")))+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
209 |
<< "--replace-all-values -e SphereRadius -n "+Util::insertQuotes(sphereRadious)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
210 |
<< "--replace-all-values -e Treshold -n "+Util::insertQuotes(treshold)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
211 |
<< "--replace-all-values -e MinOcclusion -n "+Util::insertQuotes(minOcclusion)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
212 |
<< "--replace-all-values --parent-element-name ElapsedTime -e Max -n "+Util::insertQuotes(maxElapsedTime)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
213 |
<< "--replace-all-values --parent-element-name ElapsedTime -e Min -n "+Util::insertQuotes(minElapsedTime)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
214 |
<< "--replace-all-values --parent-element-name Distance -e Max -n "+Util::insertQuotes(maxVolumeDistance)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
215 |
<< "--replace-all-values --parent-element-name Distance -e Min -n "+Util::insertQuotes(minVolumeDistance)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose" |
216 |
<< "--replace-all-values --parent-element-name SoundGroup -e Volume -n "+Util::insertQuotes(volume)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
217 |
<< "--replace-all-values --parent-element-name SoundGroup -e Pitch -n "+Util::insertQuotes(pitch)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
218 |
<< "--replace-all-values --parent-element-name SoundGroup -e NumberOfChannels -n "+Util::insertQuotes(numberChannels)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
219 |
<< "--replace-all-values --parent-element-name Volume -e Min -n "+Util::insertQuotes(minVolume)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
220 |
<< "--replace-all-values --parent-element-name Volume -e Max -n "+Util::insertQuotes(maxVolume)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
221 |
<< "--replace-all-values --parent-element-name Pitch -e Min -n "+Util::insertQuotes(minPitch)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
222 |
<< "--replace-all-values --parent-element-name Pitch -e Max -n "+Util::insertQuotes(maxPitch)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
223 |
<< "--replace-all-values -e Weight -n "+Util::insertQuotes(weight)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose" |
224 |
<< "--replace-all-values -e Priority -n "+Util::insertQuotes(priorityImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose" |
225 |
<< "--replace-all-values --parent-element-name Distance -e Min -n "+Util::insertQuotes(minVolumeDistanceImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose" |
226 |
<< "--replace-all-values --parent-element-name Distance -e Max -n "+Util::insertQuotes(maxVolumeDistanceImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose" |
227 |
<< "--replace-all-values --parent-element-name Angle -e Min -n "+Util::insertQuotes(minAngleImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose" |
228 |
<< "--replace-all-values --parent-element-name Angle -e Max -n "+Util::insertQuotes(maxAngleImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose" |
229 |
<< "--replace-all-values -e MinAttenuation -n "+Util::insertQuotes(minAttenuationImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose" |
230 |
<< "--replace-all-values -e ImpactVelocity -n "+Util::insertQuotes(impactVelocityImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose" |
231 |
<< "--replace-all-values -e MinOcclusion -n "+Util::insertQuotes(minOcclusionImp)+" -f "+Util::insertQuotes(impFileLocation)+" --no-backups --no-verbose"; |
232 |
|
233 |
if(preventRepeat){ |
234 |
(*this->xmlCommands) << "--replace-all-values --parent-element-name SoundGroup -e Flags -n PreventRepeat -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"; |
235 |
} |
236 |
|
237 |
myXmlProcessor->start(); |
238 |
myXmlProcessor->wait(); // Wait until all xml is edited |
239 |
|
240 |
QString currFileName; |
241 |
QString currGrpFileLocation; |
242 |
QString currAmbFileLocation; |
243 |
QString currImpFileLocation; |
244 |
|
245 |
for(int i=0; i<this->page2Table->rowCount(); i++){ |
246 |
|
247 |
(*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+Util::insertQuotes(outputFolder)+" "+Util::insertQuotes(this->page2Table->item(i,1)->text()); // add location of sound file to convert |
248 |
|
249 |
currFileName=this->page2Table->item(i,0)->text(); // get current file name |
250 |
currAmbFileLocation = outputFolder + "/" + QString(ambFile).replace("sample_file",currFileName); // get the new files, filenames |
251 |
currGrpFileLocation = outputFolder + "/" + QString(grpFile).replace("sample_file",currFileName); |
252 |
currImpFileLocation = outputFolder + "/" + QString(impFile).replace("sample_file",currFileName); |
253 |
|
254 |
QFile::copy(ambFileLocation, currAmbFileLocation); // make a copy of the sample files that will be the real files |
255 |
QFile::copy(grpFileLocation, currGrpFileLocation); |
256 |
QFile::copy(impFileLocation, currImpFileLocation); |
257 |
|
258 |
(*this->xmlCommands) << "--replace-all-values -e BaseTrack1 -n "+Util::insertQuotes(currFileName)+" -f "+Util::insertQuotes(currAmbFileLocation)+" --no-backups --no-verbose" // process the xml |
259 |
<< "--replace-all-values -e Sound -n "+Util::insertQuotes(currFileName)+" -f "+Util::insertQuotes(currGrpFileLocation)+" --no-backups --no-verbose" |
260 |
<< "--replace-all-values -e Group -n "+Util::insertQuotes(currFileName)+" -f "+Util::insertQuotes(currImpFileLocation)+" --no-backups --no-verbose"; |
261 |
|
262 |
myXmlProcessor->start(); |
263 |
myXmlProcessor->wait(); // Wait until all xml is edited |
264 |
|
265 |
(*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+Util::insertQuotes(outputFolder)+" "+Util::insertQuotes(currAmbFileLocation); |
266 |
(*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+Util::insertQuotes(outputFolder)+" "+Util::insertQuotes(currGrpFileLocation); |
267 |
(*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+Util::insertQuotes(outputFolder)+" "+Util::insertQuotes(currImpFileLocation); |
268 |
} |
269 |
|
270 |
this->myConverter->start(); // finally process the onisplit commands |
271 |
this->myConverter->wait(); // wait for it to complete |
272 |
} |
273 |
|
274 |
void SoundPageFinal::catchXmlAndOSplitProcessingError(QString result, int numErrors){ |
275 |
|
276 |
if(numErrors!=0){ |
277 |
QString sNumErrors=QString::number(numErrors); |
278 |
if(numErrors>1){ |
279 |
UtilVago::showErrorPopUpLogButton(result+"\n This is the last of " + sNumErrors + " errors."); |
280 |
} |
281 |
else{ |
282 |
UtilVago::showErrorPopUpLogButton(result); |
283 |
} |
284 |
} |
285 |
} |
286 |
|
287 |
void SoundPageFinal::connectSlots(){ |
288 |
//This signal is for thread that is working setup the progress bar (make it visible and set it's min-max) |
289 |
connect(this->myXmlProcessor, SIGNAL(resultConversion(QString, int)), this, SLOT(catchXmlAndOSplitProcessingError(QString, int))); |
290 |
connect(this->myConverter, SIGNAL(resultConversion(QString, int)), this, SLOT(catchXmlAndOSplitProcessingError(QString, int))); |
291 |
connect(ui->lbComplete, SIGNAL(linkActivated(const QString & )), this, SLOT(openSoundsFolder())); |
292 |
} |
293 |
|
294 |
SoundPageFinal::~SoundPageFinal() |
295 |
{ |
296 |
delete this->xmlCommands; |
297 |
delete this->oniSplitCommands; |
298 |
delete this->myXmlProcessor; |
299 |
delete this->myConverter; |
300 |
delete ui; |
301 |
} |