[luavsq] TempoTableItem: modified; timeフィールドを_timeに改名し、getterを設置した
@@ -95,13 +95,13 @@ | ||
95 | 95 | elseif( c == 1 )then |
96 | 96 | tempo = self._array[0].tempo; |
97 | 97 | base_clock = self._array[0].clock; |
98 | - base_time = self._array[0].time; | |
98 | + base_time = self._array[0]._time; | |
99 | 99 | else |
100 | 100 | local i; |
101 | 101 | for i = c - 1, 0, -1 do |
102 | 102 | local item = self._array[i]; |
103 | - if( item.time < time )then | |
104 | - return item.clock + (time - item.time) * TempoTable.gatetimePerQuater * 1000000.0 / item.tempo; | |
103 | + if( item._time < time )then | |
104 | + return item.clock + (time - item._time) * TempoTable.gatetimePerQuater * 1000000.0 / item.tempo; | |
105 | 105 | end |
106 | 106 | end |
107 | 107 | end |
@@ -120,11 +120,11 @@ | ||
120 | 120 | self._array:sort( TempoTableItem.compare ); |
121 | 121 | local item0 = self._array[0]; |
122 | 122 | if( item0.clock ~= 0 )then |
123 | - item0.time = TempoTable.baseTempo * item0.clock / (TempoTable.gatetimePerQuater * 1000000.0); | |
123 | + item0._time = TempoTable.baseTempo * item0.clock / (TempoTable.gatetimePerQuater * 1000000.0); | |
124 | 124 | else |
125 | - item0.time = 0.0; | |
125 | + item0._time = 0.0; | |
126 | 126 | end |
127 | - local prev_time = item0.time; | |
127 | + local prev_time = item0._time; | |
128 | 128 | local prev_clock = item0.clock; |
129 | 129 | local prev_tempo = item0.tempo; |
130 | 130 | local inv_tpq_sec = 1.0 / (TempoTable.gatetimePerQuater * 1000000.0); |
@@ -131,8 +131,8 @@ | ||
131 | 131 | local i; |
132 | 132 | for i = 1, c - 1, 1 do |
133 | 133 | local itemi = self._array[i]; |
134 | - itemi.time = prev_time + prev_tempo * (itemi.clock - prev_clock) * inv_tpq_sec; | |
135 | - prev_time = itemi.time; | |
134 | + itemi._time = prev_time + prev_tempo * (itemi.clock - prev_clock) * inv_tpq_sec; | |
135 | + prev_time = itemi._time; | |
136 | 136 | prev_tempo = itemi.tempo; |
137 | 137 | prev_clock = itemi.clock; |
138 | 138 | end |
@@ -149,7 +149,7 @@ | ||
149 | 149 | for i = c - 1, 0, -1 do |
150 | 150 | local item = self._array[i]; |
151 | 151 | if( item.clock < clock )then |
152 | - local init = item.time; | |
152 | + local init = item:getTime(); | |
153 | 153 | local dclock = clock - item.clock; |
154 | 154 | local sec_per_clock1 = item.tempo * 1e-6 / 480.0; |
155 | 155 | return init + dclock * sec_per_clock1; |
@@ -130,7 +130,7 @@ | ||
130 | 130 | assert_equal( 1, sequence.tempoTable:size() ); |
131 | 131 | assert_equal( 0, sequence.tempoTable:get( 0 ).clock ); |
132 | 132 | assert_equal( 500000, sequence.tempoTable:get( 0 ).tempo ); |
133 | - assert_equal( 0.0, sequence.tempoTable:get( 0 ).time ); | |
133 | + assert_equal( 0.0, sequence.tempoTable:get( 0 ):getTime() ); | |
134 | 134 | end |
135 | 135 | |
136 | 136 | function test() |
@@ -16,10 +16,10 @@ | ||
16 | 16 | assert_equal( 2, list:size() ); |
17 | 17 | assert_equal( 0, list:get( 0 ).clock ); |
18 | 18 | assert_equal( 500000, list:get( 0 ).tempo ); |
19 | - assert_equal( 0.0, list:get( 0 ).time ); | |
19 | + assert_equal( 0.0, list:get( 0 ):getTime() ); | |
20 | 20 | assert_equal( 480, list:get( 1 ).clock ); |
21 | 21 | assert_equal( 525000, list:get( 1 ).tempo ); |
22 | - assert_equal( 0.5, list:get( 1 ).time ); | |
22 | + assert_equal( 0.5, list:get( 1 ):getTime() ); | |
23 | 23 | end |
24 | 24 | |
25 | 25 | function testIterator() |
@@ -34,12 +34,12 @@ | ||
34 | 34 | local item = i:next(); |
35 | 35 | assert_equal( 0, item.clock ); |
36 | 36 | assert_equal( 500000, item.tempo ); |
37 | - assert_equal( 0.0, item.time ); | |
37 | + assert_equal( 0.0, item:getTime() ); | |
38 | 38 | assert_true( i:hasNext() ); |
39 | 39 | item = i:next(); |
40 | 40 | assert_equal( 480, item.clock ); |
41 | 41 | assert_equal( 525000, item.tempo ); |
42 | - assert_equal( 0.5, item.time ); | |
42 | + assert_equal( 0.5, item:getTime() ); | |
43 | 43 | assert_false( i:hasNext() ); |
44 | 44 | end |
45 | 45 |
@@ -47,16 +47,16 @@ | ||
47 | 47 | local list = luavsq.TempoTable.new(); |
48 | 48 | list:push( luavsq.TempoTableItem.new( 480, 525000 ) ); |
49 | 49 | list:push( luavsq.TempoTableItem.new( 0, 500000 ) ); |
50 | - list:get( 0 ).time = 0.5; | |
50 | + list:get( 0 )._time = 0.5; | |
51 | 51 | |
52 | 52 | list:sort(); |
53 | 53 | |
54 | 54 | assert_equal( 0, list:get( 0 ).clock ); |
55 | 55 | assert_equal( 500000, list:get( 0 ).tempo ); |
56 | - assert_equal( 0.0, list:get( 0 ).time ); | |
56 | + assert_equal( 0.0, list:get( 0 ):getTime() ); | |
57 | 57 | assert_equal( 480, list:get( 1 ).clock ); |
58 | 58 | assert_equal( 525000, list:get( 1 ).tempo ); |
59 | - assert_equal( 0.5, list:get( 1 ).time ); | |
59 | + assert_equal( 0.5, list:get( 1 ):getTime() ); | |
60 | 60 | end |
61 | 61 | |
62 | 62 | function testClockFromSec() |
@@ -77,7 +77,7 @@ | ||
77 | 77 | assert_equal( 1, list:size() ); |
78 | 78 | assert_equal( 0, list:get( 0 ).clock ); |
79 | 79 | assert_equal( 500000, list:get( 0 ).tempo ); |
80 | - assert_equal( 0.0, list:get( 0 ).time ); | |
80 | + assert_equal( 0.0, list:get( 0 ):getTime() ); | |
81 | 81 | |
82 | 82 | list = luavsq.TempoTable.new(); |
83 | 83 | list:push( luavsq.TempoTableItem.new( 480, 525000 ) ); |
@@ -86,10 +86,10 @@ | ||
86 | 86 | assert_equal( 2, list:size() ); |
87 | 87 | assert_equal( 0, list:get( 0 ).clock ); |
88 | 88 | assert_equal( 500000, list:get( 0 ).tempo ); |
89 | - assert_equal( 0.0, list:get( 0 ).time ); | |
89 | + assert_equal( 0.0, list:get( 0 ):getTime() ); | |
90 | 90 | assert_equal( 480, list:get( 1 ).clock ); |
91 | 91 | assert_equal( 525000, list:get( 1 ).tempo ); |
92 | - assert_equal( 0.5, list:get( 1 ).time ); | |
92 | + assert_equal( 0.5, list:get( 1 ):getTime() ); | |
93 | 93 | end |
94 | 94 | |
95 | 95 | function testGetSecFromClock() |
@@ -6,7 +6,7 @@ | ||
6 | 6 | local entry = luavsq.TempoTableItem.new(); |
7 | 7 | assert_equal( 0, entry.clock ); |
8 | 8 | assert_equal( 0, entry.tempo ); |
9 | - assert_equal( 0.0, entry.time ); | |
9 | + assert_equal( 0.0, entry:getTime() ); | |
10 | 10 | |
11 | 11 | entry = luavsq.TempoTableItem.new( 480, 500000 ); |
12 | 12 | assert_equal( 480, entry.clock ); |
@@ -20,12 +20,12 @@ | ||
20 | 20 | |
21 | 21 | function testClone() |
22 | 22 | local entry = luavsq.TempoTableItem.new( 480, 500000 ); |
23 | - entry.time = 0.5; | |
23 | + entry._time = 0.5; | |
24 | 24 | |
25 | 25 | local copy = entry:clone(); |
26 | 26 | assert_equal( 480, copy.clock ); |
27 | 27 | assert_equal( 500000, copy.tempo ); |
28 | - assert_equal( 0.5, copy.time ); | |
28 | + assert_equal( 0.5, copy:getTime() ); | |
29 | 29 | end |
30 | 30 | |
31 | 31 | function testCompareTo() |
@@ -39,14 +39,14 @@ | ||
39 | 39 | function testEquals() |
40 | 40 | local a = luavsq.TempoTableItem.new( 480, 500000 ); |
41 | 41 | local b = luavsq.TempoTableItem.new( 480, 500000 ); |
42 | - a.time = 0.5; | |
43 | - b.time = 0.5; | |
42 | + a._time = 0.5; | |
43 | + b._time = 0.5; | |
44 | 44 | assert_true( a:equals( b ) ); |
45 | 45 | -- クロックは同じだがtimeが違う |
46 | - b.time = 1; | |
46 | + b._time = 1; | |
47 | 47 | assert_true( a:equals( b ) ); |
48 | 48 | b.clock = 1; |
49 | - b.time = 0.5; | |
49 | + b._time = 0.5; | |
50 | 50 | assert_false( a:equals( b ) ); |
51 | 51 | end |
52 | 52 |
@@ -20,7 +20,6 @@ | ||
20 | 20 | -- @name TempoTableItem |
21 | 21 | -- @field clock (integer) Tick 単位の時刻 |
22 | 22 | -- @field tempo (integer) テンポ値。四分音符の長さをマイクロ秒単位で表した値 |
23 | --- @field time (double) 秒単位の時刻 | |
24 | 23 | TempoTableItem = {}; |
25 | 24 | |
26 | 25 | -- |
@@ -31,7 +30,7 @@ | ||
31 | 30 | local arguments = { ... }; |
32 | 31 | this.clock = 0; |
33 | 32 | this.tempo = 0; |
34 | - this.time = 0.0; | |
33 | + this._time = 0.0; | |
35 | 34 | |
36 | 35 | --- |
37 | 36 | -- 文字列に変換する |
@@ -38,7 +37,7 @@ | ||
38 | 37 | -- @return (string) 変換後の文字列 |
39 | 38 | -- @name toString |
40 | 39 | function this:toString() |
41 | - return "{Clock=" .. self.clock .. ", Tempo=" .. self.tempo .. ", Time=" .. self.time .. "}"; | |
40 | + return "{Clock=" .. self.clock .. ", Tempo=" .. self.tempo .. ", Time=" .. self._time .. "}"; | |
42 | 41 | end |
43 | 42 | |
44 | 43 | --- |
@@ -47,7 +46,7 @@ | ||
47 | 46 | -- @name clone |
48 | 47 | function this:clone() |
49 | 48 | local result = TempoTableItem.new( self.clock, self.tempo ); |
50 | - result.time = self.time; | |
49 | + result._time = self._time; | |
51 | 50 | return result; |
52 | 51 | end |
53 | 52 |
@@ -84,6 +83,14 @@ | ||
84 | 83 | end |
85 | 84 | end |
86 | 85 | |
86 | + --- | |
87 | + -- 秒単位の時刻を取得する | |
88 | + -- @return (double) 秒単位の時刻 | |
89 | + -- @name getTime | |
90 | + function this:getTime() | |
91 | + return self._time; | |
92 | + end | |
93 | + | |
87 | 94 | if( #arguments == 2 )then |
88 | 95 | this:_init_2( arguments[1], arguments[2] ); |
89 | 96 | end |