Fix #5483: sf2_player: No crash when file is no soundfont (#5487)

This commit is contained in:
Johannes Lorenz
2020-05-21 22:45:01 +02:00
committed by GitHub
parent 29a5abc30b
commit 109cdf6cf3

View File

@@ -358,18 +358,24 @@ void sf2Instrument::openFile( const QString & _sf2File, bool updateTrackName )
// Add to map, if doesn't exist.
else
{
m_fontId = fluid_synth_sfload( m_synth, sf2Ascii, true );
bool loaded = false;
if( fluid_is_soundfont( sf2Ascii ) )
{
m_fontId = fluid_synth_sfload( m_synth, sf2Ascii, true );
if( fluid_synth_sfcount( m_synth ) > 0 )
{
// Grab this sf from the top of the stack and add to list
m_font = new sf2Font( fluid_synth_get_sfont( m_synth, 0 ) );
s_fonts.insert( relativePath, m_font );
if( fluid_synth_sfcount( m_synth ) > 0 )
{
// Grab this sf from the top of the stack and add to list
m_font = new sf2Font( fluid_synth_get_sfont( m_synth, 0 ) );
s_fonts.insert( relativePath, m_font );
loaded = true;
}
}
else
if(!loaded)
{
collectErrorForUI( sf2Instrument::tr( "A soundfont %1 could not be loaded." ).arg( QFileInfo( _sf2File ).baseName() ) );
// TODO: Why is the filename missing when the file does not exist?
collectErrorForUI( sf2Instrument::tr( "A soundfont %1 could not be loaded." ).
arg( QFileInfo( _sf2File ).baseName() ) );
}
}