forked from kbinani/libvsq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTempo.hpp
More file actions
140 lines (121 loc) · 3.54 KB
/
Tempo.hpp
File metadata and controls
140 lines (121 loc) · 3.54 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
/**
* Tempo.h
* 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 __Tempo_h__
#define __Tempo_h__
#include "vsqglobal.hpp"
#include <string>
#include <sstream>
VSQ_BEGIN_NAMESPACE
/**
* @brief テンポ情報テーブル内の要素を表現するクラス
*/
class Tempo{
friend class TempoList;
public:
/**
* Tick 単位の時刻
* @var int
*/
tick_t clock;
/**
* テンポ値。四分音符の長さをマイクロ秒単位で表した値
* @var int
*/
int tempo;
protected:
/**
* テンポ変更の秒単位の時刻
* @var double
* @access private
*/
double _time;
public:
/**
* @brief 文字列に変換する
* @return (string) 変換後の文字列
*/
const std::string toString()const {
std::ostringstream oss;
oss << "{Clock=" << clock << ", Tempo=" << tempo << ", Time=" << _time << "}";
return oss.str();
}
/**
* @brief 初期化を行う
* @param clock (int) Tick 単位の時刻
* @param tempo (int) テンポ値。四分音符の長さをマイクロ秒単位で表した値
*/
explicit Tempo( VSQ_NS::tick_t clock, int tempo ){
this->clock = clock;
this->tempo = tempo;
_time = 0.0;
}
explicit Tempo(){
clock = 0;
tempo = 0;
_time = 0.0;
}
/**
* @brief 順序を比較する
* @param entry (Tempo) 比較対象のアイテム
* @return (int) このインスタンスが比較対象よりも小さい場合は負の整数、等しい場合は 0、大きい場合は正の整数を返す
*/
int compareTo( const Tempo &entry )const {
return compareCore( *this, entry );
}
/**
* @brief このオブジェクトのインスタンスと、指定されたオブジェクトが同じかどうかを調べる
* @param entry (Tempo) 比較対象のオブジェクト
* @return (boolean) 比較対象と同じであれば <code>true</code> を、そうでなければ <code>false</code> を返す
*/
bool equals(const Tempo &entry)const {
if( clock == entry.clock ){
return true;
}else{
return false;
}
}
/**
* @brief 秒単位の時刻を取得する
* @return (double) 秒単位の時刻
*/
double getTime()const {
return _time;
}
/**
* @brief コピーを作成する
* @return このオブジェクトのコピー
*/
Tempo clone() const{
Tempo result;
result.clock = clock;
result.tempo = tempo;
result._time = _time;
return result;
}
/**
* @brief 2 つの {@link Tempo} を比較する
* @param a (Tempo) 比較対象のオブジェクト
* @param b (Tempo) 比較対象のオブジェクト
* @return (boolean) <code>a</code> が <code>b</code> よりも小さい場合は <code>true</code>、そうでない場合は <code>false</code> を返す
*/
static bool compare( const Tempo &a, const Tempo &b ){
return compareCore( a, b ) < 0;
}
private:
static int compareCore( const Tempo &a, const Tempo &b ){
return (int)(a.clock - b.clock);
}
};
VSQ_END_NAMESPACE
#endif