Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/gui/EditorProperty.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 101 - (hide 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 haruneko24 50 #include "EditorProperty.h"
2    
3 haruneko24 54 #include <QFile>
4 haruneko24 60 #include <QFileInfo>
5 haruneko24 54 #include <QStringList>
6     #include <QTextCodec>
7     #include <QTextStream>
8    
9 haruneko24 55 #include "SynthesizerFactory.h"
10 haruneko24 74 #include "StyleGeneratorFactory.h"
11 haruneko24 101 #include "SecondOrderStyleGenerator.h"
12 haruneko24 74 #include "SimpleStyleGenerator.h"
13 haruneko24 59 #include "SingerPreferenceItem.h"
14     #include "SingerModel.h"
15 haruneko24 53 #include "TreeItem.h"
16 haruneko24 55 #include "Vocoder.h"
17 haruneko24 56 #include "dsp/star.h"
18 haruneko24 55 #include "WorldEngine.h"
19 haruneko24 56 #include "WaveCorpus.h"
20 haruneko24 50 #include "../configure.h"
21    
22     using namespace stand::gui;
23    
24 haruneko24 55 namespace
25     {
26    
27 haruneko24 74 class DefaultSynthesizerFactory : public SynthesizerFactory
28 haruneko24 55 {
29     public:
30 haruneko24 74 explicit DefaultSynthesizerFactory(EditorProperty *property)
31 haruneko24 55 {
32     _property = property;
33     }
34    
35     QString author() const
36     {
37 haruneko24 56 return QString("HAL@shurabaP");
38 haruneko24 55 }
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 haruneko24 59 stand::synthesis::AbstractCorpus *createCorpus(stand::model::SingerModel *singer)
64 haruneko24 55 {
65 haruneko24 59 return new stand::synthesis::WaveCorpus(singer);
66 haruneko24 55 }
67    
68 haruneko24 56 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 haruneko24 55 private:
87     EditorProperty *_property;
88     };
89    
90 haruneko24 74 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 haruneko24 101 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 haruneko24 55 }
169    
170 haruneko24 50 EditorProperty::EditorProperty()
171     {
172     _msFramePeriod = stand::DefaultFramePeriod;
173     _currentDir = QDir::current();
174 haruneko24 55
175 haruneko24 74 _EngineItem defaultEngine = {"STAND the WORLD", "Default", new DefaultSynthesizerFactory(this)};
176 haruneko24 55 _engines.append(defaultEngine);
177 haruneko24 56
178 haruneko24 74 _StyleItem defaultStyle = {"Simple Note F0", "Default", new DefaultStyleGeneratorFactory()};
179     _styles.append(defaultStyle);
180    
181 haruneko24 56 _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 haruneko24 50 }
188    
189     EditorProperty::~EditorProperty()
190     {
191     _destroy();
192     }
193    
194     void EditorProperty::_destroy()
195     {
196 haruneko24 59 for(int i = 0; i < _singers.size(); i++)
197 haruneko24 54 {
198 haruneko24 59 delete _singers[i].item;
199 haruneko24 54 }
200 haruneko24 59 _singers.clear();
201 haruneko24 55
202     for(int i = 0; i < _engines.size(); i++)
203     {
204     delete _engines[i].factory;
205     }
206     _engines.clear();
207    
208 haruneko24 74 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 haruneko24 55 _engines.append(defaultEngine);
219 haruneko24 74
220     _StyleItem defaultStyle = {"Simple Note F0", "Default", new DefaultStyleGeneratorFactory };
221     _styles.append(defaultStyle);
222 haruneko24 101
223     _StyleItem defaultStyle2 = {"Second Order", "Default", new DefaultStyleGeneratorFactory2 };
224     _styles.append(defaultStyle2);
225 haruneko24 50 }
226    
227 haruneko24 60 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 haruneko24 77 QStringList EditorProperty::singerList() const
241 haruneko24 52 {
242 haruneko24 77 QStringList ret;
243 haruneko24 63 foreach(const _SingerItem &item, _singers)
244 haruneko24 54 {
245 haruneko24 77 ret << item.name;
246 haruneko24 54 }
247     return ret;
248 haruneko24 52 }
249 haruneko24 53
250 haruneko24 77 QStringList EditorProperty::engineList() const
251 haruneko24 55 {
252 haruneko24 77 QStringList ret;
253 haruneko24 55 foreach(const _EngineItem &item , _engines)
254     {
255 haruneko24 77 ret << item.name;
256 haruneko24 55 }
257     return ret;
258     }
259    
260 haruneko24 77 QStringList EditorProperty::styleList() const
261 haruneko24 74 {
262 haruneko24 77 QStringList ret;
263 haruneko24 74 foreach(const _StyleItem &item , _styles)
264     {
265 haruneko24 77 ret << item.name;
266 haruneko24 74 }
267     return ret;
268     }
269    
270 haruneko24 59 QString EditorProperty::singerPath(const QString &key) const
271 haruneko24 54 {
272 haruneko24 63 foreach(const _SingerItem &item, _singers)
273 haruneko24 54 {
274 haruneko24 55 if(key == item.name)
275 haruneko24 54 {
276 haruneko24 55 return item.path;
277 haruneko24 54 }
278     }
279     return QString();
280     }
281    
282 haruneko24 55 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 haruneko24 74 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 haruneko24 59 stand::model::SingerModel *EditorProperty::singer(const QString &key) const
307 haruneko24 54 {
308 haruneko24 59 for(int i = 0; i < _singers.size(); i++)
309 haruneko24 54 {
310 haruneko24 59 if(key == _singers[i].name)
311 haruneko24 54 {
312 haruneko24 59 return _singers[i].item->singer();
313 haruneko24 54 }
314     }
315     return NULL;
316     }
317    
318 haruneko24 55 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 haruneko24 74 return NULL;
328 haruneko24 55 }
329    
330 haruneko24 74 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 haruneko24 63 void EditorProperty::appendSinger(const QString &path)
343 haruneko24 53 {
344 haruneko24 59 SingerPreferenceItem *s = new SingerPreferenceItem(path);
345     if(!s->isValid())
346 haruneko24 53 {
347 haruneko24 59 delete s;
348 haruneko24 53 return;
349     }
350 haruneko24 63 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 haruneko24 59 _singers.append(item);
361 haruneko24 53 }
362 haruneko24 54
363 haruneko24 74 void EditorProperty::appendStyle(const QString &path)
364     {
365     StyleGeneratorFactory *s = new StyleGeneratorFactory(path);
366 haruneko24 59
367 haruneko24 74 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 haruneko24 54 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 haruneko24 56 stream << "FramePeriod=" << _msFramePeriod << endl;
395     stream << "WorkingFolder=" << _currentDir.absolutePath() << endl;
396 haruneko24 54
397 haruneko24 56 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 haruneko24 59 for(int i = 0; i < _singers.size(); i++)
405 haruneko24 54 {
406 haruneko24 63 stream << "SingerPath=" << _singers[i].path << endl;
407 haruneko24 54 }
408    
409 haruneko24 74 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 haruneko24 54 return true;
420     }
421    
422 haruneko24 59 QList<QPair<QString, helper::PreferenceItem *> > EditorProperty::singers() const
423     {
424     QList<QPair<QString, helper::PreferenceItem *> > ret;
425    
426 haruneko24 60 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 haruneko24 59 return ret;
432     }
433    
434     QList<QPair<QString, helper::PreferenceItem *> > EditorProperty::engines() const
435     {
436     QList<QPair<QString, helper::PreferenceItem *> > ret;
437    
438 haruneko24 60 for(int i = 0; i < _engines.size(); i++)
439     {
440     ret.append(QPair<QString, helper::PreferenceItem *>(_engines[i].path, _engines[i].factory));
441     }
442 haruneko24 59 return ret;
443 haruneko24 60
444 haruneko24 59 }
445    
446 haruneko24 74 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 haruneko24 60 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 haruneko24 54 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 haruneko24 74 if(sl.size() < 2)
504 haruneko24 54 {
505     continue;
506     }
507 haruneko24 74 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 haruneko24 54 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 haruneko24 63 else if(sl.at(0) == "SingerPath")
523 haruneko24 54 {
524 haruneko24 63 appendSinger(sl.at(1));
525 haruneko24 54 }
526 haruneko24 56 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 haruneko24 74 else if(sl.at(0) == "StylePath")
551     {
552     appendStyle(sl.at(1));
553     }
554 haruneko24 56 else
555     {
556     qDebug("Unknown Symbol; %s", line.toUtf8().data());
557     }
558 haruneko24 54 }
559     return true;
560     }
561    

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