ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/soundWizard/soundpagefinal.cpp
Revision: 1035
Committed: Thu Mar 24 22:28:41 2016 UTC (9 years, 6 months ago) by s10k
Content type: text/x-c++src
Original Path: Vago/trunk/Vago/soundWizard/soundpagefinal.cpp
File size: 11474 byte(s)
Log Message:
Vago 9.0b

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 QString message="Couldn't clean vago temp dir for complete sound wizard. Aborting.\n"+GlobalVars::VagoTemporaryDir;
152 this->myLogger->writeString(message);
153 Util::showErrorLogPopUp(message);
154 return;
155 }
156
157 if(!QDir(QDir::tempPath()).mkpath("VagoTemp")){
158 QString message="Couldn't reconstruct vago temp dir for complete sound wizard. Aborting.\n"+GlobalVars::VagoTemporaryDir;
159 this->myLogger->writeString(message);
160 Util::showErrorLogPopUp(message);
161 }
162
163 // Copy sample xml files to tmp dir
164 QFile::copy(":/new/sampleFiles/"+ambFile , ambFileLocation);
165 QFile::copy(":/new/sampleFiles/"+grpFile , grpFileLocation);
166 QFile::setPermissions(ambFileLocation, QFile::ReadOwner | QFile::WriteOwner); //remove read only attribute that come from resources
167 QFile::setPermissions(grpFileLocation, QFile::ReadOwner | QFile::WriteOwner);
168
169 (*this->xmlCommands) << "replaceall -element:Priority -value:"+priority+" -filename:"+ambFileLocation+" -nobackups"
170 << "replaceall -element:Flags -value:"+flags.join(" ")+" -filename:"+ambFileLocation+" -nobackups"
171 << "replaceall -element:SphereRadius -value:"+sphereRadious+" -filename:"+ambFileLocation+" -nobackups"
172 << "replaceall -element:Treshold -value:"+treshold+" -filename:"+ambFileLocation+" -nobackups"
173 << "replaceall -element:MinOcclusion -value:"+minOcclusion+" -filename:"+ambFileLocation+" -nobackups"
174 << "replaceall -parelement:ElapsedTime -element:Min -value:"+minElapsedTime+" -filename:"+ambFileLocation+" -nobackups"
175 << "replaceall -parelement:Distance -element:Max -value:"+maxVolumeDistance+" -filename:"+ambFileLocation+" -nobackups"
176 << "replaceall -parelement:Distance -element:Min -value:"+minVolumeDistance+" -filename:"+ambFileLocation+" -nobackups"
177 << "replaceall -parelement:SoundGroup -element:Volume -value:"+volume+" -filename:"+grpFileLocation+" -nobackups"
178 << "replaceall -parelement:SoundGroup -element:Pitch -value:"+pitch+" -filename:"+grpFileLocation+" -nobackups"
179 << "replaceall -parelement:SoundGroup -element:NumberOfChannels -value:"+numberChannels+" -filename:"+grpFileLocation+" -nobackups"
180 << "replaceall -parelement:Volume -element:Min -value:"+minVolume+" -filename:"+grpFileLocation+" -nobackups"
181 << "replaceall -parelement:Volume -element:Max -value:"+maxVolume+" -filename:"+grpFileLocation+" -nobackups"
182 << "replaceall -parelement:Pitch -element:Min -value:"+minPitch+" -filename:"+grpFileLocation+" -nobackups"
183 << "replaceall -parelement:Pitch -element:Max -value:"+maxPitch+" -filename:"+grpFileLocation+" -nobackups"
184 << "replaceall -element:Weight -value:"+weight+" -filename:"+grpFileLocation+" -nobackups";
185
186 if(preventRepeat){
187 (*this->xmlCommands) << "replaceall -parelement:SoundGroup -element:Flags -value:PreventRepeat -filename:"+grpFileLocation+" -nobackups";
188 }
189
190 myXmlProcessor->start();
191 myXmlProcessor->wait(); // Wait until all xml is edited
192
193 QString currFileName;
194 QString currGrpFileLocation;
195 QString currAmbFileLocation;
196
197 for(int i=0; i<this->page2Table->rowCount(); i++){
198
199 (*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+outputFolder+" "+Util::insertQuotes(this->page2Table->item(i,1)->text()); // add location of sound file to convert
200
201 currFileName=this->page2Table->item(i,0)->text(); // get current file name
202 currAmbFileLocation = QString(ambFileLocation).replace("sample_file",currFileName); // get the new files, filenames
203 currGrpFileLocation = QString(grpFileLocation).replace("sample_file",currFileName);
204
205 QFile::copy(ambFileLocation, currAmbFileLocation); // make a copy of the sample files that will be the real files
206 QFile::copy(grpFileLocation, currGrpFileLocation);
207
208 (*this->xmlCommands) << "replaceall -element:BaseTrack1 -value:"+currFileName+" -filename:"+currAmbFileLocation+" -nobackups" // process the xml
209 << "replaceall -element:Sound -value:"+currFileName+" -filename:"+currGrpFileLocation+" -nobackups";
210
211 myXmlProcessor->start();
212 myXmlProcessor->wait(); // Wait until all xml is edited
213 }
214
215 (*this->oniSplitCommands) << this->commandMap->value("xml->XML->ONI")+" "+outputFolder+" "+Util::insertQuotes(GlobalVars::VagoTemporaryDir+"/*.xml");
216
217 this->myConverter->start(); // finally process the onisplit commands
218 this->myConverter->wait(); // wait for it to complete
219
220 // Finally remove the sample files, since not needed anymore
221 QFile(ambFileLocation).remove();
222 QFile(grpFileLocation).remove();
223 }
224
225 void SoundPageFinal::catchXmlAndOSplitProcessingError(QString result, int numErrors){
226
227 if(numErrors!=0){
228 QString sNumErrors=QString::number(numErrors);
229 if(numErrors>1){
230 Util::showErrorLogPopUp(result+"\n This is the last of "+sNumErrors+" Errors.");
231 }
232 else{
233 Util::showErrorLogPopUp(result);
234 }
235 }
236 }
237
238 void SoundPageFinal::connectSlots(){
239 //This signal is for thread that is working setup the progress bar (make it visible and set it's min-max)
240 connect(this->myXmlProcessor, SIGNAL(resultConversion(QString, int)), this, SLOT(catchXmlAndOSplitProcessingError(QString, int)));
241 connect(this->myConverter, SIGNAL(resultConversion(QString, int)), this, SLOT(catchXmlAndOSplitProcessingError(QString, int)));
242 connect(ui->lbComplete, SIGNAL(linkActivated(const QString & )), this, SLOT(openSoundsFolder()));
243 }
244
245 SoundPageFinal::~SoundPageFinal()
246 {
247 delete this->xmlCommands;
248 delete this->oniSplitCommands;
249 delete this->myXmlProcessor;
250 delete this->myConverter;
251 delete ui;
252 }