forked from kbinani/libvsq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.hpp
More file actions
198 lines (178 loc) · 5.61 KB
/
Common.hpp
File metadata and controls
198 lines (178 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* Common.hpp
* Copyright © 2012 kbinani
*
* This file is part of libvsq.
*
* libvsq is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* libvsq is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __Common_hpp__
#define __Common_hpp__
#include "vsqglobal.hpp"
#include <string>
#include <vector>
#include "DynamicsMode.hpp"
#include "PlayMode.hpp"
#include "TextStream.hpp"
#include "StringUtil.hpp"
VSQ_BEGIN_NAMESPACE
/**
* @brief VSQ ファイルのメタテキストの [Common] セクションに記録される内容を格納するクラス
*/
class Common{
public:
/**
* @brief トラックの歌声合成エンジンのバージョンを表す文字列
*/
std::string version;// = "DSB301";
/**
* @brief トラックの名前
*/
std::string name;// = "Miku";
/**
* @brief ダイナミクスモード
*/
DynamicsMode::DynamicsModeEnum dynamicsMode;// = DynamicsMode::EXPERT;
/**
* @brief (Unknown)
*/
std::string color;
protected:
/**
* @brief Play mode.
*/
PlayMode::PlayModeEnum _playMode;
private:
/**
* @brief Previous play mode before play mode is set to OFF.
*/
PlayMode::PlayModeEnum _lastPlayMode;
public:
/**
* @brief 初期化を行う
*/
explicit Common(){
init();
}
/**
* @brief 初期化を行う
* @param stream 読み込み元のテキストストリーム
* @param lastLine 読み込んだ最後の行。テーブルの ["value"] に文字列が格納される
* @todo VSQFileReaderに移動する
*/
explicit Common( TextStream &stream, std::string &lastLine ){
init();
this->version = "";
this->name = "";
this->color = "0,0,0";
this->dynamicsMode = DynamicsMode::STANDARD;
this->_playMode = PlayMode::PLAY_WITH_SYNTH;
lastLine = stream.readLine();
while( lastLine.find( "[" ) != 0 ){
std::vector<std::string> spl = StringUtil::explode( "=", lastLine );
std::string search = spl[0];
if( search == "Version" ){
this->version = spl[1];
}else if( search == "Name" ){
this->name = spl[1];
}else if( search == "Color" ){
this->color = spl[1];
}else if( search == "DynamicsMode" ){
this->dynamicsMode = (DynamicsMode::DynamicsModeEnum)StringUtil::parseInt<int>( spl[1] );
}else if( search == "PlayMode" ){
this->_playMode = (PlayMode::PlayModeEnum)StringUtil::parseInt<int>( spl[1] );
}
if( !stream.ready() ){
break;
}
lastLine = stream.readLine();
}
}
/**
* @brief 初期化を行う
* @param name トラック名
* @param r 赤(意味は不明)
* @param g 緑(意味は不明)
* @param b 青(意味は不明)
* @param dynamicsMode シーケンスの Dynamics モード
* @param playMode シーケンスの Play モード
*/
explicit Common( std::string name, int r, int g, int b, DynamicsMode::DynamicsModeEnum dynamicsMode, PlayMode::PlayModeEnum playMode ){
init();
this->version = "DSB301";
this->name = name;
ostringstream oss;
oss << r << "," << g << "," << b;
this->color = oss.str();
this->dynamicsMode = dynamicsMode;
this->_playMode = playMode;
}
/**
* @brief コピーを作成する
* @return このインスタンスのコピー
*/
Common clone() const{
std::vector<std::string> spl = StringUtil::explode( ",", this->color );
int r = StringUtil::parseInt<int>( spl[0] );
int g = StringUtil::parseInt<int>( spl[1] );
int b = StringUtil::parseInt<int>( spl[2] );
Common result( this->name, r, g, b, this->dynamicsMode, this->_playMode );
result.version = this->version;
result._lastPlayMode = this->_lastPlayMode;
return result;
}
/**
* @brief Get play mode.
*/
PlayMode::PlayModeEnum playMode()const {
return _playMode;
}
/**
* @brief Set play mode.
*/
void setPlayMode(PlayMode::PlayModeEnum mode) {
_playMode = mode;
if (mode != PlayMode::OFF) {
_lastPlayMode = mode;
}
}
/**
* @brief Get previous play mode before play mode is set to OFF.
*/
PlayMode::PlayModeEnum lastPlayMode()const {
return _lastPlayMode;
}
/**
* @brief テキストストリームに出力する
* @param stream (TextStream) 出力先のストリーム
* @todo VSQFileWriterに移動する
*/
void write( TextStream &stream ) const{
stream.writeLine( "[Common]" );
stream.writeLine( "Version=" + this->version );
stream.writeLine( "Name=" + this->name );
stream.writeLine( "Color=" + this->color );
ostringstream oss;
oss << "DynamicsMode=" << (int)this->dynamicsMode;
stream.writeLine( oss.str() );
oss.str( "" );
oss << "PlayMode=" << (int)this->_playMode;
stream.writeLine( oss.str() );
}
private:
void init(){
this->version = "DSB301";
this->name = "Miku";
this->dynamicsMode = DynamicsMode::EXPERT;
this->_playMode = PlayMode::PLAY_WITH_SYNTH;
this->color = "179,181,123";
this->_lastPlayMode = PlayMode::PLAY_WITH_SYNTH;
}
};
VSQ_END_NAMESPACE
#endif