Exemple #1
0
bool midi_processor::is_riff_midi( std::vector<uint8_t> const& p_file )
{
    if ( p_file.size() < 20 ) return false;
    if ( p_file[ 0 ] != 'R' || p_file[ 1 ] != 'I' || p_file[ 2 ] != 'F' || p_file[ 3 ] != 'F' ) return false;
    uint32_t riff_size = p_file[ 4 ] | ( p_file[ 5 ] << 8 ) | ( p_file[ 6 ] << 16 ) | ( p_file[ 7 ] << 24 );
    if ( riff_size < 12 || ( p_file.size() < riff_size + 8 ) ) return false;
    if ( p_file[ 8 ] != 'R' || p_file[ 9 ] != 'M' || p_file[ 10 ] != 'I' || p_file[ 11 ] != 'D' ||
         p_file[ 12 ] != 'd' || p_file[ 13 ] != 'a' || p_file[ 14 ] != 't' || p_file[ 15 ] != 'a' ) return false;
    uint32_t data_size = p_file[ 16 ] | ( p_file[ 17 ] << 8 ) | ( p_file[ 18 ] << 16 ) | ( p_file[ 19 ] << 24 );
    if ( data_size < 18 || p_file.size() < data_size + 20 || riff_size < data_size + 12 ) return false;
    std::vector<uint8_t> test;
    test.assign( p_file.begin() + 20, p_file.begin() + 20 + 18 );
    return is_standard_midi( test );
}
bool midi_processor::process_file( std::vector<uint8_t> const& p_file, const char * p_extension, midi_container & p_out )
{
    if ( is_standard_midi( p_file ) )
	{
        return process_standard_midi( p_file, p_out );
	}
    else if ( is_riff_midi( p_file ) )
	{
        return process_riff_midi( p_file, p_out );
	}
    else if ( is_hmp( p_file ) )
	{
        return process_hmp( p_file, p_out );
    }
    else if ( is_hmi( p_file ) )
	{
        return process_hmi( p_file, p_out );
    }
    else if ( is_xmi( p_file ) )
	{
        return process_xmi( p_file, p_out );
    }
    else if ( is_mus( p_file ) )
	{
        return process_mus( p_file, p_out );
    }
    else if ( is_mids( p_file ) )
	{
        return process_mids( p_file, p_out );
    }
    else if ( is_lds( p_file, p_extension ) )
	{
        return process_lds( p_file, p_out );
    }
    else if ( is_gmf( p_file ) )
	{
        return process_gmf( p_file, p_out );
    }
    else return false;
}