Updated sflist preset control to match latest foo_midi, now supports multiple preset commands per group, and channel commands support hyphenated ranges

CQTexperiment
Chris Moeller 2013-10-20 17:30:59 -07:00
parent 2e07cf29a0
commit e930372d1e
2 changed files with 57 additions and 43 deletions

View File

@ -342,6 +342,33 @@ void BMPlayer::shutdown()
_soundFonts.resize( 0 ); _soundFonts.resize( 0 );
} }
void BMPlayer::compound_presets( std::vector<BASS_MIDI_FONTEX> & out, std::vector<BASS_MIDI_FONTEX> & in, std::vector<long> & channels )
{
if ( !in.size() )
in.push_back( { 0, -1, -1, -1, 0, 0 } );
if ( channels.size() )
{
for ( auto pit = in.begin(); pit != in.end(); ++pit )
{
for ( auto it = channels.begin(); it != channels.end(); ++it )
{
bank_lsb_override[ *it - 1 ] = *it;
int dbanklsb = (int) *it;
pit->dbanklsb = dbanklsb;
out.push_back( *pit );
}
}
}
else
{
for ( auto pit = in.begin(); pit != in.end(); ++pit )
{
out.push_back( *pit );
}
}
}
bool BMPlayer::startup() bool BMPlayer::startup()
{ {
if ( _stream ) return true; if ( _stream ) return true;
@ -396,7 +423,7 @@ bool BMPlayer::startup()
cr = strchr( name, '|' ); cr = strchr( name, '|' );
if ( cr ) if ( cr )
{ {
long dbank = 0, dpreset = -1, sbank = -1, spreset = -1; std::vector<BASS_MIDI_FONTEX> nested_presets;
std::vector<long> channels; std::vector<long> channels;
bool valid = true; bool valid = true;
bool pushed_back = true; bool pushed_back = true;
@ -413,8 +440,8 @@ bool BMPlayer::startup()
// patch override - "p[db#,]dp#=[sb#,]sp#" ex. "p0,5=0,1" // patch override - "p[db#,]dp#=[sb#,]sp#" ex. "p0,5=0,1"
// may be used once per preset group // may be used once per preset group
pushed_back = false; pushed_back = false;
dbank = 0; long dbank = 0;
dpreset = strtol( cr, &endchr, 10 ); long dpreset = strtol( cr, &endchr, 10 );
if ( endchr == cr ) if ( endchr == cr )
{ {
valid = false; valid = false;
@ -437,8 +464,8 @@ bool BMPlayer::startup()
break; break;
} }
cr = endchr + 1; cr = endchr + 1;
sbank = -1; long sbank = -1;
spreset = strtol( cr, &endchr, 10 ); long spreset = strtol( cr, &endchr, 10 );
if ( endchr == cr ) if ( endchr == cr )
{ {
valid = false; valid = false;
@ -451,39 +478,51 @@ bool BMPlayer::startup()
spreset = strtol( cr, &endchr, 10 ); spreset = strtol( cr, &endchr, 10 );
if ( endchr == cr ) if ( endchr == cr )
{ {
cr = nameptr - 1; valid = false;
break; break;
} }
} }
if ( *endchr && *endchr != ';' && *endchr != '&' ) if ( *endchr && *endchr != ';' && *endchr != '&' )
{ {
cr = nameptr - 1; valid = false;
break; break;
} }
cr = endchr; cr = endchr;
nested_presets.push_back( { 0, (int) spreset, (int) sbank, (int) dpreset, (int) dbank, 0 } );
} }
break; break;
case 'c': case 'c':
{ {
// channel override - implemented using bank LSB, which is disabled from // channel override - implemented using bank LSB, which is disabled from
// actual use. - format "c#" ex. "c16" (range is 1-48) // actual use. - format "c#[-#]" ex. "c16" (range is 1-48)
// may be used multiple times per preset group // may be used multiple times per preset group
pushed_back = false; pushed_back = false;
long channel = strtol(cr, &endchr, 10); long channel_start = strtol(cr, &endchr, 10);
long channel_end;
if ( endchr == cr ) if ( endchr == cr )
{ {
valid = false; valid = false;
break; break;
} }
if ( channel < 1 || channel > 48 ) if ( channel_start < 1 || channel_start > 48 )
{ {
valid = false; valid = false;
break; break;
} }
channel_end = channel_start;
if ( *endchr == '-' )
{
channel_end = strtol(cr, &endchr, 10);
if ( channel_end <= channel_start || channel_end > 48 )
{
valid = false;
break;
}
}
for ( auto it = channels.begin(); it != channels.end(); ++it ) for ( auto it = channels.begin(); it != channels.end(); ++it )
{ {
if ( *it == channel ) if ( *it >= channel_start || *it <= channel_end )
{ {
valid = false; valid = false;
break; break;
@ -495,7 +534,8 @@ bool BMPlayer::startup()
break; break;
} }
cr = endchr; cr = endchr;
channels.push_back( channel ); for ( long channel = channel_start; channel <= channel_end; ++channel )
channels.push_back( channel );
} }
break; break;
@ -504,21 +544,8 @@ bool BMPlayer::startup()
// separates preset groups per SoundFont bank // separates preset groups per SoundFont bank
if ( !pushed_back ) if ( !pushed_back )
{ {
if ( channels.size() ) compound_presets( presets, nested_presets, channels );
{ nested_presets.clear(); channels.clear();
for ( auto it = channels.begin(); it != channels.end(); ++it )
{
bank_lsb_override[ *it - 1 ] = *it;
int dbanklsb = (int) *it;
presets.push_back( { 0, (int) spreset, (int) sbank, (int) dpreset, (int) dbank, dbanklsb } );
}
}
else
{
presets.push_back( { 0, (int) spreset, (int) sbank, (int) dpreset, (int) dbank, 0 } );
}
sbank = -1; spreset = -1; dpreset = -1; dbank = 0; channels.clear();
pushed_back = true; pushed_back = true;
} }
} }
@ -535,22 +562,7 @@ bool BMPlayer::startup()
} }
} }
if ( !pushed_back && valid ) if ( !pushed_back && valid )
{ compound_presets( presets, nested_presets, channels );
if ( channels.size() )
{
for ( auto it = channels.begin(); it != channels.end(); ++it )
{
bank_lsb_override[ *it - 1 ] = *it;
int dbanklsb = (int) *it;
presets.push_back( { 0, (int) spreset, (int) sbank, (int) dpreset, (int) dbank, dbanklsb } );
}
}
else
{
presets.push_back( { 0, (int) spreset, (int) sbank, (int) dpreset, (int) dbank, 0 } );
}
}
if ( !valid ) if ( !valid )
{ {
presets.clear(); presets.clear();

View File

@ -25,6 +25,8 @@ private:
virtual void shutdown(); virtual void shutdown();
virtual bool startup(); virtual bool startup();
void compound_presets( std::vector<BASS_MIDI_FONTEX> & out, std::vector<BASS_MIDI_FONTEX> & in, std::vector<long> & channels );
void reset_parameters(); void reset_parameters();