ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/soundWizard/soundpagefinal.cpp
Revision: 1047
Committed: Fri Sep 16 22:51:26 2016 UTC (9 years ago) by s10k
Content type: text/x-c++src
Original Path: Vago/trunk/Vago/soundWizard/soundpagefinal.cpp
File size: 12168 byte(s)
Log Message:
Added Vago v1.0

File Contents

# Content
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 ambFileLocation=GlobalVars::VagoTemporaryDir+"/"+ambFile;
49 QString grpFileLocation=GlobalVars::VagoTemporaryDir+"/"+grpFile;
50
51 // Page 2 variables
52 QString outputFolder;
53
54 // Page 3 variables
55 QString sphereRadious, minElapsedTime, maxElapsedTime, minVolumeDistance,
56 maxVolumeDistance, minOcclusion, treshold, priority;
57 QStringList flags;
58 bool priorityLow = false, priorityNormal = false,
59 priorityHigh = false, priorityHighest = false;
60
61 bool interruptOnStop=false;
62 bool playOnce=false;
63 bool canPan=false;
64
65 // Page 4 variables
66 QString volume, minVolume, maxVolume, pitch, minPitch, weight, maxPitch,
67 numberChannels;
68 bool preventRepeat=false;
69 bool stereo22=false, mono22=false, mono44Pc=false;
70
71 // Get data page 2
72 if(field("rbOther").toBool()){
73 outputFolder=field("leOtherLocation").toString();
74 }
75 else{
76 outputFolder=this->soundsLocation;
77 }
78
79 outputFolder = Util::insertQuotes(outputFolder); // for onisplit work correctly
80
81 // Get data page 3
82
83 priorityLow=field("rbPriorityLow").toBool();
84 priorityNormal=field("rbPriorityNormal").toBool();
85 priorityHigh=field("rbPriorityHigh").toBool();
86 priorityHighest=field("rbPriorityHighest").toBool();
87
88 if(priorityNormal){
89 priority="Normal";
90 }
91 else if(priorityLow){
92 priority="Low";
93 }
94 else if(priorityHigh){
95 priority="High";
96 }
97 else if(priorityHighest){
98 priority="Highest";
99 }
100
101 if(interruptOnStop){
102 flags << "InterruptTracksOnStop";
103 }
104
105 if(playOnce){
106 flags << "PlayOnce";
107 }
108
109 if(canPan){
110 flags << "CanPan";
111 }
112
113 interruptOnStop=field("cbInterruptOnStop").toBool();
114 playOnce=field("cbPlayOnce").toBool();
115 canPan=field("cbCanPan").toBool();
116
117 sphereRadious=Util::normalizeDecimalSeparator(field("leSphereRadious").toString());
118 minElapsedTime=Util::normalizeDecimalSeparator(field("leMinElapsedTime").toString());
119 maxElapsedTime=Util::normalizeDecimalSeparator(field("leMaxElapsedTime").toString());
120 minVolumeDistance=Util::normalizeDecimalSeparator(field("leMinVolumeDistance").toString());
121 maxVolumeDistance=Util::normalizeDecimalSeparator(field("leMaxVolumeDistance").toString());
122 minOcclusion=Util::normalizeDecimalSeparator(field("leMinOcclusion").toString());
123 treshold=Util::normalizeDecimalSeparator(field("leTreshold").toString());
124
125 // Get data page 4
126
127 volume=Util::normalizeDecimalSeparator(field("leVolume").toString());
128 minVolume=Util::normalizeDecimalSeparator(field("leMinVolume").toString());
129 maxVolume=Util::normalizeDecimalSeparator(field("leMaxVolume").toString());
130 pitch=Util::normalizeDecimalSeparator(field("lePitch").toString());
131 minPitch=Util::normalizeDecimalSeparator(field("leMinPitch").toString());
132 maxPitch=Util::normalizeDecimalSeparator(field("leMaxPitch").toString());
133 weight=Util::normalizeDecimalSeparator(field("leWeight").toString());
134
135 preventRepeat=field("cbPreventRepeat").toBool();
136
137 stereo22=field("rbStereo22").toBool();
138 mono22=field("rbMono22").toBool();
139 mono44Pc=field("rbMono44Pc").toBool();
140
141 if(stereo22 || mono44Pc){
142 numberChannels="2";
143 }
144 else if(mono22){
145 numberChannels="1";
146 }
147 //######################################################### Starting xml processing
148
149 // Clean tmp dir
150 if(!Util::rmDir(GlobalVars::VagoTemporaryDir)){
151 UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't clean vago temp dir for complete sound wizard. Aborting.\n"+GlobalVars::VagoTemporaryDir);
152 return;
153 }
154
155 if(!QDir(QDir::tempPath()).mkpath("VagoTemp")){
156 UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't reconstruct vago temp dir for complete sound wizard. Aborting.\n"+GlobalVars::VagoTemporaryDir);
157 }
158
159 // Copy sample xml files to tmp dir
160 QFile::copy(":/new/sampleFiles/"+ambFile , ambFileLocation);
161 QFile::copy(":/new/sampleFiles/"+grpFile , grpFileLocation);
162 QFile::setPermissions(ambFileLocation, QFile::ReadOwner | QFile::WriteOwner); //remove read only attribute that come from resources
163 QFile::setPermissions(grpFileLocation, QFile::ReadOwner | QFile::WriteOwner);
164
165 (*this->xmlCommands)
166 << "--replace-all-values -e Priority -n "+Util::insertQuotes(priority)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
167 << "--replace-all-values -e Flags -n "+(flags.join(" ").isEmpty() ? "\" \"" : Util::insertQuotes(flags.join(" ")))+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
168 << "--replace-all-values -e SphereRadius -n "+Util::insertQuotes(sphereRadious)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
169 << "--replace-all-values -e Treshold -n "+Util::insertQuotes(treshold)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
170 << "--replace-all-values -e MinOcclusion -n "+Util::insertQuotes(minOcclusion)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
171 << "--replace-all-values --parent-element-name ElapsedTime -e Min -n "+Util::insertQuotes(minElapsedTime)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
172 << "--replace-all-values --parent-element-name Distance -e Max -n "+Util::insertQuotes(maxVolumeDistance)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
173 << "--replace-all-values --parent-element-name Distance -e Min -n "+Util::insertQuotes(minVolumeDistance)+" -f "+Util::insertQuotes(ambFileLocation)+" --no-backups --no-verbose"
174 << "--replace-all-values --parent-element-name SoundGroup -e Volume -n "+Util::insertQuotes(volume)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"
175 << "--replace-all-values --parent-element-name SoundGroup -e Pitch -n "+Util::insertQuotes(pitch)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"
176 << "--replace-all-values --parent-element-name SoundGroup -e NumberOfChannels -n "+Util::insertQuotes(numberChannels)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"
177 << "--replace-all-values --parent-element-name Volume -e Min -n "+Util::insertQuotes(minVolume)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"
178 << "--replace-all-values --parent-element-name Volume -e Max -n "+Util::insertQuotes(maxVolume)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"
179 << "--replace-all-values --parent-element-name Pitch -e Min -n "+Util::insertQuotes(minPitch)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"
180 << "--replace-all-values --parent-element-name Pitch -e Max -n "+Util::insertQuotes(maxPitch)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose"
181 << "--replace-all-values -e Weight -n "+Util::insertQuotes(weight)+" -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose";
182
183 if(preventRepeat){
184 (*this->xmlCommands) << "--replace-all-values --parent-element-name SoundGroup -e Flags -n PreventRepeat -f "+Util::insertQuotes(grpFileLocation)+" --no-backups --no-verbose";
185 }
186
187 myXmlProcessor->start();
188 myXmlProcessor->wait(); // Wait until all xml is edited
189
190 QString currFileName;
191 QString currGrpFileLocation;
192 QString currAmbFileLocation;
193
194 for(int i=0; i<this->page2Table->rowCount(); i++){
195
196 (*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+outputFolder+" "+Util::insertQuotes(this->page2Table->item(i,1)->text()); // add location of sound file to convert
197
198 currFileName=this->page2Table->item(i,0)->text(); // get current file name
199 currAmbFileLocation = QString(ambFileLocation).replace("sample_file",currFileName); // get the new files, filenames
200 currGrpFileLocation = QString(grpFileLocation).replace("sample_file",currFileName);
201
202 QFile::copy(ambFileLocation, currAmbFileLocation); // make a copy of the sample files that will be the real files
203 QFile::copy(grpFileLocation, currGrpFileLocation);
204
205 (*this->xmlCommands) << "--replace-all-values -e BaseTrack1 -n "+Util::insertQuotes(currFileName)+" -f "+Util::insertQuotes(currAmbFileLocation)+" --no-backups --no-verbose" // process the xml
206 << "--replace-all-values -e Sound -n "+Util::insertQuotes(currFileName)+" -f "+Util::insertQuotes(currGrpFileLocation)+" --no-backups --no-verbose";
207
208 myXmlProcessor->start();
209 myXmlProcessor->wait(); // Wait until all xml is edited
210 }
211
212 (*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+outputFolder+" "+Util::insertQuotes(GlobalVars::VagoTemporaryDir+"/*.xml");
213
214 this->myConverter->start(); // finally process the onisplit commands
215 this->myConverter->wait(); // wait for it to complete
216
217 // Finally remove the sample files, since not needed anymore
218 QFile(ambFileLocation).remove();
219 QFile(grpFileLocation).remove();
220 }
221
222 void SoundPageFinal::catchXmlAndOSplitProcessingError(QString result, int numErrors){
223
224 if(numErrors!=0){
225 QString sNumErrors=QString::number(numErrors);
226 if(numErrors>1){
227 UtilVago::showErrorPopUpLogButton(result+"\n This is the last of " + sNumErrors + " Errors.");
228 }
229 else{
230 UtilVago::showErrorPopUpLogButton(result);
231 }
232 }
233 }
234
235 void SoundPageFinal::connectSlots(){
236 //This signal is for thread that is working setup the progress bar (make it visible and set it's min-max)
237 connect(this->myXmlProcessor, SIGNAL(resultConversion(QString, int)), this, SLOT(catchXmlAndOSplitProcessingError(QString, int)));
238 connect(this->myConverter, SIGNAL(resultConversion(QString, int)), this, SLOT(catchXmlAndOSplitProcessingError(QString, int)));
239 connect(ui->lbComplete, SIGNAL(linkActivated(const QString & )), this, SLOT(openSoundsFolder()));
240 }
241
242 SoundPageFinal::~SoundPageFinal()
243 {
244 delete this->xmlCommands;
245 delete this->oniSplitCommands;
246 delete this->myXmlProcessor;
247 delete this->myConverter;
248 delete ui;
249 }