Sequencer: Fix casting/sign related bug which could cause a hang during SMF writing.
This commit is contained in:
parent
1a07dda5d9
commit
8109ff7bc0
|
@ -20,6 +20,7 @@
|
|||
#include "smf.H"
|
||||
#include "phrase.H"
|
||||
#include "pattern.H"
|
||||
#include <math.h>
|
||||
|
||||
using namespace MIDI;
|
||||
|
||||
|
@ -143,11 +144,11 @@ smf::read_byte ( void )
|
|||
}
|
||||
|
||||
void
|
||||
smf::write_var ( long var )
|
||||
smf::write_var ( unsigned long var )
|
||||
{
|
||||
long buffer;
|
||||
buffer = var & 0x7F;
|
||||
|
||||
unsigned long buffer = var & 0x7F;
|
||||
byte_t buf[4];
|
||||
|
||||
/* we shift it right 7, if there is
|
||||
still set bits, encode into buffer
|
||||
in reverse order */
|
||||
|
@ -157,15 +158,19 @@ smf::write_var ( long var )
|
|||
buffer |= ( var & 0x7F ) | 0x80;
|
||||
}
|
||||
|
||||
for ( ;; )
|
||||
int i = 0;
|
||||
|
||||
while ( i < 4 )
|
||||
{
|
||||
write_byte( buffer );
|
||||
|
||||
buf[i++] = buffer;
|
||||
|
||||
if ( buffer & 0x80 )
|
||||
buffer >>= 8;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
write_bytes( buf, i );
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,15 +187,6 @@ smf::write_long ( unsigned long x )
|
|||
write_bytes( buf, 4 );
|
||||
}
|
||||
|
||||
void
|
||||
smf::write_ascii ( const char *buf )
|
||||
{
|
||||
if ( strlen( buf ) != 4 )
|
||||
ASSERTION( "invalid MIDI value" );
|
||||
|
||||
write_bytes( (void *)buf, 4 );
|
||||
}
|
||||
|
||||
void
|
||||
smf::write_short ( unsigned short x )
|
||||
{
|
||||
|
@ -208,6 +204,15 @@ smf::write_byte ( byte_t b )
|
|||
write_bytes( &b, 1 );
|
||||
}
|
||||
|
||||
void
|
||||
smf::write_ascii ( const char *buf )
|
||||
{
|
||||
if ( strlen( buf ) != 4 )
|
||||
ASSERTION( "invalid MIDI value" );
|
||||
|
||||
write_bytes( (void *)buf, 4 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
smf::write_bytes ( const void *p, size_t l )
|
||||
|
@ -231,7 +236,7 @@ smf::write_event ( const midievent *e )
|
|||
tick_t delta = ts - _time;
|
||||
_time = ts;
|
||||
|
||||
write_var( delta );
|
||||
write_var( floor(delta) );
|
||||
|
||||
if ( _cue && (e->is_note_off() || e->is_note_on() ) )
|
||||
{
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
void read_bytes ( void *p, int l );
|
||||
byte_t read_byte ( void );
|
||||
|
||||
void write_var ( long var );
|
||||
void write_var ( unsigned long var );
|
||||
void write_long ( unsigned long x );
|
||||
void write_ascii ( const char *buf );
|
||||
void write_short ( unsigned short x );
|
||||
|
|
Loading…
Reference in New Issue