リビジョン | 1975 (tree) |
---|---|
日時 | 2012-01-29 05:16:36 |
作者 | ![]() |
[stand2.0/StandConverter] TranscriberをGUIへ移植(未完)
@@ -17,8 +17,8 @@ | ||
17 | 17 | |
18 | 18 | using namespace stand::gui; |
19 | 19 | |
20 | -ConverterWindow::ConverterWindow(QWidget *parent) : | |
21 | - QMainWindow(parent), | |
20 | +ConverterWindow::ConverterWindow(QWidget *parent, Qt::WindowFlags f) : | |
21 | + QMainWindow(parent, f), | |
22 | 22 | ui(new Ui::ConverterWindow()) |
23 | 23 | { |
24 | 24 | ui->setupUi(this); |
@@ -16,7 +16,7 @@ | ||
16 | 16 | |
17 | 17 | // Set ColorComboBox |
18 | 18 | QStringList colorNames; |
19 | - colorNames << tr("red") << tr("green") << tr("blue") << tr("cyan") << tr("magenta") << tr("yellow") << tr("white"); | |
19 | + colorNames << tr("red") << tr("lime") << tr("blue") << tr("cyan") << tr("magenta") << tr("yellow") << tr("white"); | |
20 | 20 | QPalette pallete = ui->ColorSelector->palette(); |
21 | 21 | pallete.setColor(QPalette::Highlight, Qt::transparent); |
22 | 22 |
@@ -33,7 +33,7 @@ | ||
33 | 33 | void sendCancelToConverter(); |
34 | 34 | |
35 | 35 | public: |
36 | - explicit ConverterWindow(QWidget *parent = 0); | |
36 | + explicit ConverterWindow(QWidget *parent = 0, Qt::WindowFlags f = Qt::Window); | |
37 | 37 | ~ConverterWindow(); |
38 | 38 | |
39 | 39 | /// <summary> オーバーライドされた closeEvent .ユーザが Window を閉じようとしたときに呼ばれます. </summary> |
@@ -78,13 +78,13 @@ | ||
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | -void MappingView::setMapping(QVector<stand::gui::MappingView::Map> &mapping) | |
81 | +void MappingView::setMapping(QVector<stand::gui::MappingView::Item> &mapping) | |
82 | 82 | { |
83 | 83 | _data = mapping; |
84 | 84 | unsigned int i; |
85 | 85 | for(i = 0; i < _data.size(); i++) |
86 | 86 | { |
87 | - Map m = _data.at(i), tmp; | |
87 | + Item m = _data.at(i), tmp; | |
88 | 88 | int index = i; |
89 | 89 | for(int j = i + 1; j < _data.size(); j++) |
90 | 90 | { |
@@ -5,8 +5,11 @@ | ||
5 | 5 | #include "../synthesis/Transcriber.h" |
6 | 6 | #include "../synthesis/TranscriberSetting.h" |
7 | 7 | #include "../io/UtauLibrary.h" |
8 | +#include "../utility/Utility.h" | |
9 | +#include "ConverterWindow.h" | |
8 | 10 | |
9 | 11 | #include <QMessageBox> |
12 | +#include <QFileDialog> | |
10 | 13 | #include <QCloseEvent> |
11 | 14 | |
12 | 15 | using namespace stand::gui; |
@@ -17,6 +20,8 @@ | ||
17 | 20 | { |
18 | 21 | ui->setupUi(this); |
19 | 22 | |
23 | + // TabWidget の中身を空にする. | |
24 | + // 今のとこ必要なんだけど, ui の設定でどうにかならないのかな? | |
20 | 25 | while(ui->SettingTabs->count() != 0) |
21 | 26 | { |
22 | 27 | QWidget *p = ui->SettingTabs->widget(0); |
@@ -24,10 +29,10 @@ | ||
24 | 29 | delete p; |
25 | 30 | } |
26 | 31 | TranscriberWidget *w = new TranscriberWidget(ui->SettingTabs); |
27 | - ui->SettingTabs->addTab(w, tr("Base")); | |
32 | + ui->SettingTabs->addTab(w, tr("Lib. 1")); | |
28 | 33 | |
29 | 34 | connect(w, SIGNAL(changed(QWidget*)), this, SLOT(settingChanged())); |
30 | - connect(this, SIGNAL(mappingChanged(QVector<stand::gui::MappingView::Map>&)), ui->MappingView, SLOT(setMapping(QVector<stand::gui::MappingView::Map>&))); | |
35 | + connect(this, SIGNAL(mappingChanged(QVector<stand::gui::MappingView::Item>&)), ui->MappingView, SLOT(setMapping(QVector<stand::gui::MappingView::Item>&))); | |
31 | 36 | |
32 | 37 | isAnalyzing = false; |
33 | 38 | current = NULL; |
@@ -43,8 +48,8 @@ | ||
43 | 48 | |
44 | 49 | void TranscriberWindow::settingChanged() |
45 | 50 | { |
46 | - QVector<stand::gui::MappingView::Map> mapping; | |
47 | - stand::gui::MappingView::Map m; | |
51 | + QVector<stand::gui::MappingView::Item> mapping; | |
52 | + stand::gui::MappingView::Item m; | |
48 | 53 | for(int i = 0; i < ui->SettingTabs->count(); i++) |
49 | 54 | { |
50 | 55 | TranscriberWidget *w = dynamic_cast<TranscriberWidget *>(ui->SettingTabs->widget(i)); |
@@ -86,12 +91,12 @@ | ||
86 | 91 | { |
87 | 92 | int index = ui->SettingTabs->count(); |
88 | 93 | QString num; |
89 | - num.setNum(index); | |
94 | + num.setNum(index + 1); | |
90 | 95 | |
91 | 96 | TranscriberWidget *w = new TranscriberWidget(ui->SettingTabs, index); |
92 | - ui->SettingTabs->addTab(w, tr("Opt. ") + num); | |
97 | + ui->SettingTabs->addTab(w, tr("Lib. ") + num); | |
93 | 98 | connect(w, SIGNAL(changed(QWidget*)), this, SLOT(settingChanged())); |
94 | - connect(this, SIGNAL(mappingChanged(QVector<stand::gui::MappingView::Map>&)), ui->MappingView, SLOT(setMapping(QVector<stand::gui::MappingView::Map>&))); | |
99 | + connect(this, SIGNAL(mappingChanged(QVector<stand::gui::MappingView::Item>&)), ui->MappingView, SLOT(setMapping(QVector<stand::gui::MappingView::Item>&))); | |
95 | 100 | settingChanged(); |
96 | 101 | } |
97 | 102 |
@@ -98,10 +103,10 @@ | ||
98 | 103 | void TranscriberWindow::removeTab() |
99 | 104 | { |
100 | 105 | int index = ui->SettingTabs->currentIndex(); |
101 | - // Base tab cannot be removed. | |
102 | - if(index == 0) | |
106 | + // 少なくとも一つのタブは必要である. | |
107 | + if(ui->SettingTabs->count() == 1) | |
103 | 108 | { |
104 | - QMessageBox::critical(this, tr("Error"), tr("You can not remove base tab."), QMessageBox::Ok); | |
109 | + QMessageBox::critical(this, tr("Error"), tr("You need at least one lib."), QMessageBox::Ok); | |
105 | 110 | return; |
106 | 111 | } |
107 | 112 |
@@ -131,6 +136,8 @@ | ||
131 | 136 | ui->ProgressBar->setEnabled(isAnalyzing); |
132 | 137 | ui->RemoveButton->setEnabled(!isAnalyzing); |
133 | 138 | ui->SettingTabs->setEnabled(!isAnalyzing); |
139 | + ui->RootDirectory->setEnabled(!isAnalyzing); | |
140 | + ui->RootSelector->setEnabled(!isAnalyzing); | |
134 | 141 | } |
135 | 142 | |
136 | 143 | void TranscriberWindow::pushAnalyze() |
@@ -145,17 +152,36 @@ | ||
145 | 152 | } |
146 | 153 | } |
147 | 154 | |
155 | +void TranscriberWindow::pushRootDir() | |
156 | +{ | |
157 | + QString dirName = QFileDialog::getExistingDirectory( | |
158 | + this, | |
159 | + tr("Select connect root directory."), | |
160 | + tr("") | |
161 | + ); | |
162 | + ui->RootDirectory->setText(dirName); | |
163 | +} | |
164 | + | |
148 | 165 | void TranscriberWindow::_beginAnalyze() |
149 | 166 | { |
150 | 167 | stand::synthesis::TranscriberSetting s; |
151 | - // ToDo::Create Setting | |
152 | - | |
168 | + // Directory の存在チェック.なければ作成するなどの処理. | |
169 | + if(!stand::utility::makeDirectory(this, ui->RootDirectory->text(), true)) | |
170 | + { | |
171 | + return; | |
172 | + } | |
173 | + // 設定がおかしい. | |
174 | + if(!_checkSettingAvailability()) | |
175 | + { | |
176 | + return; | |
177 | + } | |
178 | + // コンバータが使える設定に変換する.できなければ帰る. | |
153 | 179 | if(!_createSetting(s)) |
154 | 180 | { |
155 | 181 | QMessageBox::critical(this, tr("Error"), tr("Some settings are invalid.")); |
156 | 182 | return; |
157 | 183 | } |
158 | - ui->ProgressBar->setMaximum(s.base.lib->size()); | |
184 | + ui->ProgressBar->setMaximum(s.libraries.at(0).body->size()); | |
159 | 185 | current = new stand::synthesis::Transcriber(&s, this); |
160 | 186 | connect(this, SIGNAL(sendCancelToTranscriber()), current, SLOT(cancel())); |
161 | 187 | connect(current, SIGNAL(progressChanged(int)), ui->ProgressBar, SLOT(setValue(int))); |
@@ -185,62 +211,63 @@ | ||
185 | 211 | bool TranscriberWindow::_createSetting(stand::synthesis::TranscriberSetting &s) |
186 | 212 | { |
187 | 213 | s.numThreads = ui->NumThreads->value(); |
188 | - s.base.lib = new stand::io::UtauLibrary(); | |
189 | 214 | |
190 | - TranscriberWidget *w = dynamic_cast<TranscriberWidget *>(ui->SettingTabs->widget(0)); | |
191 | - QString filename = w->dir() + QDir::separator() + "oto.ini"; | |
192 | - if(!s.base.lib->readFromOtoIni(filename, w->codec())) | |
215 | + // 指定されたライブラリを全部読み込む. | |
216 | + for(int i = 0; i < ui->SettingTabs->count(); i++) | |
193 | 217 | { |
194 | - QMessageBox::critical(this, tr("Error"), tr("Base file path is invalid\n") + filename); | |
195 | - delete s.base.lib; | |
196 | - return false; | |
197 | - } | |
198 | - s.base.brightness = w->bri(); | |
199 | - s.base.note = w->note(); | |
200 | - | |
201 | - for(int i = 0; i < ui->SettingTabs->count() - 1; i++) | |
202 | - { | |
203 | 218 | stand::synthesis::Transcriber::TranscriberItem item; |
204 | - w = dynamic_cast<TranscriberWidget *>(ui->SettingTabs->widget(i + 1)); | |
219 | + TranscriberWidget *w = dynamic_cast<TranscriberWidget *>(ui->SettingTabs->widget(i)); | |
205 | 220 | QString filename = w->dir() + QDir::separator() + "oto.ini"; |
206 | 221 | stand::io::UtauLibrary *lib = new stand::io::UtauLibrary(); |
207 | - if(lib->readFromOtoIni(filename, w->codec())) | |
222 | + if(lib->readFromOtoIni(filename, w->codec()) && lib->size() != 0) | |
208 | 223 | { |
209 | - item.lib = lib; | |
224 | + item.body = lib; | |
210 | 225 | item.brightness = w->bri(); |
211 | 226 | item.note = w->note(); |
212 | - s.optionals.push_back(item); | |
227 | + s.libraries.push_back(item); | |
228 | + const stand::io::UtauPhoneme *p = lib->at(0); | |
229 | + // 波形データの場合,とりあえずユーザに通知しておしまいにする. | |
230 | + // ConverterDialogにしておけばよかったか… | |
231 | + if(p->filename.contains(".wav")) | |
232 | + { | |
233 | + QMessageBox::critical(this, tr("Error"), tr("You must convert the library below.\n") + lib->directory().absolutePath()); | |
234 | + for(int i = 0; i < s.libraries.size(); i++) | |
235 | + { | |
236 | + delete s.libraries.at(i).body; | |
237 | + } | |
238 | + return false; | |
239 | + } | |
213 | 240 | } |
214 | 241 | else |
215 | 242 | { |
216 | - QMessageBox::critical(this, tr("Error"), tr("Invalid file path\n") + filename); | |
243 | + // 読み込めなかった. | |
244 | + QMessageBox::critical(this, tr("Error"), tr("Could not find the library below\n") + filename); | |
217 | 245 | delete lib; |
218 | - delete s.base.lib; | |
219 | - for(int i = 0; i < s.optionals.size(); i++) | |
246 | + for(int i = 0; i < s.libraries.size(); i++) | |
220 | 247 | { |
221 | - delete s.optionals.at(i).lib; | |
248 | + delete s.libraries.at(i).body; | |
222 | 249 | } |
223 | 250 | return false; |
224 | 251 | } |
225 | 252 | } |
226 | 253 | // ToDo::そーーーーと!! |
227 | - for(int i = 0; i < s.optionals.size(); i++) | |
254 | + for(int i = 0; i < s.libraries.size(); i++) | |
228 | 255 | { |
229 | - int minimum = s.optionals.at(i).brightness; | |
256 | + int minimum = s.libraries.at(i).brightness; | |
230 | 257 | int index = i; |
231 | - for(int j = i + 1; j < s.optionals.size(); j++) | |
258 | + for(int j = i + 1; j < s.libraries.size(); j++) | |
232 | 259 | { |
233 | - if(minimum < s.optionals.at(j).brightness) | |
260 | + if(minimum < s.libraries.at(j).brightness) | |
234 | 261 | { |
235 | - minimum = s.optionals.at(j).brightness; | |
262 | + minimum = s.libraries.at(j).brightness; | |
236 | 263 | index = j; |
237 | 264 | } |
238 | 265 | } |
239 | 266 | stand::synthesis::Transcriber::TranscriberItem item, tmp; |
240 | - item = s.optionals.at(index); | |
241 | - tmp = s.optionals.at(i); | |
242 | - s.optionals.replace(i, item); | |
243 | - s.optionals.replace(index, tmp); | |
267 | + item = s.libraries.at(index); | |
268 | + tmp = s.libraries.at(i); | |
269 | + s.libraries.replace(i, item); | |
270 | + s.libraries.replace(index, tmp); | |
244 | 271 | } |
245 | 272 | |
246 | 273 | return true; |
@@ -255,3 +282,21 @@ | ||
255 | 282 | isAnalyzing = false; |
256 | 283 | _setItemEnabled(); |
257 | 284 | } |
285 | + | |
286 | +bool TranscriberWindow::_checkSettingAvailability() | |
287 | +{ | |
288 | + QDir root(ui->RootDirectory->text()); | |
289 | + for(int i = 0; i < ui->SettingTabs->count(); i++) | |
290 | + { | |
291 | + TranscriberWidget *w = dynamic_cast<TranscriberWidget *>(ui->SettingTabs->widget(i)); | |
292 | + QString relative = root.relativeFilePath(w->dir()); | |
293 | + QString absolute = QDir(relative).absolutePath(); | |
294 | + if(relative == absolute) | |
295 | + { | |
296 | + QMessageBox::critical(this, tr("Error"), tr("Could not create relative path of the library below;\n") + relative); | |
297 | + return false; | |
298 | + } | |
299 | + } | |
300 | + return true; | |
301 | +} | |
302 | + |
@@ -14,7 +14,7 @@ | ||
14 | 14 | { |
15 | 15 | Q_OBJECT |
16 | 16 | public: |
17 | - struct Map | |
17 | + struct Item | |
18 | 18 | { |
19 | 19 | int note; |
20 | 20 | int brightness; |
@@ -27,7 +27,7 @@ | ||
27 | 27 | void paintEvent(QPaintEvent *e); |
28 | 28 | |
29 | 29 | public slots: |
30 | - void setMapping(QVector<stand::gui::MappingView::Map> &mapping); | |
30 | + void setMapping(QVector<stand::gui::MappingView::Item> &mapping); | |
31 | 31 | |
32 | 32 | signals: |
33 | 33 |
@@ -40,7 +40,7 @@ | ||
40 | 40 | }; |
41 | 41 | |
42 | 42 | _color **_map; |
43 | - QVector<Map> _data; | |
43 | + QVector<Item> _data; | |
44 | 44 | const static int _MAPPING_SIZE; |
45 | 45 | }; |
46 | 46 |
@@ -25,14 +25,16 @@ | ||
25 | 25 | Q_OBJECT |
26 | 26 | signals: |
27 | 27 | void sendCancelToTranscriber(); |
28 | - void mappingChanged(QVector<stand::gui::MappingView::Map> &mapping); | |
28 | + void mappingChanged(QVector<stand::gui::MappingView::Item> &mapping); | |
29 | 29 | public slots: |
30 | 30 | void addTab(); |
31 | 31 | void removeTab(); |
32 | 32 | |
33 | 33 | void pushAnalyze(); |
34 | + void pushRootDir(); | |
34 | 35 | void settingChanged(); |
35 | 36 | void transcriptionFinished(bool); |
37 | + | |
36 | 38 | public: |
37 | 39 | explicit TranscriberWindow(QWidget *parent = 0); |
38 | 40 | ~TranscriberWindow(); |
@@ -45,6 +47,7 @@ | ||
45 | 47 | void _setItemEnabled(); |
46 | 48 | |
47 | 49 | bool _createSetting(stand::synthesis::TranscriberSetting &s); |
50 | + bool _checkSettingAvailability(); | |
48 | 51 | |
49 | 52 | Ui::TranscriberWindow *ui; |
50 | 53 | stand::synthesis::Transcriber *current; |
@@ -0,0 +1,4 @@ | ||
1 | +#include "StandLibrary.h" | |
2 | + | |
3 | +using namespace stand::io; | |
4 | + |
@@ -6,7 +6,7 @@ | ||
6 | 6 | |
7 | 7 | using namespace stand::io; |
8 | 8 | |
9 | -const WaveFile::WaveHeader WaveFile::DEFAULT_WAVE_FORMAT = | |
9 | +const WaveFile::Header WaveFile::DEFAULT_WAVE_FORMAT = | |
10 | 10 | { |
11 | 11 | 1, |
12 | 12 | 0, |
@@ -20,7 +20,8 @@ | ||
20 | 20 | |
21 | 21 | bool UtauLibrary::readFromOtoIni(const QString &filename, QTextCodec *codec) |
22 | 22 | { |
23 | - _directory = QDir(filename); | |
23 | + QFileInfo info(filename); | |
24 | + _directory = info.absoluteDir().absolutePath(); | |
24 | 25 | clear(); |
25 | 26 | return _readFromOtoIni(filename, codec); |
26 | 27 | } |
@@ -28,12 +29,12 @@ | ||
28 | 29 | bool UtauLibrary::_readFromOtoIni(const QString &filename, QTextCodec *codec) |
29 | 30 | { |
30 | 31 | QFile file(filename); |
31 | - qDebug("UtauLibrary::readFromOtoIni(%s, %s)", filename, (codec)?(codec->name().data()):"\"\""); | |
32 | + qDebug("UtauLibrary::readFromOtoIni(%s, %s)", filename.toLocal8Bit().data(), (codec)?(codec->name().data()):"\"\""); | |
32 | 33 | |
33 | 34 | // ファイルが存在しない. |
34 | 35 | if(file.exists() == false) |
35 | 36 | { |
36 | - qDebug(" File Not Found :%s", filename); | |
37 | + qDebug(" File Not Found :%s", filename.toLocal8Bit().data()); | |
37 | 38 | return false; |
38 | 39 | } |
39 | 40 |
@@ -40,7 +41,7 @@ | ||
40 | 41 | // 開けない. |
41 | 42 | if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
42 | 43 | { |
43 | - qDebug(" File Open Error :%s", filename); | |
44 | + qDebug(" File Open Error :%s", filename.toLocal8Bit().data()); | |
44 | 45 | return false; |
45 | 46 | } |
46 | 47 |
@@ -51,7 +52,7 @@ | ||
51 | 52 | } |
52 | 53 | |
53 | 54 | QFileInfo fileInfo(filename); |
54 | - QString relative = _directory.relativeFilePath(fileInfo.absoluteDir().absolutePath()) + QDir::separator(); | |
55 | + QString relative = _directory.relativeFilePath(fileInfo.absoluteDir().absolutePath()); | |
55 | 56 | if(relative == QDir::separator()) |
56 | 57 | { |
57 | 58 | relative = ""; |
@@ -68,7 +69,7 @@ | ||
68 | 69 | c++; |
69 | 70 | if(!_readOneLine(line, relative)) |
70 | 71 | { |
71 | - qDebug(" Invalid args in l.%d\t: %s", c, line); | |
72 | + qDebug(" Invalid args in l.%d\t: %s", c, line.toLocal8Bit().data()); | |
72 | 73 | } |
73 | 74 | } |
74 | 75 |
@@ -89,7 +90,7 @@ | ||
89 | 90 | |
90 | 91 | bool UtauLibrary::_readRecursive(const QString &filename, QTextCodec *codec, int maxDepth) |
91 | 92 | { |
92 | - qDebug("UtauLibrary::readRecursive(%s, %s, %d)", filename, (codec)?(codec->name().data()):"\"\"", maxDepth); | |
93 | + qDebug("UtauLibrary::readRecursive(%s, %s, %d)", filename.toLocal8Bit().data(), (codec)?(codec->name().data()):"\"\"", maxDepth); | |
93 | 94 | bool ret = false; |
94 | 95 | QDir dir(filename); |
95 | 96 | QFileInfoList dirList = dir.entryInfoList(QDir::AllDirs); |
@@ -174,11 +175,11 @@ | ||
174 | 175 | |
175 | 176 | const UtauPhoneme *UtauLibrary::find(const QString &pronounce) |
176 | 177 | { |
177 | - QHash<QString, UtauPhoneme *>::iterator it; | |
178 | + QHash<QString, int>::iterator it; | |
178 | 179 | it = settingMap.find(pronounce); |
179 | 180 | if(it != settingMap.end()) |
180 | 181 | { |
181 | - return it.value(); | |
182 | + return at(it.value()); | |
182 | 183 | } |
183 | 184 | return NULL; |
184 | 185 | } |
@@ -0,0 +1,26 @@ | ||
1 | +#ifndef STANDLIBRARY_H | |
2 | +#define STANDLIBRARY_H | |
3 | + | |
4 | +#include <Qt> | |
5 | +#include <QDir> | |
6 | +#include <QVector> | |
7 | + | |
8 | +class QTextCodec; | |
9 | + | |
10 | +namespace stand | |
11 | +{ | |
12 | +namespace io | |
13 | +{ | |
14 | + | |
15 | +class UtauLibrary; | |
16 | + | |
17 | +class StandLibrary | |
18 | +{ | |
19 | +public: | |
20 | + | |
21 | +}; | |
22 | + | |
23 | +} | |
24 | +} | |
25 | + | |
26 | +#endif // STANDLIBRARY_H |
@@ -11,7 +11,7 @@ | ||
11 | 11 | class WaveFile |
12 | 12 | { |
13 | 13 | public: |
14 | - struct WaveHeader | |
14 | + struct Header | |
15 | 15 | { |
16 | 16 | qint16 formatID; |
17 | 17 | qint32 chunksize; |
@@ -31,7 +31,7 @@ | ||
31 | 31 | bool read(const char* filename); |
32 | 32 | bool write(const char* filename); |
33 | 33 | |
34 | - void setHeader(const WaveHeader &h) | |
34 | + void setHeader(const Header &h) | |
35 | 35 | { |
36 | 36 | _header = h; |
37 | 37 | } |
@@ -54,7 +54,7 @@ | ||
54 | 54 | return (!_data || _length == 0); |
55 | 55 | } |
56 | 56 | |
57 | - const WaveHeader *header() const | |
57 | + const Header *header() const | |
58 | 58 | { |
59 | 59 | return &_header; |
60 | 60 | } |
@@ -65,7 +65,7 @@ | ||
65 | 65 | } |
66 | 66 | |
67 | 67 | double normalize(); |
68 | - const static WaveHeader DEFAULT_WAVE_FORMAT; | |
68 | + const static Header DEFAULT_WAVE_FORMAT; | |
69 | 69 | private: |
70 | 70 | void _createBuffer(unsigned int l); |
71 | 71 | void _destroy(); |
@@ -82,7 +82,7 @@ | ||
82 | 82 | void _writeData24(qint8 *p); |
83 | 83 | void _writeData32(qint8 *p); |
84 | 84 | |
85 | - WaveHeader _header; | |
85 | + Header _header; | |
86 | 86 | double *_data; |
87 | 87 | unsigned int _length; |
88 | 88 | }; |
@@ -76,9 +76,8 @@ | ||
76 | 76 | /// <param name = s> 追加したい原音設定 </parm> |
77 | 77 | void push_back(const UtauPhoneme &s) |
78 | 78 | { |
79 | - UtauPhoneme u = s; | |
80 | - settingList.push_back(u); | |
81 | - settingMap.insert(u.pronounce, &(settingList.back())); | |
79 | + settingMap[s.pronounce] = settingList.count(); | |
80 | + settingList.push_back(s); | |
82 | 81 | } |
83 | 82 | |
84 | 83 | /// <summary> 指定発音の原音設定を返します. </summary> |
@@ -92,7 +91,7 @@ | ||
92 | 91 | bool _readRecursive(const QString &filename, QTextCodec *codec = NULL, int maxDepth = 1); |
93 | 92 | |
94 | 93 | QVector<UtauPhoneme> settingList; |
95 | - QHash<QString, UtauPhoneme *> settingMap; | |
94 | + QHash<QString, int> settingMap; | |
96 | 95 | |
97 | 96 | QDir _directory; |
98 | 97 | }; |
@@ -72,6 +72,7 @@ | ||
72 | 72 | |
73 | 73 | bool StandFile::read(const char *path) |
74 | 74 | { |
75 | + qDebug("StandFile::read(\"%s\");", path); | |
75 | 76 | FILE *fp = fopen(path, "rb"); |
76 | 77 | if(!fp) |
77 | 78 | { |
@@ -113,6 +114,7 @@ | ||
113 | 114 | |
114 | 115 | bool StandFile::write(const char *path) |
115 | 116 | { |
117 | + qDebug("StandFile::write(\"%s\");", path); | |
116 | 118 | if(!_f0 || !_t || !_MFCC || !vorbis.data) |
117 | 119 | { |
118 | 120 | qDebug("StandFile::write(\"%s\"); // Empty Data.", path); |
@@ -121,7 +123,7 @@ | ||
121 | 123 | FILE *fp = fopen(path, "wb"); |
122 | 124 | if(!fp) |
123 | 125 | { |
124 | - qDebug("StandFile::write(\"%s\"); // File could not be opened.", path); | |
126 | + qDebug("StandFile::write(\"%s\"); // File open error.", path); | |
125 | 127 | return false; |
126 | 128 | } |
127 | 129 |
@@ -289,17 +291,22 @@ | ||
289 | 291 | stand::math::smoothMatching(dst_to_src_stretched, src_to_dst, src_env, dst_to_src_stretched, src_len); |
290 | 292 | |
291 | 293 | double framePeriod = src->framePeriod(); |
292 | - for( int i = 0; i < dst_len - 1; i++ ){ | |
294 | + for( int i = 0; i < dst_len - 1; i++ ) | |
295 | + { | |
293 | 296 | double tmp = (double)i / (double)dst_len * (double)src_len; |
294 | - if( tmp >= src_len - 1 ){ | |
295 | - dst_to_src[i] = dst_to_src_stretched[src_len-1]; | |
296 | - }else{ | |
297 | + if( tmp >= src_len - 1 ) | |
298 | + { | |
299 | + dst_to_src[i] = dst_to_src_stretched[src_len-1] * dst->framePeriod() / 1000.0 / (double)src_len * (double)dst_len; | |
300 | + } | |
301 | + else | |
302 | + { | |
297 | 303 | dst_to_src[i] = stand::math::interpolateArray(tmp, dst_to_src_stretched) * dst->framePeriod() / 1000.0 / (double)src_len * (double)dst_len; |
298 | 304 | } |
299 | 305 | } |
300 | - dst_to_src[dst_len-1] = dst_to_src_stretched[src_len-1] / (double)src_len * (double)dst_len; | |
306 | + dst_to_src[dst_len-1] = dst_to_src_stretched[src_len-1] * dst->framePeriod() / 1000.0 / (double)src_len * (double)dst_len; | |
301 | 307 | |
302 | - for( int i = 0; i < src_len; i++ ){ | |
308 | + for( int i = 0; i < src_len; i++ ) | |
309 | + { | |
303 | 310 | dst_to_src_stretched[i] = src_to_dst[i] * framePeriod / 1000.0; |
304 | 311 | } |
305 | 312 | memcpy( src_to_dst, dst_to_src_stretched, sizeof( double ) * src_len ); |
@@ -8,15 +8,19 @@ | ||
8 | 8 | Transcriber::Transcriber(const TranscriberSetting *s, QObject *parent) : |
9 | 9 | QThread(parent) |
10 | 10 | { |
11 | - setting = s; | |
11 | + setting = new TranscriberSetting(); | |
12 | + setting->numThreads = s->numThreads; | |
13 | + for(int i = 0; i < s->libraries.size(); i++) | |
14 | + { | |
15 | + setting->libraries.push_back(s->libraries.at(i)); | |
16 | + } | |
12 | 17 | } |
13 | 18 | |
14 | 19 | Transcriber::~Transcriber() |
15 | 20 | { |
16 | - delete setting->base.lib; | |
17 | - for(int i = 0; i < setting->optionals.size();i ++) | |
21 | + for(int i = 0; i < setting->libraries.size();i ++) | |
18 | 22 | { |
19 | - delete setting->optionals.at(i).lib; | |
23 | + delete setting->libraries.at(i).body; | |
20 | 24 | } |
21 | 25 | for(int i = 0; i < elements.size(); i++) |
22 | 26 | { |
@@ -25,6 +29,7 @@ | ||
25 | 29 | elements.at(i)->disconnect(); |
26 | 30 | delete elements.at(i); |
27 | 31 | } |
32 | + delete setting; | |
28 | 33 | } |
29 | 34 | |
30 | 35 | void Transcriber::run() |
@@ -34,7 +39,7 @@ | ||
34 | 39 | QMutex mutex; |
35 | 40 | mutex.lock(); |
36 | 41 | elements.clear(); |
37 | - for(int i = 0; i < setting->numThreads && i < setting->base.lib->size(); i++) | |
42 | + for(int i = 0; i < setting->numThreads && i < setting->libraries.at(0).body->size(); i++) | |
38 | 43 | { |
39 | 44 | TranscriberElement *e = new TranscriberElement(i, setting, &mutex, this); |
40 | 45 | elements.push_back(e); |
@@ -41,9 +46,10 @@ | ||
41 | 46 | e->start(); |
42 | 47 | currentIndex = i; |
43 | 48 | } |
49 | + currentIndex++; | |
44 | 50 | mutex.unlock(); |
45 | 51 | |
46 | - currentIndex = currentFinished = 0; | |
52 | + currentFinished = 0; | |
47 | 53 | waitMutex.lock(); |
48 | 54 | condition.wait(&waitMutex); |
49 | 55 | waitMutex.unlock(); |
@@ -55,7 +61,7 @@ | ||
55 | 61 | void Transcriber::elementFinished(TranscriberElement *e) |
56 | 62 | { |
57 | 63 | currentFinished++; |
58 | - if(currentIndex < setting->base.lib->size()) | |
64 | + if(currentIndex < setting->libraries.at(0).body->size()) | |
59 | 65 | { |
60 | 66 | e->setIndex(currentIndex); |
61 | 67 | currentIndex++; |
@@ -64,14 +70,12 @@ | ||
64 | 70 | { |
65 | 71 | e->finishTranscription(); |
66 | 72 | } |
67 | - // SafeGuard (要るかな?) | |
68 | - if(currentFinished == setting->base.lib->size() - 1) | |
73 | + | |
74 | + if(currentFinished == setting->libraries.at(0).body->size()) | |
69 | 75 | { |
70 | - for(int i = 0; i < setting->numThreads; i++) | |
71 | - { | |
76 | + cancel(); | |
77 | + } | |
72 | 78 | |
73 | - } | |
74 | - } | |
75 | 79 | emit progressChanged(currentFinished); |
76 | 80 | } |
77 | 81 |
@@ -16,8 +16,7 @@ | ||
16 | 16 | class TranscriberSetting |
17 | 17 | { |
18 | 18 | public: |
19 | - Transcriber::TranscriberItem base; | |
20 | - QVector<Transcriber::TranscriberItem> optionals; | |
19 | + QVector<Transcriber::TranscriberItem> libraries; | |
21 | 20 | |
22 | 21 | unsigned int numThreads; |
23 | 22 | }; |
@@ -32,7 +32,7 @@ | ||
32 | 32 | public: |
33 | 33 | struct TranscriberItem |
34 | 34 | { |
35 | - stand::io::UtauLibrary *lib; | |
35 | + stand::io::UtauLibrary *body; | |
36 | 36 | int note; |
37 | 37 | int brightness; |
38 | 38 | }; |
@@ -43,7 +43,7 @@ | ||
43 | 43 | void run(); |
44 | 44 | |
45 | 45 | private: |
46 | - const TranscriberSetting *setting; | |
46 | + TranscriberSetting *setting; | |
47 | 47 | int currentFinished; |
48 | 48 | int currentIndex; |
49 | 49 | QVector<TranscriberElement *> elements; |
@@ -10,8 +10,7 @@ | ||
10 | 10 | |
11 | 11 | using namespace stand::synthesis; |
12 | 12 | |
13 | -TranscriberElement::TranscriberElement(unsigned int index, const TranscriberSetting *s, QMutex *m, Transcriber *t) : | |
14 | - QThread(t) | |
13 | +TranscriberElement::TranscriberElement(unsigned int index, const TranscriberSetting *s, QMutex *m, Transcriber *t) | |
15 | 14 | { |
16 | 15 | this->index = index; |
17 | 16 | this->setting = s; |
@@ -18,10 +17,9 @@ | ||
18 | 17 | this->mutex = m; |
19 | 18 | this->transcriber = t; |
20 | 19 | |
21 | - items.push_back(s->base); | |
22 | - for(int i = 0; i < s->optionals.size(); i++) | |
20 | + for(int i = 0; i < s->libraries.size(); i++) | |
23 | 21 | { |
24 | - items.push_back(s->optionals.at(i)); | |
22 | + items.push_back(s->libraries.at(i)); | |
25 | 23 | } |
26 | 24 | isFinished = false; |
27 | 25 | } |
@@ -42,42 +40,7 @@ | ||
42 | 40 | |
43 | 41 | do |
44 | 42 | { |
45 | - stand::io::StandFile *prev, *current = NULL; | |
46 | - prev = new stand::io::StandFile(); | |
47 | - QString filename = items.at(0).lib->directory().absolutePath() + QDir::separator() + items.at(0).lib->at(index)->filename; | |
48 | - // 簡単だけど拡張子チェック | |
49 | - if(filename.contains(".vvd") && !prev->read(QDir::toNativeSeparators(filename).toLocal8Bit().data())) | |
50 | - { | |
51 | - qDebug("%s is not vvd file!", filename); | |
52 | - delete prev; | |
53 | - prev = NULL; | |
54 | - } | |
55 | - for(int i = 1; i < items.size(); i++) | |
56 | - { | |
57 | - const stand::io::UtauPhoneme *phoneme = items.at(i).lib->find(items.at(0).lib->at(index)->pronounce); | |
58 | - if(phoneme) | |
59 | - { | |
60 | - filename = items.at(i).lib->directory().absolutePath() + QDir::separator() + phoneme->filename; | |
61 | - current = new stand::io::StandFile(); | |
62 | - // 現在のファイルを読み込む→現在のファイルがよめていて,前回もファイルが読めていた場合だけ分析を行う. | |
63 | - if(filename.contains(".vvd") && current->read(QDir::toNativeSeparators(filename).toLocal8Bit().data()) && prev) | |
64 | - { | |
65 | - // ToDo:: 写像関数の計算と保存 | |
66 | - stand::io::StandFile::matching(prev, current); | |
67 | - // ファイルへ保存. | |
68 | - current->write(QDir::toNativeSeparators(filename).toLocal8Bit().data()); | |
69 | - } | |
70 | - else | |
71 | - { | |
72 | - qDebug("%s is not vvd file!", filename); | |
73 | - delete current; | |
74 | - current = NULL; | |
75 | - } | |
76 | - } | |
77 | - delete prev; | |
78 | - prev = current; | |
79 | - } | |
80 | - delete current; | |
43 | + _analyze(); | |
81 | 44 | mutex->lock(); |
82 | 45 | transcriber->elementFinished(this); |
83 | 46 | mutex->unlock(); |
@@ -86,3 +49,40 @@ | ||
86 | 49 | |
87 | 50 | qDebug(" Done::TranscriberElement::run();"); |
88 | 51 | } |
52 | + | |
53 | +void TranscriberElement::_analyze() | |
54 | +{ | |
55 | + stand::io::StandFile *prev, *current = NULL; | |
56 | + prev = new stand::io::StandFile(); | |
57 | + QString filename = items.at(0).body->directory().absolutePath() + QDir::separator() + items.at(0).body->at(index)->filename; | |
58 | + // 簡単だけど拡張子チェック | |
59 | + if(filename.contains(".vvd") && !prev->read(QDir::toNativeSeparators(filename).toLocal8Bit().data())) | |
60 | + { | |
61 | + delete prev; | |
62 | + prev = NULL; | |
63 | + } | |
64 | + for(int i = 1; i < items.size(); i++) | |
65 | + { | |
66 | + const stand::io::UtauPhoneme *phoneme = items.at(i).body->find(items.at(0).body->at(index)->pronounce); | |
67 | + if(phoneme) | |
68 | + { | |
69 | + filename = items.at(i).body->directory().absolutePath() + QDir::separator() + phoneme->filename; | |
70 | + current = new stand::io::StandFile(); | |
71 | + // 現在のファイルを読み込む→現在のファイルがよめていて,前回もファイルが読めていた場合だけ分析を行う. | |
72 | + if(filename.contains(".vvd") && current->read(QDir::toNativeSeparators(filename).toLocal8Bit().data()) && prev) | |
73 | + { | |
74 | + // 写像関数の計算と保存 | |
75 | + stand::io::StandFile::matching(prev, current); | |
76 | + current->write(QDir::toNativeSeparators(filename).toLocal8Bit().data()); | |
77 | + } | |
78 | + else | |
79 | + { | |
80 | + delete current; | |
81 | + current = NULL; | |
82 | + } | |
83 | + } | |
84 | + delete prev; | |
85 | + prev = current; | |
86 | + } | |
87 | + delete current; | |
88 | +} |
@@ -30,6 +30,8 @@ | ||
30 | 30 | void setIndex(int index); |
31 | 31 | void finishTranscription(); |
32 | 32 | private: |
33 | + void _analyze(); | |
34 | + | |
33 | 35 | unsigned int index; |
34 | 36 | const TranscriberSetting *setting; |
35 | 37 | QMutex *mutex; |