Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/gui/EditorProperty.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 101 - (show annotations) (download) (as text)
Fri Feb 1 01:09:56 2013 UTC (11 years, 2 months ago) by haruneko24
File MIME type: text/x-c++src
File size: 13691 byte(s)


1 #include "EditorProperty.h"
2
3 #include <QFile>
4 #include <QFileInfo>
5 #include <QStringList>
6 #include <QTextCodec>
7 #include <QTextStream>
8
9 #include "SynthesizerFactory.h"
10 #include "StyleGeneratorFactory.h"
11 #include "SecondOrderStyleGenerator.h"
12 #include "SimpleStyleGenerator.h"
13 #include "SingerPreferenceItem.h"
14 #include "SingerModel.h"
15 #include "TreeItem.h"
16 #include "Vocoder.h"
17 #include "dsp/star.h"
18 #include "WorldEngine.h"
19 #include "WaveCorpus.h"
20 #include "../configure.h"
21
22 using namespace stand::gui;
23
24 namespace
25 {
26
27 class DefaultSynthesizerFactory : public SynthesizerFactory
28 {
29 public:
30 explicit DefaultSynthesizerFactory(EditorProperty *property)
31 {
32 _property = property;
33 }
34
35 QString author() const
36 {
37 return QString("HAL@shurabaP");
38 }
39
40 QString comment() const
41 {
42 return QString("This engine is a default one for ECHOES editor."
43 " It uses WORLD, a fast Vocoder system by M.Morise."
44 " You can get original source codes of WORLD below; "
45 " http://www.slp.is.ritsumei.ac.jp/~morise/world/");
46 }
47
48 QString web() const
49 {
50 return QString("http://sourceforge.jp/projects/echoes/");
51 }
52
53 QString name() const
54 {
55 return QString("STAND the WORLD");
56 }
57
58 QString iconPath() const
59 {
60 return QString("stand.png");
61 }
62
63 stand::synthesis::AbstractCorpus *createCorpus(stand::model::SingerModel *singer)
64 {
65 return new stand::synthesis::WaveCorpus(singer);
66 }
67
68 stand::synthesis::AbstractSynthesizer *createSynthesizer(stand::synthesis::AbstractCorpus *corpus)
69 {
70 if(!corpus || !_property)
71 {
72 return NULL;
73 }
74
75 using namespace stand::synthesis;
76
77 int sampleRate = _property->format().sampleRate();
78 int filterLength = world::GetFFTSizeForStar(sampleRate);
79 VocoderInfo info(VocoderInfo::PowerSpectrum, filterLength, VocoderInfo::ResidualSpectrum, filterLength, sampleRate);
80 WorldEngine *engine = new stand::synthesis::WorldEngine(info);
81
82 Vocoder *v = new Vocoder(engine, corpus);
83 return v;
84 }
85
86 private:
87 EditorProperty *_property;
88 };
89
90 class DefaultStyleGeneratorFactory : public StyleGeneratorFactory
91 {
92 public:
93 explicit DefaultStyleGeneratorFactory(const QString &path = QString()) :
94 StyleGeneratorFactory(path)
95 {
96 }
97
98 QString author() const
99 {
100 return QString("HAL@shurabaP");
101 }
102
103 QString comment() const
104 {
105 return QString("This is a test packaged class for AbstractStyleGenerator");
106 }
107
108 QString web() const
109 {
110 return QString("http://sourceforge.jp/projects/echoes/");
111 }
112
113 QString name() const
114 {
115 return QString("Simple F0 Generator");
116 }
117
118 QString iconPath() const
119 {
120 return QString("");
121 }
122
123 virtual stand::echoes::AbstractStyleGenerator *createGenerator() const
124 {
125 return new stand::echoes::SimpleStyleGenerator;
126 }
127 };
128
129 class DefaultStyleGeneratorFactory2 : public StyleGeneratorFactory
130 {
131 public:
132 explicit DefaultStyleGeneratorFactory2(const QString &path = QString()) :
133 StyleGeneratorFactory(path)
134 {
135 }
136
137 QString author() const
138 {
139 return QString("HAL@shurabaP");
140 }
141
142 QString comment() const
143 {
144 return QString("This is a test packaged class for AbstractStyleGenerator");
145 }
146
147 QString web() const
148 {
149 return QString("http://sourceforge.jp/projects/echoes/");
150 }
151
152 QString name() const
153 {
154 return QString("Simple F0 Generator");
155 }
156
157 QString iconPath() const
158 {
159 return QString("");
160 }
161
162 virtual stand::echoes::AbstractStyleGenerator *createGenerator() const
163 {
164 return new stand::echoes::SecondOrderStyleGenerator;
165 }
166 };
167
168 }
169
170 EditorProperty::EditorProperty()
171 {
172 _msFramePeriod = stand::DefaultFramePeriod;
173 _currentDir = QDir::current();
174
175 _EngineItem defaultEngine = {"STAND the WORLD", "Default", new DefaultSynthesizerFactory(this)};
176 _engines.append(defaultEngine);
177
178 _StyleItem defaultStyle = {"Simple Note F0", "Default", new DefaultStyleGeneratorFactory()};
179 _styles.append(defaultStyle);
180
181 _format.setByteOrder(QAudioFormat::LittleEndian);
182 _format.setChannelCount(stand::DefaultChannelCount);
183 _format.setCodec("audio/pcm");
184 _format.setSampleRate(stand::DefaultSamplingFrequency);
185 _format.setSampleSize(stand::DefaultSamplingSize);
186 _format.setSampleType(QAudioFormat::SignedInt);
187 }
188
189 EditorProperty::~EditorProperty()
190 {
191 _destroy();
192 }
193
194 void EditorProperty::_destroy()
195 {
196 for(int i = 0; i < _singers.size(); i++)
197 {
198 delete _singers[i].item;
199 }
200 _singers.clear();
201
202 for(int i = 0; i < _engines.size(); i++)
203 {
204 delete _engines[i].factory;
205 }
206 _engines.clear();
207
208 for(int i = 0; i < _styles.size(); i++)
209 {
210 delete _styles[i].factory;
211 }
212 _styles.clear();
213
214 _msFramePeriod = stand::DefaultFramePeriod;
215 _currentDir = QDir::current();
216
217 _EngineItem defaultEngine = { "STAND the WORLD", "Default", new DefaultSynthesizerFactory(this)};
218 _engines.append(defaultEngine);
219
220 _StyleItem defaultStyle = {"Simple Note F0", "Default", new DefaultStyleGeneratorFactory };
221 _styles.append(defaultStyle);
222
223 _StyleItem defaultStyle2 = {"Second Order", "Default", new DefaultStyleGeneratorFactory2 };
224 _styles.append(defaultStyle2);
225 }
226
227 void EditorProperty::setCurrentDir(const QDir &dir)
228 {
229 QFileInfo info(dir.path());
230 if(info.isFile())
231 {
232 _currentDir = info.dir();
233 }
234 else
235 {
236 _currentDir = dir;
237 }
238 }
239
240 QStringList EditorProperty::singerList() const
241 {
242 QStringList ret;
243 foreach(const _SingerItem &item, _singers)
244 {
245 ret << item.name;
246 }
247 return ret;
248 }
249
250 QStringList EditorProperty::engineList() const
251 {
252 QStringList ret;
253 foreach(const _EngineItem &item , _engines)
254 {
255 ret << item.name;
256 }
257 return ret;
258 }
259
260 QStringList EditorProperty::styleList() const
261 {
262 QStringList ret;
263 foreach(const _StyleItem &item , _styles)
264 {
265 ret << item.name;
266 }
267 return ret;
268 }
269
270 QString EditorProperty::singerPath(const QString &key) const
271 {
272 foreach(const _SingerItem &item, _singers)
273 {
274 if(key == item.name)
275 {
276 return item.path;
277 }
278 }
279 return QString();
280 }
281
282 QString EditorProperty::enginePath(const QString &key) const
283 {
284 foreach(const _EngineItem &item, _engines)
285 {
286 if(key == item.name)
287 {
288 return item.path;
289 }
290 }
291 return QString();
292 }
293
294 QString EditorProperty::stylePath(const QString &key) const
295 {
296 foreach(const _StyleItem &item, _styles)
297 {
298 if(key == item.name)
299 {
300 return item.path;
301 }
302 }
303 return QString();
304 }
305
306 stand::model::SingerModel *EditorProperty::singer(const QString &key) const
307 {
308 for(int i = 0; i < _singers.size(); i++)
309 {
310 if(key == _singers[i].name)
311 {
312 return _singers[i].item->singer();
313 }
314 }
315 return NULL;
316 }
317
318 SynthesizerFactory *EditorProperty::factory(const QString &key) const
319 {
320 foreach(const _EngineItem &item, _engines)
321 {
322 if(key == item.name)
323 {
324 return item.factory;
325 }
326 }
327 return NULL;
328 }
329
330 StyleGeneratorFactory *EditorProperty::style(const QString &key) const
331 {
332 foreach(const _StyleItem &item, _styles)
333 {
334 if(key == item.name)
335 {
336 return item.factory;
337 }
338 }
339 return NULL;
340 }
341
342 void EditorProperty::appendSinger(const QString &path)
343 {
344 SingerPreferenceItem *s = new SingerPreferenceItem(path);
345 if(!s->isValid())
346 {
347 delete s;
348 return;
349 }
350 appendSinger(path, s);
351 }
352
353 void EditorProperty::appendSinger(const QString &path, SingerPreferenceItem *singer)
354 {
355 if(!singer || !singer->isValid())
356 {
357 return;
358 }
359 _SingerItem item = {singer->name(), path, singer};
360 _singers.append(item);
361 }
362
363 void EditorProperty::appendStyle(const QString &path)
364 {
365 StyleGeneratorFactory *s = new StyleGeneratorFactory(path);
366
367 appendStyle(path, s);
368 }
369
370 void EditorProperty::appendStyle(const QString &path, StyleGeneratorFactory *style)
371 {
372 if(!style || !style->isValid())
373 {
374 return;
375 }
376 _StyleItem item = {style->name(), path, style};
377 _styles.append(item);
378 }
379
380
381 bool EditorProperty::write(const QString &path) const
382 {
383 QFile file(path);
384
385 if(!file.open(QIODevice::WriteOnly))
386 {
387 qDebug("EditorProperty::write(\"%s\"); // File open error.", path.toUtf8().data());
388 return false;
389 }
390
391 QTextStream stream(&file);
392 stream.setCodec(QTextCodec::codecForName("UTF-8"));
393
394 stream << "FramePeriod=" << _msFramePeriod << endl;
395 stream << "WorkingFolder=" << _currentDir.absolutePath() << endl;
396
397 stream << "ByteOrder=" << _format.byteOrder() << endl;
398 stream << "ChannelCount=" << _format.channelCount() << endl;
399 stream << "Codec=" << _format.codec() << endl;
400 stream << "SampleRate=" << _format.sampleRate() << endl;
401 stream << "SampleSize=" << _format.sampleSize() << endl;
402 stream << "SampleType=" << _format.sampleType() << endl;
403
404 for(int i = 0; i < _singers.size(); i++)
405 {
406 stream << "SingerPath=" << _singers[i].path << endl;
407 }
408
409 for(int i = 1; i < _engines.size(); i++)
410 {
411 stream << "EnginePath=" << _engines[i].path << endl;
412 }
413
414 for(int i = 1; i < _styles.size(); i++)
415 {
416 stream << "StylePath=" << _styles[i].path << endl;
417 }
418
419 return true;
420 }
421
422 QList<QPair<QString, helper::PreferenceItem *> > EditorProperty::singers() const
423 {
424 QList<QPair<QString, helper::PreferenceItem *> > ret;
425
426 for(int i = 0; i < _singers.size(); i++)
427 {
428 ret.append(QPair<QString, helper::PreferenceItem *>(_singers[i].path, _singers[i].item));
429 }
430
431 return ret;
432 }
433
434 QList<QPair<QString, helper::PreferenceItem *> > EditorProperty::engines() const
435 {
436 QList<QPair<QString, helper::PreferenceItem *> > ret;
437
438 for(int i = 0; i < _engines.size(); i++)
439 {
440 ret.append(QPair<QString, helper::PreferenceItem *>(_engines[i].path, _engines[i].factory));
441 }
442 return ret;
443
444 }
445
446 QList<QPair<QString, helper::PreferenceItem *> > EditorProperty::styles() const
447 {
448 QList<QPair<QString, helper::PreferenceItem *> > ret;
449
450 for(int i = 0; i < _styles.size(); i++)
451 {
452 ret.append(QPair<QString, helper::PreferenceItem *>(_styles[i].path, _styles[i].factory));
453 }
454 return ret;
455
456 }
457
458 void EditorProperty::setSinger(int index, const QString &path, SingerPreferenceItem *singer)
459 {
460 if(index < 0 || _singers.size() <= index)
461 {
462 return;
463 }
464 if(!singer || !singer->isValid())
465 {
466 return;
467 }
468
469 delete _singers[index].item;
470 _singers[index].item = singer;
471 _singers[index].path = path;
472 _singers[index].name = singer->name();
473 }
474
475 bool EditorProperty::read(const QString &path)
476 {
477 QFile file(path);
478
479 if(!file.exists())
480 {
481 qDebug("EditorProperty::read(\"%s\"); // File not found.", path.toUtf8().data());
482 return false;
483 }
484
485 if(!file.open(QIODevice::ReadOnly))
486 {
487 qDebug("EditorProperty::read(\"%s\"); // File open error.", path.toUtf8().data());
488 return false;
489 }
490
491 QTextStream stream(&file);
492 stream.setCodec(QTextCodec::codecForName("UTF-8"));
493
494 _destroy();
495 while(!stream.atEnd())
496 {
497 QString line = stream.readLine();
498 if(!line.contains("="))
499 {
500 continue;
501 }
502 QStringList sl = line.split("=");
503 if(sl.size() < 2)
504 {
505 continue;
506 }
507 else if(sl.size() > 2)
508 {
509 for(int i = 2; i < sl.size(); i++)
510 {
511 sl[1] += "=" + sl.at(i);
512 }
513 }
514 if(sl.at(0) == "FramePeriod")
515 {
516 _msFramePeriod = sl.at(1).toDouble();
517 }
518 else if(sl.at(0) == "WorkingFolder")
519 {
520 _currentDir = QDir(sl.at(1));
521 }
522 else if(sl.at(0) == "SingerPath")
523 {
524 appendSinger(sl.at(1));
525 }
526 else if(sl.at(0) == "ByteOrder")
527 {
528 _format.setByteOrder((QAudioFormat::Endian)sl.at(1).toInt());
529 }
530 else if(sl.at(0) == "ChannelCount")
531 {
532 _format.setChannelCount(sl.at(1).toInt());
533 }
534 else if(sl.at(0) == "Codec")
535 {
536 _format.setCodec(sl.at(1));
537 }
538 else if(sl.at(0) == "SampleSize")
539 {
540 _format.setSampleSize(sl.at(1).toInt());
541 }
542 else if(sl.at(0) == "SampleType")
543 {
544 _format.setSampleType((QAudioFormat::SampleType)sl.at(1).toInt());
545 }
546 else if(sl.at(0) == "SampleRate")
547 {
548 _format.setSampleRate(sl.at(1).toInt());
549 }
550 else if(sl.at(0) == "StylePath")
551 {
552 appendStyle(sl.at(1));
553 }
554 else
555 {
556 qDebug("Unknown Symbol; %s", line.toUtf8().data());
557 }
558 }
559 return true;
560 }
561

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26