forked from kbinani/libvsq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaster.hpp
More file actions
89 lines (79 loc) · 2.32 KB
/
Master.hpp
File metadata and controls
89 lines (79 loc) · 2.32 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
/**
* Master.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 __Master_hpp__
#define __Master_hpp__
#include "vsqglobal.hpp"
#include "TextStream.hpp"
#include "StringUtil.hpp"
#include <vector>
#include <sstream>
VSQ_BEGIN_NAMESPACE
/**
* @brief VSQ ファイルのメタテキストの [Master] に記録される内容を取り扱うクラス
*/
class Master{
public:
/**
* @brief プリメジャーの長さ(小節数)
*/
int preMeasure;
explicit Master(){
this->preMeasure = 1;
}
/**
* @brief プリメジャーを指定し、初期化を行う
* @param preMeasure プリメジャーの長さ(小節数)
*/
explicit Master( int preMeasure ){
this->preMeasure = preMeasure;
}
/**
* @brief テキストストリームから読み込むことで初期化を行う
* @param stream 読み込むテキストストリーム
* @param lastLine 読み込んだ最後の行。
*/
explicit Master( TextStream &stream, std::string &lastLine ){
this->preMeasure = 0;
lastLine = stream.readLine();
while( lastLine.find( "[" ) == std::string::npos ){
std::vector<std::string> spl = StringUtil::explode( "=", lastLine );
if( spl[0] == "PreMeasure" ){
this->preMeasure = StringUtil::parseInt<int>( spl[1] );
}
if( !stream.ready() ){
break;
}
lastLine = stream.readLine();
}
}
/**
* @brief コピーを作成する
* @return このオブジェクトのコピー
*/
Master clone() const{
return Master( this->preMeasure );
}
/**
* @brief テキストストリームに出力する
* @param stream (TextStream) 出力先
*/
void write( TextStream &stream ) const{
stream.writeLine( "[Master]" );
std::ostringstream oss;
oss << "PreMeasure=" << this->preMeasure;
stream.writeLine( oss.str() );
}
};
VSQ_END_NAMESPACE
#endif