ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/soundWizard/soundpagefinal.cpp
Revision: 771
Committed: Sun Mar 31 19:02:16 2013 UTC (12 years, 6 months ago) by s10k
Content type: text/x-c++src
Original Path: Vago/trunk/Vago/soundWizard/soundpagefinal.cpp
File size: 11003 byte(s)
Log Message:

File Contents

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