[luavsq] 拍子とテンポ情報を格納するクラスを移植
@@ -0,0 +1,13 @@ | ||
1 | +require( "lunit" ); | |
2 | +dofile( "../Timesig.lua" ); | |
3 | +module( "enhanced", package.seeall, lunit.testcase ); | |
4 | + | |
5 | +function testConstructor() | |
6 | + local timesig = luavsq.Timesig.new(); | |
7 | + assert_equal( 0, timesig.numerator ); | |
8 | + assert_equal( 0, timesig.denominator ); | |
9 | + | |
10 | + timesig = luavsq.Timesig.new( 3, 4 ); | |
11 | + assert_equal( 3, timesig.numerator ); | |
12 | + assert_equal( 4, timesig.denominator ); | |
13 | +end |
@@ -0,0 +1,56 @@ | ||
1 | +require( "lunit" ); | |
2 | +dofile( "../TempoTableEntry.lua" ); | |
3 | +module( "enhanced", package.seeall, lunit.testcase ); | |
4 | + | |
5 | +function testConstructor() | |
6 | + local entry = luavsq.TempoTableEntry.new(); | |
7 | + assert_equal( 0, entry.clock ); | |
8 | + assert_equal( 0, entry.tempo ); | |
9 | + assert_equal( 0.0, entry.time ); | |
10 | + | |
11 | + entry = luavsq.TempoTableEntry.new( 480, 500000, 0.5 ); | |
12 | + assert_equal( 480, entry.clock ); | |
13 | + assert_equal( 500000, entry.tempo ); | |
14 | + assert_equal( 0.5, entry.time ); | |
15 | +end | |
16 | + | |
17 | +function testToString() | |
18 | + local entry = luavsq.TempoTableEntry.new( 480, 500000, 0.5 ); | |
19 | + assert_equal( "{Clock=480, Tempo=500000, Time=0.5}", entry:toString() ); | |
20 | +end | |
21 | + | |
22 | +function testClone() | |
23 | + local entry = luavsq.TempoTableEntry.new( 480, 500000, 0.5 ); | |
24 | + local copy = entry:clone(); | |
25 | + assert_equal( 480, copy.clock ); | |
26 | + assert_equal( 500000, copy.tempo ); | |
27 | + assert_equal( 0.5, copy.time ); | |
28 | +end | |
29 | + | |
30 | +function testCompareTo() | |
31 | + local a = luavsq.TempoTableEntry.new(); | |
32 | + local b = luavsq.TempoTableEntry.new( 480, 500000, 0.5 ); | |
33 | + assert_true( 0 < b:compareTo( a ) ); | |
34 | + assert_equal( 0, a:compareTo( a ) ); | |
35 | + assert_true( 0 > a:compareTo( b ) ); | |
36 | +end | |
37 | + | |
38 | +function testEquals() | |
39 | + local a = luavsq.TempoTableEntry.new( 480, 500000, 0.5 ); | |
40 | + local b = luavsq.TempoTableEntry.new( 480, 500000, 0.5 ); | |
41 | + assert_true( a:equals( b ) ); | |
42 | + -- クロックは同じだがtimeが違う | |
43 | + b.time = 1; | |
44 | + assert_true( a:equals( b ) ); | |
45 | + b.clock = 1; | |
46 | + b.time = 0.5; | |
47 | + assert_false( a:equals( b ) ); | |
48 | +end | |
49 | + | |
50 | +function testCompare() | |
51 | + local a = luavsq.TempoTableEntry.new(); | |
52 | + local b = luavsq.TempoTableEntry.new( 480, 500000, 0.5 ); | |
53 | + assert_true( 0 < luavsq.TempoTableEntry.compare( b, a ) ); | |
54 | + assert_equal( 0, luavsq.TempoTableEntry.compare( a, a ) ); | |
55 | + assert_true( 0 > luavsq.TempoTableEntry.compare( a, b ) ); | |
56 | +end |
@@ -0,0 +1,63 @@ | ||
1 | +require( "lunit" ); | |
2 | +dofile( "../TimesigTableEntry.lua" ); | |
3 | +module( "enhanced", package.seeall, lunit.testcase ); | |
4 | + | |
5 | +function testConstruct() | |
6 | + local item = luavsq.TimesigTableEntry.new(); | |
7 | + assert_equal( 0, item.clock ); | |
8 | + assert_equal( 4, item.numerator ); | |
9 | + assert_equal( 4, item.denominator ); | |
10 | + assert_equal( 0, item.barCount ); | |
11 | + | |
12 | + item = luavsq.TimesigTableEntry.new( 480, 3, 4, 1 ); | |
13 | + assert_equal( 480, item.clock ); | |
14 | + assert_equal( 3, item.numerator ); | |
15 | + assert_equal( 4, item.denominator ); | |
16 | + assert_equal( 1, item.barCount ); | |
17 | +end | |
18 | + | |
19 | +function testToString() | |
20 | + local item = luavsq.TimesigTableEntry.new( 480, 3, 4, 1 ); | |
21 | + assert_equal( "{Clock=480, Numerator=3, Denominator=4, BarCount=1}", item:toString() ); | |
22 | +end | |
23 | + | |
24 | +function testClone() | |
25 | + local item = luavsq.TimesigTableEntry.new( 480, 3, 4, 1 ); | |
26 | + local copy = item:clone(); | |
27 | + assert_equal( 480, copy.clock ); | |
28 | + assert_equal( 3, copy.numerator ); | |
29 | + assert_equal( 4, copy.denominator ); | |
30 | + assert_equal( 1, copy.barCount ); | |
31 | +end | |
32 | + | |
33 | +function testCompareTo() | |
34 | + local a = luavsq.TimesigTableEntry.new( 480, 3, 4, 1 ); | |
35 | + local b = luavsq.TimesigTableEntry.new( 480, 3, 4, 1 ); | |
36 | + assert_equal( 0, a:compareTo( b ) ); | |
37 | + | |
38 | + -- barCount が異なる | |
39 | + a.barCount = 2; | |
40 | + assert_true( 0 < a:compareTo( b ) ); | |
41 | + assert_true( 0 > b:compareTo( a ) ); | |
42 | + | |
43 | + -- barCount が同じだが、他が異なる | |
44 | + a.barCount = 1; | |
45 | + a.clock = 1; | |
46 | + assert_equal( 0, a:compareTo( b ) ); | |
47 | +end | |
48 | + | |
49 | +function testCompare() | |
50 | + local a = luavsq.TimesigTableEntry.new( 480, 3, 4, 1 ); | |
51 | + local b = luavsq.TimesigTableEntry.new( 480, 3, 4, 1 ); | |
52 | + assert_equal( 0, luavsq.TimesigTableEntry.compare( a, b ) ); | |
53 | + | |
54 | + -- barCount が異なる | |
55 | + a.barCount = 2; | |
56 | + assert_true( 0 < luavsq.TimesigTableEntry.compare( a, b ) ); | |
57 | + assert_true( 0 > luavsq.TimesigTableEntry.compare( b, a ) ); | |
58 | + | |
59 | + -- barCount が同じだが、他が異なる | |
60 | + a.barCount = 1; | |
61 | + a.clock = 1; | |
62 | + assert_equal( 0, luavsq.TimesigTableEntry.compare( a, b ) ); | |
63 | +end |
@@ -8,7 +8,7 @@ | ||
8 | 8 | dofile( "../VibratoHandle.lua" ); |
9 | 9 | dofile( "../IconParameter.lua" ); |
10 | 10 | dofile( "../VibratoBPList.lua" ); |
11 | -dofile( "../NoteHeadhandle.lua" ); | |
11 | +dofile( "../NoteHeadHandle.lua" ); | |
12 | 12 | dofile( "../IconDynamicsHandle.lua" ); |
13 | 13 | dofile( "../Util.lua" ); |
14 | 14 | module( "enhanced", package.seeall, lunit.testcase ); |
@@ -0,0 +1,45 @@ | ||
1 | +--[[ | |
2 | + Timesig.lua | |
3 | + Copyright © 2011 kbinani | |
4 | + | |
5 | + This file is part of luavsq. | |
6 | + | |
7 | + luavsq is free software; you can redistribute it and/or | |
8 | + modify it under the terms of the BSD License. | |
9 | + | |
10 | + luavsq is distributed in the hope that it will be useful, | |
11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
13 | +]] | |
14 | + | |
15 | +if( nil == luavsq )then | |
16 | + luavsq = {}; | |
17 | +end | |
18 | + | |
19 | +if( nil == luavsq.Timesig )then | |
20 | + | |
21 | + luavsq.Timesig = {}; | |
22 | + | |
23 | + function luavsq.Timesig.new( ... ) | |
24 | + local this = {}; | |
25 | + local arguments = { ... }; | |
26 | + this.numerator = 0; | |
27 | + this.denominator = 0; | |
28 | + | |
29 | + --- | |
30 | + -- @param numerator [int] | |
31 | + -- @param denominator [int] | |
32 | + -- @return [void] | |
33 | + function this:_init_2( numerator, denominator ) | |
34 | + self.numerator = numerator; | |
35 | + self.denominator = denominator; | |
36 | + end | |
37 | + | |
38 | + if( #arguments == 2 )then | |
39 | + this:_init_2( arguments[1], arguments[2] ); | |
40 | + end | |
41 | + | |
42 | + return this; | |
43 | + end | |
44 | + | |
45 | +end |
@@ -0,0 +1,90 @@ | ||
1 | +--[[ | |
2 | + TempoTableEntry.lua | |
3 | + Copyright © 2011 kbinani | |
4 | + | |
5 | + This file is part of luavsq. | |
6 | + | |
7 | + luavsq is free software; you can redistribute it and/or | |
8 | + modify it under the terms of the BSD License. | |
9 | + | |
10 | + luavsq is distributed in the hope that it will be useful, | |
11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
13 | +]] | |
14 | + | |
15 | +if( nil == luavsq )then | |
16 | + luavsq = {}; | |
17 | +end | |
18 | + | |
19 | +if( nil == luavsq.TempoTableEntry )then | |
20 | + | |
21 | + luavsq.TempoTableEntry = {}; | |
22 | + | |
23 | + function luavsq.TempoTableEntry.new( ... ) | |
24 | + local this = {}; | |
25 | + local arguments = { ... }; | |
26 | + this.clock = 0; | |
27 | + this.tempo = 0; | |
28 | + this.time = 0.0; | |
29 | + | |
30 | + --- | |
31 | + -- @return [string] | |
32 | + function this:toString() | |
33 | + return "{Clock=" .. self.clock .. ", Tempo=" .. self.tempo .. ", Time=" .. self.time .. "}"; | |
34 | + end | |
35 | + | |
36 | + --- | |
37 | + -- @return [object] | |
38 | + function this:clone() | |
39 | + return luavsq.TempoTableEntry.new( self.clock, self.tempo, self.time ); | |
40 | + end | |
41 | + | |
42 | + --- | |
43 | + -- overload1 | |
44 | + -- @return [TempoTableEntry] | |
45 | + -- | |
46 | + -- overload2 | |
47 | + -- @param clock [int] | |
48 | + -- @param _tempo [int] | |
49 | + -- @param _time [int] | |
50 | + -- @return [TempoTableEntry] | |
51 | + function this:_init_3( clock, tempo, time ) | |
52 | + self.clock = clock; | |
53 | + self.tempo = tempo; | |
54 | + self.time = time; | |
55 | + end | |
56 | + | |
57 | + --- | |
58 | + -- @param entry [TempoTableEntry] | |
59 | + -- @return [int] | |
60 | + function this:compareTo( entry ) | |
61 | + return self.clock - entry.clock; | |
62 | + end | |
63 | + | |
64 | + --- | |
65 | + -- @param entry [TempoTableEntry] | |
66 | + -- @return [bool] | |
67 | + function this:equals( entry ) | |
68 | + if( self.clock == entry.clock )then | |
69 | + return true; | |
70 | + else | |
71 | + return false; | |
72 | + end | |
73 | + end | |
74 | + | |
75 | + if( #arguments == 3 )then | |
76 | + this:_init_3( arguments[1], arguments[2], arguments[3] ); | |
77 | + end | |
78 | + | |
79 | + return this; | |
80 | + end | |
81 | + | |
82 | + --- | |
83 | + -- @param a [TempoTableEntry] | |
84 | + -- @param b [TempoTableEntry] | |
85 | + -- @return [int] | |
86 | + function luavsq.TempoTableEntry.compare( a, b ) | |
87 | + return a:compareTo( b ); | |
88 | + end | |
89 | + | |
90 | +end |
@@ -0,0 +1,90 @@ | ||
1 | +--[[ | |
2 | + TimesigTableEntry.lua | |
3 | + Copyright © 2011 kbinani | |
4 | + | |
5 | + This file is part of luavsq. | |
6 | + | |
7 | + luavsq is free software; you can redistribute it and/or | |
8 | + modify it under the terms of the BSD License. | |
9 | + | |
10 | + luavsq is distributed in the hope that it will be useful, | |
11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
13 | +]] | |
14 | + | |
15 | +if( nil == luavsq )then | |
16 | + luavsq = {}; | |
17 | +end | |
18 | + | |
19 | +if( nil == luavsq.TimesigTableEntry )then | |
20 | + | |
21 | + luavsq.TimesigTableEntry = {}; | |
22 | + | |
23 | + function luavsq.TimesigTableEntry.new( ... ) | |
24 | + local this = {}; | |
25 | + local arguments = { ... }; | |
26 | + | |
27 | + --- | |
28 | + -- クロック数 | |
29 | + this.clock = 0; | |
30 | + | |
31 | + --- | |
32 | + -- 拍子の分子 | |
33 | + this.numerator = 4; | |
34 | + | |
35 | + --- | |
36 | + -- 拍子の分母 | |
37 | + this.denominator = 4; | |
38 | + | |
39 | + --- | |
40 | + -- 何小節目か | |
41 | + this.barCount = 0; | |
42 | + | |
43 | + --- | |
44 | + -- @param clock [int] | |
45 | + -- @param numerator [int] | |
46 | + -- @param denominator [int] | |
47 | + -- @param bar_count [int] | |
48 | + -- @return [TimeSigTableEntry] | |
49 | + function this:_init_4( clock, numerator, denominator, barCount ) | |
50 | + self.clock = clock; | |
51 | + self.numerator = numerator; | |
52 | + self.denominator = denominator; | |
53 | + self.barCount = barCount; | |
54 | + end | |
55 | + | |
56 | + --- | |
57 | + -- @return [string] | |
58 | + function this:toString() | |
59 | + return "{Clock=" .. self.clock .. ", Numerator=" .. self.numerator .. ", Denominator=" .. self.denominator .. ", BarCount=" .. self.barCount .. "}"; | |
60 | + end | |
61 | + | |
62 | + --- | |
63 | + -- @return [object] | |
64 | + function this:clone() | |
65 | + return luavsq.TimesigTableEntry.new( self.clock, self.numerator, self.denominator, self.barCount ); | |
66 | + end | |
67 | + | |
68 | + --- | |
69 | + -- @param item [TimeSigTableEntry] | |
70 | + -- @return [int] | |
71 | + function this:compareTo( item ) | |
72 | + return self.barCount - item.barCount; | |
73 | + end | |
74 | + | |
75 | + if( #arguments == 4 )then | |
76 | + this:_init_4( arguments[1], arguments[2], arguments[3], arguments[4] ); | |
77 | + end | |
78 | + | |
79 | + return this; | |
80 | + end | |
81 | + | |
82 | + --- | |
83 | + -- @param a [TimeSigTableEntry] | |
84 | + -- @param b [TimeSigTableEntry] | |
85 | + -- @return [int] | |
86 | + function luavsq.TimesigTableEntry.compare( a, b ) | |
87 | + return a:compareTo( b ); | |
88 | + end | |
89 | + | |
90 | +end |