git-svn-id: http://svn.sourceforge.jp/svnroot/lipsync@8 b1f601f4-4f45-0410-8980-aecacb008692

This commit is contained in:
kbinani
2009-07-29 17:03:20 +00:00
parent 0453ea1636
commit 8ab2a598b3
49 changed files with 3567 additions and 1370 deletions

View File

@@ -61,7 +61,11 @@ namespace Boare.Lib.Vsq {
private static long readDeltaClock( Stream stream ) {
long ret = 0;
while ( true ) {
byte d = (byte)stream.ReadByte();
int i = stream.ReadByte();
if ( i < 0 ) {
break;
}
byte d = (byte)i;
ret = (ret << 7) | ((long)d & 0x7f);
if ( (d & 0x80) == 0x00 ) {
break;
@@ -203,11 +207,8 @@ namespace Boare.Lib.Vsq {
private ushort m_format;
private ushort m_time_format;
public MidiFile( string path )
: this( new FileStream( path, FileMode.Open ) ) {
}
public MidiFile( Stream stream ) {
public MidiFile( string path ){
Stream stream = new FileStream( path, FileMode.Open, FileAccess.Read );
// ヘッダ
byte[] byte4 = new byte[4];
stream.Read( byte4, 0, 4 );
@@ -251,9 +252,66 @@ namespace Boare.Lib.Vsq {
long clock = 0;
byte last_status_byte = 0x00;
while ( stream.Position < startpos + size ) {
m_events[track].Add( MidiEvent.read( stream, ref clock, ref last_status_byte ) );
MidiEvent mi = MidiEvent.read( stream, ref clock, ref last_status_byte );
m_events[track].Add( mi );
}
if ( m_time_format != 480 ) {
int count = m_events[track].Count;
for ( int i = 0; i < count; i++ ) {
MidiEvent mi = m_events[track][i];
mi.Clock = mi.Clock * 480 / m_time_format;
m_events[track][i] = mi;
}
}
}
m_time_format = 480;
#if DEBUG
string dbg = Path.Combine( Path.GetDirectoryName( path ), Path.GetFileNameWithoutExtension( path ) + ".txt" );
using ( StreamWriter sw = new StreamWriter( dbg ) ) {
const string format = " {0,8} 0x{1:X4} {2,-35} 0x{3:X2} 0x{4:X2}";
const string format0 = " {0,8} 0x{1:X4} {2,-35} 0x{3:X2}";
for ( int track = 1; track < m_events.Count; track++ ) {
sw.WriteLine( "MidiFile..ctor; track=" + track );
byte msb, lsb, data_msb, data_lsb;
msb = lsb = data_msb = data_lsb = 0x0;
for ( int i = 0; i < m_events[track].Count; i++ ) {
if ( m_events[track][i].FirstByte == 0xb0 ) {
switch ( m_events[track][i].Data[0] ) {
case 0x63:
msb = m_events[track][i].Data[1];
lsb = 0x0;
break;
case 0x62:
lsb = m_events[track][i].Data[1];
break;
case 0x06:
data_msb = m_events[track][i].Data[1];
ushort nrpn = (ushort)(msb << 8 | lsb);
string name = NRPN.getName( nrpn );
if ( name == "" ) {
name = "* * UNKNOWN * *";
sw.WriteLine( string.Format( format0, m_events[track][i].Clock, nrpn, name, data_msb ) );
} else {
//if ( !NRPN.is_require_data_lsb( nrpn ) ) {
sw.WriteLine( string.Format( format0, m_events[track][i].Clock, nrpn, name, data_msb ) );
//}
}
break;
case 0x26:
data_lsb = m_events[track][i].Data[1];
ushort nrpn2 = (ushort)(msb << 8 | lsb);
string name2 = NRPN.getName( nrpn2 );
if ( name2 == "" ) {
name2 = "* * UNKNOWN * *";
}
sw.WriteLine( string.Format( format, m_events[track][i].Clock, nrpn2, name2, data_msb, data_lsb ) );
break;
}
}
}
}
}
#endif
stream.Close();
}