• R/O
  • SSH
  • HTTPS

cadencii: コミット


コミットメタ情報

リビジョン1863 (tree)
日時2011-12-05 02:01:48
作者kbinani

ログメッセージ

[luavsq] Sequence: modified; MIDIメタテキストを作成する処理のテストを追加

変更サマリ

差分

--- luavsq/trunk/Sequence.lua (revision 1862)
+++ luavsq/trunk/Sequence.lua (revision 1863)
@@ -220,141 +220,6 @@
220220 end
221221
222222 --
223- -- メタテキストイベントを作成する
224- -- @return (table&lt;<a href="../files/MidiEvent.html">MidiEvent</a>&gt;) メタテキストを格納した MidiEvent の配列
225- -- @name <i>_generateMetaTextEvent</i>
226- function this:_generateMetaTextEvent( ... )
227- local arguments = { ... };
228- if( #arguments == 2 )then
229- return self:_generateMetaTextEvent_2( arguments[1], arguments[2] );
230- elseif( #arguments == 3 )then
231- return self:_generateMetaTextEvent_3( arguments[1], arguments[2], arguments[3] );
232- elseif( #arguments == 4 )then
233- return self:_generateMetaTextEvent_4( arguments[1], arguments[2], arguments[3], arguments[4] );
234- end
235- end
236-
237- --
238- -- メタテキストイベントを作成する
239- -- @param track (integer) トラック番号
240- -- @param encoding (string) マルチバイト文字のテキストエンコーディング(現在は Shift_JIS 固定で、引数は無視される)
241- -- @return (table&lt;<a href="../files/MidiEvent.html">MidiEvent</a>&gt;) メタテキストを格納した <a href="../files/MidiEvent.html">MidiEvent</a> の配列
242- -- @name _generateMetaTextEvent_2
243- function this:_generateMetaTextEvent_2( track, encoding )
244- self:_generateMetaTextEvent_4( track, encoding, self:_calculatePreMeasureInClock(), false );
245- end
246-
247- --
248- -- メタテキストイベントを作成する
249- -- @param track (integer) トラック番号
250- -- @param encoding (string) マルチバイト文字のテキストエンコーディング(現在は Shift_JIS 固定で、引数は無視される)
251- -- @param startClock (integer) イベント作成の開始位置
252- -- @return (table&lt;<a href="../files/MidiEvent.html">MidiEvent</a>&gt;) メタテキストを格納した <a href="../files/MidiEvent.html">MidiEvent</a> の配列
253- -- @name _generateMetaTextEvent_3
254- function this:_generateMetaTextEvent_3( track, encoding, startClock )
255- self:_generateMetaTextEvent_4( track, encoding, startClock, false );
256- end
257-
258- --
259- -- メタテキストイベントを作成する
260- -- @param track (integer) トラック番号
261- -- @param encoding (string) マルチバイト文字のテキストエンコーディング(現在は Shift_JIS 固定で、引数は無視される)
262- -- @param startClock (integer) イベント作成の開始位置
263- -- @param printPitch (boolean) pitch を含めて出力するかどうか(現在は false 固定で、引数は無視される)
264- -- @return (table&lt;<a href="../files/MidiEvent.html">MidiEvent</a>&gt;) メタテキストを格納した MidiEvent の配列
265- -- @name _generateMetaTextEvent_4
266- function this:_generateMetaTextEvent_4( track, encoding, startClock, printPitch )
267- local _NL = string.char( 0x0a );
268- local ret = {};
269- local sr = TextStream.new();
270- self.track:get( track ):printMetaText( sr, self._totalClocks + 120, startClock, printPitch );
271- sr:setPointer( -1 );
272- local line_count = -1;
273- local tmp = "";
274- if( sr:ready() )then
275- local buffer = {};
276- local first = true;
277- while( sr:ready() )do
278- if( first )then
279- tmp = sr:readLine();
280- first = false;
281- else
282- tmp = _NL .. sr:readLine();
283- end
284- local line = CP932Converter.convertFromUTF8( tmp );
285- local linebytes = Util.stringToArray( line );
286- Sequence._array_add_all( buffer, linebytes );
287- local prefix = Sequence._getLinePrefixBytes( line_count + 1 );
288- while( #prefix + #buffer >= 127 )do
289- line_count = line_count + 1;
290- local prefix = Sequence._getLinePrefixBytes( line_count );
291- local add = MidiEvent.new();
292- add.clock = 0;
293- add.firstByte = 0xff;
294- add.data = {};--new int[128];
295- add.data[1] = 0x01;
296- local remain = 127;
297- local i;
298- for i = 1, #prefix, 1 do
299- add.data[i + 1] = prefix[i];
300- end
301- for i = #prefix + 1, remain, 1 do
302- local d = buffer[1];
303- add.data[i + 1] = d;
304- table.remove( buffer, 1 );
305- end
306- table.insert( ret, add );
307- prefix = Sequence._getLinePrefixBytes( line_count + 1 );
308- end
309- end
310- if( #buffer > 0 )then
311- local prefix = Sequence._getLinePrefixBytes( line_count + 1 );
312- while( #prefix + #buffer >= 127 )do
313- line_count = line_count + 1;
314- prefix = Sequence._getLinePrefixBytes( line_count );
315- local add = MidiEvent.new();
316- add.clock = 0;
317- add.firstByte = 0xff;
318- add.data = {};--new int[128];
319- add.data[1] = 0x01;
320- local remain = 127;
321- local i;
322- for i = 1, #prefix, 1 do
323- add.data[i + 1] = prefix[i];
324- end
325- for i = #prefix + 1, remain, 1 do
326- add.data[i + 1] = buffer[1];
327- table.remove( buffer, 1 );
328- end
329- table.insert( ret, add );
330- prefix = Sequence._getLinePrefixBytes( line_count + 1 );
331- end
332- if( #buffer > 0 )then
333- line_count = line_count + 1;
334- local prefix = Sequence._getLinePrefixBytes( line_count );
335- local add = MidiEvent.new();
336- add.clock = 0;
337- add.firstByte = 0xff;
338- local remain = #prefix + #buffer;
339- add.data = {};--new int[remain + 1];
340- add.data[1] = 0x01;
341- local i;
342- for i = 1, #prefix, 1 do
343- add.data[i + 1] = prefix[i];
344- end
345- for i = #prefix + 1, remain, 1 do
346- add.data[i + 1] = buffer[1];
347- table.remove( buffer, 1 );
348- end
349- table.insert( ret, add );
350- end
351- end
352- end
353-
354- return ret;
355- end
356-
357- --
358223 -- 指定した時刻における、プリセンド込の時刻と、ディレイを取得する
359224 -- @param clock (integer) Tick 単位の時刻
360225 -- @param msPreSend (integer) ミリ秒単位のプリセンド時間
@@ -510,6 +375,100 @@
510375 end
511376
512377 --
378+-- 文字列を MIDI メタイベントにしたものを取得する
379+-- @access private
380+-- @param sr (TextStream) MIDI イベント生成元の文字列が出力されたストリーム
381+-- @param encoding (string) マルチバイト文字のテキストエンコーディング(現在は Shift_JIS 固定で、引数は無視される)
382+function Sequence._getMidiEventsFromMetaText( sr, encoding )
383+ local _NL = string.char( 0x0a );
384+ local ret = {};
385+ sr:setPointer( -1 );
386+ local line_count = -1;
387+ local tmp = "";
388+ if( sr:ready() )then
389+ local buffer = {};
390+ local first = true;
391+ while( sr:ready() )do
392+ if( first )then
393+ tmp = sr:readLine();
394+ first = false;
395+ else
396+ tmp = _NL .. sr:readLine();
397+ end
398+ local line = CP932Converter.convertFromUTF8( tmp );
399+ local linebytes = Util.stringToArray( line );
400+ Sequence._array_add_all( buffer, linebytes );
401+ local prefix = Sequence._getLinePrefixBytes( line_count + 1 );
402+ while( #prefix + #buffer >= 127 )do
403+ line_count = line_count + 1;
404+ local prefix = Sequence._getLinePrefixBytes( line_count );
405+ local add = MidiEvent.new();
406+ add.clock = 0;
407+ add.firstByte = 0xff;
408+ add.data = {};--new int[128];
409+ add.data[1] = 0x01;
410+ local remain = 127;
411+ local i;
412+ for i = 1, #prefix, 1 do
413+ add.data[i + 1] = prefix[i];
414+ end
415+ for i = #prefix + 1, remain, 1 do
416+ local d = buffer[1];
417+ add.data[i + 1] = d;
418+ table.remove( buffer, 1 );
419+ end
420+ table.insert( ret, add );
421+ prefix = Sequence._getLinePrefixBytes( line_count + 1 );
422+ end
423+ end
424+ if( #buffer > 0 )then
425+ local prefix = Sequence._getLinePrefixBytes( line_count + 1 );
426+ while( #prefix + #buffer >= 127 )do
427+ line_count = line_count + 1;
428+ prefix = Sequence._getLinePrefixBytes( line_count );
429+ local add = MidiEvent.new();
430+ add.clock = 0;
431+ add.firstByte = 0xff;
432+ add.data = {};--new int[128];
433+ add.data[1] = 0x01;
434+ local remain = 127;
435+ local i;
436+ for i = 1, #prefix, 1 do
437+ add.data[i + 1] = prefix[i];
438+ end
439+ for i = #prefix + 1, remain, 1 do
440+ add.data[i + 1] = buffer[1];
441+ table.remove( buffer, 1 );
442+ end
443+ table.insert( ret, add );
444+ prefix = Sequence._getLinePrefixBytes( line_count + 1 );
445+ end
446+ if( #buffer > 0 )then
447+ line_count = line_count + 1;
448+ local prefix = Sequence._getLinePrefixBytes( line_count );
449+ local add = MidiEvent.new();
450+ add.clock = 0;
451+ add.firstByte = 0xff;
452+ local remain = #prefix + #buffer;
453+ add.data = {};--new int[remain + 1];
454+ add.data[1] = 0x01;
455+ local i;
456+ for i = 1, #prefix, 1 do
457+ add.data[i + 1] = prefix[i];
458+ end
459+ for i = #prefix + 1, remain, 1 do
460+ add.data[i + 1] = buffer[1];
461+ table.remove( buffer, 1 );
462+ end
463+ table.insert( ret, add );
464+ end
465+ end
466+ end
467+
468+ return ret;
469+end
470+
471+--
513472 -- トラックをストリームに出力する
514473 -- @param sequence (<a href="../files/Sequence.html">Sequence</a>) 出力するシーケンス
515474 -- @param track (integer) 出力するトラックの番号
@@ -534,7 +493,9 @@
534493 stream:write( seq_name, 1, #seq_name );
535494
536495 --Meta Textを準備
537- local meta = sequence:_generateMetaTextEvent( track, encoding, 0, printPitch );
496+ local textStream = TextStream.new();
497+ self.track:get( track ):printMetaText( textStream, self._totalClocks + 120, 0, printPitch );
498+ local meta = Sequence._getMidiEventsFromMetaText( track, encoding, 0, printPitch );
538499 local lastClock = 0;
539500 local i;
540501 for i = 1, #meta, 1 do
--- luavsq/trunk/test/SequenceTest.lua (revision 1862)
+++ luavsq/trunk/test/SequenceTest.lua (revision 1863)
@@ -191,12 +191,34 @@
191191 assert_equal( 2400, sequence:getTotalClocks() );
192192 end
193193
194-function test_generateMetaTextEventWithoutPitch()
195- fail();
196-end
194+function test_getMidiEventsFromMetaText()
195+ local stream = luavsq.TextStream.new();
196+ -- 「あ」が Shift_JIS になった時分割される「あ」を Shift_JIS にすると「0x82 0xA0」
197+ stream:write( string.rep( "a", 118 ) .. "あ" );
198+ stream:write( string.rep( "b", 63 ) );
199+ local events = luavsq.Sequence._getMidiEventsFromMetaText( stream, "Shift_JIS" );
200+ assert_equal( 2, #events );
197201
198-function test_generateMetaTextEventWithPitch()
199--- fail();
202+ assert_equal( 0, events[1].clock );
203+ assert_equal( 0xFF, events[1].firstByte );
204+ assert_equal( 128, #events[1].data );
205+ assert_equal( 0x01, events[1].data[1] );
206+ local actual = "";
207+ local i;
208+ for i = 2, #events[1].data, 1 do
209+ actual = actual .. string.char( events[1].data[i] );
210+ end
211+ assert_equal( "DM:0000:" .. string.rep( "a", 118 ) .. string.char( 0x82 ), actual );
212+
213+ assert_equal( 0, events[2].clock );
214+ assert_equal( 0xFF, events[2].firstByte );
215+ assert_equal( 73, #events[2].data );
216+ assert_equal( 0x01, events[2].data[1] );
217+ actual = "";
218+ for i = 2, #events[2].data, 1 do
219+ actual = actual .. string.char( events[2].data[i] );
220+ end
221+ assert_equal( "DM:0001:" .. string.char( 0xA0 ) .. string.rep( "b", 63 ), actual );
200222 end
201223
202224 function test_getActualClockAndDelay()
旧リポジトリブラウザで表示