source: s10k/Vago/soundWizard/soundpagefinal.cpp@ 1134

Last change on this file since 1134 was 1093, checked in by s10k, 7 years ago

Vago 1.4

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