Skip to content

Commit

Permalink
add implicit float->int conversion for setParamFloat()
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Nov 21, 2024
1 parent cc2aef7 commit 312d5ea
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/chuck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,19 @@ t_CKBOOL ChucK::setParamFloat( const std::string & name, t_CKFLOAT value )
std::string key = tolower(name);
// check read-only
if( readOnlyParam(key) ) return FALSE;
// check
// check param type
if( m_params.count( key ) > 0 && m_param_types[key] == ck_param_float )
{
// insert into map
m_params[key] = ck_ftoa( value, 32 );
return TRUE;
}
// if param is an int, e.g., sample rate | 1.5.4.2 (ge)
else if( m_params.count( key ) > 0 && m_param_types[key] == ck_param_int )
{
// round and redirect to setParam() as int
return setParam( name, (t_CKINT)(value+.05) );
}
else
{
return FALSE;
Expand Down Expand Up @@ -441,6 +447,11 @@ t_CKFLOAT ChucK::getParamFloat( const std::string & name )
std::istringstream s( m_params[key] );
s >> result;
}
else if( m_params.count( key ) > 0 && m_param_types[key] == ck_param_int )
{
// get int and return as float | 1.5.4.2 (ge)
return (t_CKFLOAT)getParamInt(name);
}
return result;
}

Expand Down

0 comments on commit 312d5ea

Please sign in to comment.