• R/O
  • SSH
  • HTTPS

cadencii: コミット


コミットメタ情報

リビジョン1764 (tree)
日時2011-11-10 22:03:17
作者kbinani

ログメッセージ

[luavsq] メタテキストのCommonの処理周りを移植

変更サマリ

差分

--- luavsq/trunk/test/PlayModeTest.lua (nonexistent)
+++ luavsq/trunk/test/PlayModeTest.lua (revision 1764)
@@ -0,0 +1,9 @@
1+require( "lunit" );
2+dofile( "../PlayMode.lua" );
3+module( "enhanced", package.seeall, lunit.testcase );
4+
5+function test()
6+ assert_equal( -1, luavsq.PlayMode.Off );
7+ assert_equal( 0, luavsq.PlayMode.PlayAfterSynth );
8+ assert_equal( 1, luavsq.PlayMode.PlayWithSynth );
9+end
--- luavsq/trunk/test/DynamicsModeTest.lua (nonexistent)
+++ luavsq/trunk/test/DynamicsModeTest.lua (revision 1764)
@@ -0,0 +1,8 @@
1+require( "lunit" );
2+dofile( "../DynamicsMode.lua" );
3+module( "enhanced", package.seeall, lunit.testcase );
4+
5+function test()
6+ assert_equal( 0, luavsq.DynamicsMode.Standard );
7+ assert_equal( 1, luavsq.DynamicsMode.Expert );
8+end
--- luavsq/trunk/test/UtilTest.lua (revision 1763)
+++ luavsq/trunk/test/UtilTest.lua (revision 1764)
@@ -34,3 +34,13 @@
3434 assert_equal( -1, luavsq.Util.searchArray( array, "A" ) );
3535 assert_equal( -1, luavsq.Util.searchArray( nil, "a" ) );
3636 end
37+
38+function testMakeUInt16BE()
39+ local bytes = { 0x12, 0x34 };
40+ assert_equal( 0x1234, luavsq.Util.makeUInt16BE( bytes ) );
41+end
42+
43+function testMakeUInt32BE()
44+ local bytes = { 0x12, 0x34, 0x56, 0x78 };
45+ assert_equal( 0x12345678, luavsq.Util.makeUInt32BE( bytes ) );
46+end
--- luavsq/trunk/test/VibratoBPListTest.lua (revision 1763)
+++ luavsq/trunk/test/VibratoBPListTest.lua (revision 1764)
@@ -47,7 +47,7 @@
4747
4848 function testSetElement()
4949 local list = luavsq.VibratoBPList.new( { 0.0, 0.4, 1.0 }, { 1, 64, 128 } );
50- list:setElement( 1, luavsq.VibratoBPPair.new( 0.2, 32 ) );
50+ list:setElement( 1, luavsq.VibratoBP.new( 0.2, 32 ) );
5151 assert_equal( 0.2, list:getElement( 1 ).x );
5252 assert_equal( 32, list:getElement( 1 ).y );
5353 end
--- luavsq/trunk/test/VibratoBPTest.lua (revision 1763)
+++ luavsq/trunk/test/VibratoBPTest.lua (revision 1764)
@@ -4,33 +4,33 @@
44 module( "enhanced", package.seeall, lunit.testcase );
55
66 function testConstruct()
7- local point = luavsq.VibratoBPPair.new();
7+ local point = luavsq.VibratoBP.new();
88 assert_equal( 0.0, point.x );
99 assert_equal( 0, point.y );
1010 end
1111
1212 function testConstructWithCoordinate()
13- local point = luavsq.VibratoBPPair.new( 2.0, 3 );
13+ local point = luavsq.VibratoBP.new( 2.0, 3 );
1414 assert_equal( 2, point.x );
1515 assert_equal( 3, point.y );
1616 end
1717
1818 function testCompareTo()
19- local a = luavsq.VibratoBPPair.new( 2.0, 3 );
20- local b = luavsq.VibratoBPPair.new( 2.0, 10 );
19+ local a = luavsq.VibratoBP.new( 2.0, 3 );
20+ local b = luavsq.VibratoBP.new( 2.0, 10 );
2121 assert_equal( 0, a:compareTo( b ) );
2222
23- local c = luavsq.VibratoBPPair.new( 1.0, 3 );
23+ local c = luavsq.VibratoBP.new( 1.0, 3 );
2424 assert_equal( 1, b:compareTo( c ) );
2525 assert_equal( -1, c:compareTo( b ) );
2626 end
2727
2828 function testCompare()
29- local a = luavsq.VibratoBPPair.new( 2.0, 3 );
30- local b = luavsq.VibratoBPPair.new( 2.0, 10 );
31- assert_equal( 0, luavsq.VibratoBPPair.compare( a, b ) );
29+ local a = luavsq.VibratoBP.new( 2.0, 3 );
30+ local b = luavsq.VibratoBP.new( 2.0, 10 );
31+ assert_equal( 0, luavsq.VibratoBP.compare( a, b ) );
3232
33- local c = luavsq.VibratoBPPair.new( 1.0, 3 );
34- assert_equal( 1, luavsq.VibratoBPPair.compare( b, c ) );
35- assert_equal( -1, luavsq.VibratoBPPair.compare( c, b ) );
33+ local c = luavsq.VibratoBP.new( 1.0, 3 );
34+ assert_equal( 1, luavsq.VibratoBP.compare( b, c ) );
35+ assert_equal( -1, luavsq.VibratoBP.compare( c, b ) );
3636 end
--- luavsq/trunk/test/CommonTest.lua (nonexistent)
+++ luavsq/trunk/test/CommonTest.lua (revision 1764)
@@ -0,0 +1,55 @@
1+require( "lunit" );
2+dofile( "../Common.lua" );
3+dofile( "../TextStream.lua" );
4+dofile( "../DynamicsMode.lua" );
5+dofile( "../PlayMode.lua" );
6+dofile( "../Util.lua" );
7+module( "enhanced", package.seeall, lunit.testcase );
8+
9+function testConstructFromStream()
10+ local stream = luavsq.TextStream.new();
11+ stream:writeLine( "Version=DSB303" );
12+ stream:writeLine( "Name=Foo" );
13+ stream:writeLine( "Color=1,2,3" );
14+ stream:writeLine( "DynamicsMode=1" );
15+ stream:writeLine( "PlayMode=1" );
16+ stream:setPointer( -1 );
17+ local lastLine = { value = "" };
18+ local common = luavsq.Common.new( stream, lastLine );
19+ assert_equal( "DSB303", common.version );
20+ assert_equal( "Foo", common.name );
21+ assert_equal( "1,2,3", common.color );
22+ assert_equal( luavsq.DynamicsMode.Expert, common.dynamicsMode );
23+ assert_equal( luavsq.PlayMode.PlayWithSynth, common.playMode );
24+end
25+
26+function testConstructFromArguments()
27+ local common = luavsq.Common.new( "__foo__", 3, 4, 5, luavsq.DynamicsMode.Standard, luavsq.PlayMode.PlayAfterSynth );
28+ assert_equal( "__foo__", common.name );
29+ assert_equal( "3,4,5", common.color );
30+ assert_equal( luavsq.DynamicsMode.Standard, common.dynamicsMode );
31+ assert_equal( luavsq.PlayMode.PlayAfterSynth, common.playMode );
32+end
33+
34+function testClone()
35+ local common = luavsq.Common.new( "__foo__", 3, 4, 5, luavsq.DynamicsMode.Standard, luavsq.PlayMode.PlayAfterSynth );
36+ local copy = common:clone();
37+ assert_equal( "__foo__", copy.name );
38+ assert_equal( "3,4,5", copy.color );
39+ assert_equal( luavsq.DynamicsMode.Standard, copy.dynamicsMode );
40+ assert_equal( luavsq.PlayMode.PlayAfterSynth, copy.playMode );
41+end
42+
43+function testWrite()
44+ local common = luavsq.Common.new( "__foo__", 3, 4, 5, luavsq.DynamicsMode.Standard, luavsq.PlayMode.PlayAfterSynth );
45+ local stream = luavsq.TextStream.new();
46+ common:write( stream );
47+ local expected =
48+ "[Common]\n" ..
49+ "Version=DSB301\n" ..
50+ "Name=__foo__\n" ..
51+ "Color=3,4,5\n" ..
52+ "DynamicsMode=0\n" ..
53+ "PlayMode=0\n";
54+ assert_equal( expected, stream:toString() );
55+end
--- luavsq/trunk/PlayMode.lua (nonexistent)
+++ luavsq/trunk/PlayMode.lua (revision 1764)
@@ -0,0 +1,35 @@
1+--[[
2+ PlayMode.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 GPLv3 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.PlayMode )then
20+
21+ luavsq.PlayMode = {};
22+
23+ ---
24+ -- トラックはミュートされる.(-1)
25+ luavsq.PlayMode.Off = -1;
26+
27+ ---
28+ -- トラックは合成された後再生される(0)
29+ luavsq.PlayMode.PlayAfterSynth = 0;
30+
31+ ---
32+ -- トラックは合成しながら再生される(1)
33+ luavsq.PlayMode.PlayWithSynth = 1;
34+
35+end
--- luavsq/trunk/DynamicsMode.lua (nonexistent)
+++ luavsq/trunk/DynamicsMode.lua (revision 1764)
@@ -0,0 +1,33 @@
1+--[[
2+ DynamicsMode.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 GPLv3 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.DynamicsMode )then
20+
21+ ---
22+ -- VOCALOID1における、ダイナミクスモードを表す定数を格納するためのクラスです。
23+ luavsq.DynamicsMode = {};
24+
25+ ---
26+ -- デフォルトのダイナミクスモードです。DYNカーブが非表示になるモードです。
27+ luavsq.DynamicsMode.Standard = 0;
28+
29+ ---
30+ -- エキスパートモードです。DYNカーブが表示されます。
31+ luavsq.DynamicsMode.Expert = 1;
32+
33+end
--- luavsq/trunk/Util.lua (revision 1763)
+++ luavsq/trunk/Util.lua (revision 1764)
@@ -71,4 +71,18 @@
7171 end
7272 return -1;
7373 end
74+
75+ ---
76+ -- @param bytes (table<number>)
77+ -- @return number
78+ function luavsq.Util.makeUInt16BE( bytes )
79+ return bytes[1] * 0x100 + bytes[2];
80+ end
81+
82+ ---
83+ -- @param bytes (table<number>)
84+ -- @return number
85+ function luavsq.Util.makeUInt32BE( bytes )
86+ return bytes[1] * 0x1000000 + bytes[2] * 0x10000 + bytes[3] * 0x100 + bytes[4];
87+ end
7488 end
--- luavsq/trunk/VibratoBPList.lua (revision 1763)
+++ luavsq/trunk/VibratoBPList.lua (revision 1764)
@@ -13,7 +13,7 @@
1313 ]]
1414
1515 -- requires( Util.lua )
16--- requires( VibratoBPPair.lua )
16+-- requires( VibratoBP.lua )
1717
1818 if( nil == luavsq )then
1919 luavsq = {};
@@ -50,7 +50,7 @@
5050
5151 local len = math.min( #x, #y );
5252 for i = 1, len, 1 do
53- self._list[i] = luavsq.VibratoBPPair.new( x[i], y[i] );
53+ self._list[i] = luavsq.VibratoBP.new( x[i], y[i] );
5454 end
5555 table.sort( self._list, luavsq.VibratoBPList._comparator );
5656 end
@@ -62,7 +62,7 @@
6262 function this:_init_2( x, y )
6363 local len = math.min( #x, #y );
6464 for i = 1, len, 1 do
65- self._list[i] = luavsq.VibratoBPPair.new( x[i], y[i] );
65+ self._list[i] = luavsq.VibratoBP.new( x[i], y[i] );
6666 end
6767 local comparator = function( a, b )
6868 if( a:compareTo( b ) < 0 )then
@@ -101,7 +101,7 @@
101101 function this:clone()
102102 local ret = luavsq.VibratoBPList.new();
103103 for i = 1, #self._list, 1 do
104- ret._list[i] = luavsq.VibratoBPPair.new( self._list[i].x, self._list[i].y );
104+ ret._list[i] = luavsq.VibratoBP.new( self._list[i].x, self._list[i].y );
105105 end
106106 return ret;
107107 end
@@ -114,7 +114,7 @@
114114
115115 ---
116116 -- @param index (integer) 0から始まるインデックス
117- -- @return (luavsq.VibratoBPPair)
117+ -- @return (luavsq.VibratoBP)
118118 function this:getElement( index )
119119 return self._list[index + 1];
120120 end
@@ -121,7 +121,7 @@
121121
122122 ---
123123 -- @param index (integer) 0から始まるインデックス
124- -- @param value (luavsq.VibratoBPPair)
124+ -- @param value (luavsq.VibratoBP)
125125 function this:setElement( index, value )
126126 self._list[index + 1] = value;
127127 end
@@ -149,7 +149,7 @@
149149 for i = 1, #spl, 1 do
150150 local spl2 = luavsq.Util.split( spl[i], '=' );
151151 if( #spl2 >= 2 )then
152- self._list[j] = luavsq.VibratoBPPair.new( tonumber( spl2[1] ), tonumber( spl2[2] ) );
152+ self._list[j] = luavsq.VibratoBP.new( tonumber( spl2[1] ), tonumber( spl2[2] ) );
153153 j = j + 1
154154 end
155155 end
@@ -166,8 +166,8 @@
166166 end
167167
168168 ---
169- -- @param a (luavsq.VibratoBPPair)
170- -- @param b (luavsq.VibratoBPPair)
169+ -- @param a (luavsq.VibratoBP)
170+ -- @param b (luavsq.VibratoBP)
171171 function luavsq.VibratoBPList._comparator( a, b )
172172 if( a:compareTo( b ) < 0 )then
173173 return true;
--- luavsq/trunk/VibratoBP.lua (revision 1763)
+++ luavsq/trunk/VibratoBP.lua (revision 1764)
@@ -1,5 +1,5 @@
11 --[[
2- VibratoBPPair.lua
2+ VibratoBP.lua
33 Copyright © 2011 kbinani
44
55 This file is part of luavsq.
@@ -16,11 +16,11 @@
1616 luavsq = {};
1717 end
1818
19-if( nil == luavsq.VibratoBPPair )then
19+if( nil == luavsq.VibratoBP )then
2020
21- luavsq.VibratoBPPair = {};
21+ luavsq.VibratoBP = {};
2222
23- function luavsq.VibratoBPPair.new( ... )
23+ function luavsq.VibratoBP.new( ... )
2424 local arguments = { ... };
2525 local this = {};
2626 this.x = 0.0;
@@ -31,8 +31,8 @@
3131 end
3232
3333 ---
34- -- この VibratoBPPair のインスタンスと、引数で指定されたインスタンスを比較する
35- -- @param item (luavsq.VibratoBPPair)
34+ -- この VibratoBP のインスタンスと、引数で指定されたインスタンスを比較する
35+ -- @param item (luavsq.VibratoBP)
3636 -- @return (integer)
3737 function this:compareTo( item )
3838 local v = self.x - item.x;
@@ -50,10 +50,10 @@
5050 ---
5151 -- 引数で与えられた 2 つのインスタンスの順序比較し、第 1 引数のものが第 2 引数のものより大きければ 1 を返す。
5252 -- 小さければ -1 を返す。同順であれば 0 を返す。
53- -- @param a (luavsq.VibratoBPPair)
54- -- @param b (luavsq.VibratoBPPair)
53+ -- @param a (luavsq.VibratoBP)
54+ -- @param b (luavsq.VibratoBP)
5555 -- @return (integer)
56- function luavsq.VibratoBPPair.compare( a, b )
56+ function luavsq.VibratoBP.compare( a, b )
5757 return a:compareTo( b );
5858 end
5959
--- luavsq/trunk/Common.lua (nonexistent)
+++ luavsq/trunk/Common.lua (revision 1764)
@@ -0,0 +1,126 @@
1+--[[
2+ Common.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+ org.kbinani.vsq 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.Common )then
20+
21+ ---
22+ -- vsqファイルのメタテキストの[Common]セクションに記録される内容を取り扱う
23+ luavsq.Common = {};
24+
25+ ---
26+ -- overload1
27+ -- @param text_stream [TextStream]
28+ -- @param last_line [ByRef<String>]
29+ --
30+ -- overload2
31+ -- @param name [String]
32+ -- @param red [int]
33+ -- @param green [int]
34+ -- @param blue [int]
35+ -- @param dynamics_mode [int]
36+ -- @param play_mode [int]
37+ function luavsq.Common.new( ... )
38+ local this = {};
39+ local arguments = { ... };
40+ this.version = "DSB301";
41+ this.name = "Miku";
42+ this.color = "179,181,123";
43+
44+ -- Dynamicsカーブを表示するモード(Expert)なら1、しない(Standard)なら0。
45+ this.dynamicsMode = luavsq.DynamicsMode.Expert;
46+
47+ -- Play With Synthesisなら1、Play After Synthesiなら0、Offなら-1。
48+ this.playMode = luavsq.PlayMode.PlayWithSynth;
49+
50+ -- PlayModeがOff(-1)にされる直前に,PlayAfterSynthかPlayWithSynthのどちらが指定されていたかを記憶しておく.
51+ this.lastPlayMode = luavsq.PlayMode.PlayWithSynth;
52+
53+ ---
54+ -- @param sr [TextStream]
55+ -- @param last_line [ByRef<string>]
56+ -- @return [void]
57+ function this:_init_2( sr, last_line )
58+ self.version = "";
59+ self.name = "";
60+ self.color = "0,0,0";
61+ self.dynamicsMode = 0;
62+ self.playMode = 1;
63+ last_line.value = sr:readLine();
64+ while( last_line.value:sub( 1, 1 ) ~= "[" )do
65+ local spl = luavsq.Util.split( last_line.value, "=" );
66+ local search = spl[1];
67+ if( search == "Version" )then
68+ self.version = spl[2];
69+ elseif( search == "Name" )then
70+ self.name = spl[2];
71+ elseif( search == "Color" )then
72+ self.color = spl[2];
73+ elseif( search == "DynamicsMode" )then
74+ self.dynamicsMode = tonumber( spl[2], 10 );
75+ elseif( search == "PlayMode" )then
76+ self.playMode = tonumber( spl[2], 10 );
77+ end
78+ if( not sr:ready() )then
79+ break;
80+ end
81+ last_line.value = sr:readLine();
82+ end
83+ end
84+
85+ function this:_init_6( name, r, g, b, dynamicsMode, playMode )
86+ self.version = "DSB301";
87+ self.name = name;
88+ self.color = r .. "," .. g .. "," .. b;
89+ self.dynamicsMode = dynamicsMode;
90+ self.playMode = playMode;
91+ end
92+
93+ function this:clone()
94+ local spl = luavsq.Util.split( self.color, "," );
95+ local r = tonumber( spl[1], 10 );
96+ local g = tonumber( spl[2], 10 );
97+ local b = tonumber( spl[3], 10 );
98+ local res = luavsq.Common.new( self.name, r, g, b, self.dynamicsMode, self.playMode );
99+ res.version = self.version;
100+ res.lastPlayMode = self.lastPlayMode;
101+ return res;
102+ end
103+
104+ ---
105+ -- インスタンスの内容をテキストファイルに出力します
106+ -- @param sw [ITextWriter] 出力先
107+ -- @return [void]
108+ function this:write( sw )
109+ sw:writeLine( "[Common]" );
110+ sw:writeLine( "Version=" .. self.version );
111+ sw:writeLine( "Name=" .. self.name );
112+ sw:writeLine( "Color=" .. self.color );
113+ sw:writeLine( "DynamicsMode=" .. self.dynamicsMode );
114+ sw:writeLine( "PlayMode=" .. self.playMode );
115+ end
116+
117+ if( #arguments == 2 )then
118+ this:_init_2( arguments[1], arguments[2] );
119+ elseif( #arguments == 6 )then
120+ this:_init_6( arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6] );
121+ end
122+
123+ return this;
124+ end
125+
126+end
旧リポジトリブラウザで表示