projects/effects/effects.cpp
// The processMessage() function encapsulates the handling of control
// messages.  It can be easily relocated within a program structure
// depending on the desired scheduling scheme.
The processMessage() function encapsulates the handling of control
messages.  It can be easily relocated within a program structure
depending on the desired scheduling scheme.
The processMessage () function encapsulates the handling of control messages . It can be easily relocated within a program structure depending on the desired scheduling scheme .
void processMessage( TickData* data )
{
  register unsigned int value1 = data->message.intValues[0];
  register StkFloat value2 = data->message.floatValues[1];
  register StkFloat temp = value2 * ONE_OVER_128;
  switch( data->message.type ) {
  case __SK_Exit_:
    if ( data->settling == false ) goto settle;
    done = true;
    return;
  case __SK_NoteOn_:
    std::cout << "note on\n";
    if ( value2 == 0.0 ) 
      data->envelope.setTarget( 0.0 );
    else 
      data->envelope.setTarget( 1.0 );
    break;
  case __SK_NoteOff_:
    std::cout << "note off\n";
    data->envelope.setTarget( 0.0 );
    break;
  case __SK_ControlChange_:
    switch ( value1 ) {
    case 20: { 
      std::cout << "effect type change\n";
      int type = data->message.intValues[1];
      data->effectId = (unsigned int) type;
      break;
    }
    case 22: 
      std::cout << "effect param 1 change\n";
      data->echo.setDelay( (unsigned long) (temp * Stk::sampleRate() * 0.95) );
      data->lshifter.setShift( 1.4 * temp + 0.3 );
      data->shifter.setShift( 1.4 * temp + 0.3 );
      data->chorus.setModFrequency( temp );
      data->prcrev.setT60( temp * 10.0 );
      data->jcrev.setT60( temp * 10.0 );
      data->nrev.setT60( temp * 10.0 );
      data->frev.setDamping( temp );
      break;
    case 23: 
      std::cout << "effect param 2 change\n";
      data->chorus.setModDepth( temp * 0.2 );
      data->frev.setRoomSize( temp );
      break;
    case 44: 
      std::cout << "effect mix change\n";
      data->echo.setEffectMix( temp );
      data->shifter.setEffectMix( temp );
      data->lshifter.setEffectMix( temp );
      data->chorus.setEffectMix( temp );
      data->prcrev.setEffectMix( temp );
      data->jcrev.setEffectMix( temp );
      data->nrev.setEffectMix( temp );
      data->frev.setEffectMix( temp );
      break;
    default:
      break;
    }
  } 
  data->haveMessage = false;
  return;
 settle:
  data->envelope.setTarget( 0.0 );
  data->counter = (int) (0.3 * data->t60 * Stk::sampleRate());
  data->settling = true;
}
void processMessage ( TickData * data ) { register unsigned int value1 = data -> message . intValues [ 0 ] ; register StkFloat value2 = data -> message . floatValues [ 1 ] ; register StkFloat temp = value2 * ONE_OVER_128 ; switch ( data -> message . type ) { case __SK_Exit_ : if ( data -> settling == false ) goto settle ; done = true ; return ; case __SK_NoteOn_ : std :: cout << " \n " ; if ( value2 == 0.0 ) data -> envelope . setTarget ( 0.0 ) ; else data -> envelope . setTarget ( 1.0 ) ; break ; case __SK_NoteOff_ : std :: cout << " \n " ; data -> envelope . setTarget ( 0.0 ) ; break ; case __SK_ControlChange_ : switch ( value1 ) { case 20 : { std :: cout << " \n " ; int type = data -> message . intValues [ 1 ] ; data -> effectId = ( unsigned int ) type ; break ; } case 22 : std :: cout << " \n " ; data -> echo . setDelay ( ( unsigned long ) ( temp * Stk :: sampleRate ( ) * 0.95 ) ) ; data -> lshifter . setShift ( 1.4 * temp + 0.3 ) ; data -> shifter . setShift ( 1.4 * temp + 0.3 ) ; data -> chorus . setModFrequency ( temp ) ; data -> prcrev . setT60 ( temp * 10.0 ) ; data -> jcrev . setT60 ( temp * 10.0 ) ; data -> nrev . setT60 ( temp * 10.0 ) ; data -> frev . setDamping ( temp ) ; break ; case 23 : std :: cout << " \n " ; data -> chorus . setModDepth ( temp * 0.2 ) ; data -> frev . setRoomSize ( temp ) ; break ; case 44 : std :: cout << " \n " ; data -> echo . setEffectMix ( temp ) ; data -> shifter . setEffectMix ( temp ) ; data -> lshifter . setEffectMix ( temp ) ; data -> chorus . setEffectMix ( temp ) ; data -> prcrev . setEffectMix ( temp ) ; data -> jcrev . setEffectMix ( temp ) ; data -> nrev . setEffectMix ( temp ) ; data -> frev . setEffectMix ( temp ) ; break ; default : break ; } } data -> haveMessage = false ; return ; settle : data -> envelope . setTarget ( 0.0 ) ; data -> counter = ( int ) ( 0.3 * data -> t60 * Stk :: sampleRate ( ) ) ; data -> settling = true ; }
The processMessage() function encapsulates the handling of control
messages.
The processMessage () function encapsulates the handling of control messages .
// velocity is zero ... really a NoteOff // a NoteOn // Change all effect values so they are "synched" to the interface. // effect type change // effect parameter change 1 // effect parameter change 2 // effect mix // end of type switch // Exit and program change messages are preceeded with a short settling period.