Changeset 562

Show
Ignore:
Timestamp:
10/15/08 00:00:41 (2 months ago)
Author:
smoors
Message:

added actions to control panning via midi

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/midiAutosense/libs/hydrogen/src/action.cpp

    r559 r562  
    8484        << "STRIP_VOLUME_RELATIVE" 
    8585        << "STRIP_VOLUME_ABSOLUTE" 
     86        << "PAN_RELATIVE" 
     87        << "PAN_ABSOULTE" 
    8688        << "BEATCOUNTER" 
    8789        << "TAP_TEMPO"; 
     
    225227 
    226228                if( vol_param != 0 ){ 
    227                                 if ( vol_param == 1){ 
     229                                if ( vol_param == 1 && instr->get_volume() < 1.5 ){ 
    228230                                        instr->set_volume( instr->get_volume() + 0.1 );   
    229                                 } else { 
    230                                         instr->set_volume( instr->get_volume() - 0.1 ); 
     231                                }  else  { 
     232                                        if( instr->get_volume() >= 0.0 ){ 
     233                                                instr->set_volume( instr->get_volume() - 0.1 ); 
     234                                        } 
    231235                                } 
    232236                } else { 
     
    261265 
    262266                Hydrogen::get_instance()->setSelectedInstrumentNumber(nLine); 
     267        } 
     268 
     269         
     270        if( sActionString == "PAN_ABSOULTE" ){ 
     271                /* 
     272                 * sets the absolute panning of a given mixer channel 
     273                */ 
     274                 
     275                bool ok; 
     276                int nLine = pAction->getParameter1().toInt(&ok,10); 
     277                int pan_param = pAction->getParameter2().toInt(&ok,10); 
     278 
     279                 
     280                float pan_L; 
     281                float pan_R; 
     282 
     283                Hydrogen *engine = Hydrogen::get_instance(); 
     284                engine->setSelectedInstrumentNumber( nLine ); 
     285                Song *song = engine->getSong(); 
     286                InstrumentList *instrList = song->get_instrument_list(); 
     287 
     288                Instrument *instr = instrList->get( nLine ); 
     289                 
     290                if( instr == NULL ) 
     291                        return false; 
     292                 
     293                pan_L = instr->get_pan_l(); 
     294                pan_R = instr->get_pan_r(); 
     295 
     296                // pan 
     297                float fPanValue = 0.0; 
     298                if (pan_R == 1.0) { 
     299                        fPanValue = 1.0 - (pan_L / 2.0); 
     300                } 
     301                else { 
     302                        fPanValue = pan_R / 2.0; 
     303                } 
     304 
     305                 
     306                fPanValue = 1 * ( ((float) pan_param) / 127.0 ); 
     307 
     308 
     309                if (fPanValue >= 0.5) { 
     310                        pan_L = (1.0 - fPanValue) * 2; 
     311                        pan_R = 1.0; 
     312                } 
     313                else { 
     314                        pan_L = 1.0; 
     315                        pan_R = fPanValue * 2; 
     316                } 
     317 
     318 
     319                instr->set_pan_l( pan_L ); 
     320                instr->set_pan_r( pan_R ); 
     321 
     322                Hydrogen::get_instance()->setSelectedInstrumentNumber(nLine); 
     323 
     324                return true; 
     325        } 
     326 
     327        if( sActionString == "PAN_RELATIVE" ){ 
     328                /* 
     329                 * changes the panning of a given mixer channel 
     330                 * this is useful if the panning is set by a rotary control knob 
     331                */ 
     332                 
     333                bool ok; 
     334                int nLine = pAction->getParameter1().toInt(&ok,10); 
     335                int pan_param = pAction->getParameter2().toInt(&ok,10); 
     336 
     337                 
     338                float pan_L; 
     339                float pan_R; 
     340 
     341                Hydrogen *engine = Hydrogen::get_instance(); 
     342                engine->setSelectedInstrumentNumber( nLine ); 
     343                Song *song = engine->getSong(); 
     344                InstrumentList *instrList = song->get_instrument_list(); 
     345 
     346                Instrument *instr = instrList->get( nLine ); 
     347                 
     348                if( instr == NULL ) 
     349                        return false; 
     350                 
     351                pan_L = instr->get_pan_l(); 
     352                pan_R = instr->get_pan_r(); 
     353 
     354                // pan 
     355                float fPanValue = 0.0; 
     356                if (pan_R == 1.0) { 
     357                        fPanValue = 1.0 - (pan_L / 2.0); 
     358                } 
     359                else { 
     360                        fPanValue = pan_R / 2.0; 
     361                } 
     362 
     363                if( pan_param == 1 && fPanValue < 1 ){ 
     364                        fPanValue += 0.05; 
     365                } 
     366 
     367                if( pan_param != 1 && fPanValue > 0 ){ 
     368                        fPanValue -= 0.05; 
     369                } 
     370 
     371                if (fPanValue >= 0.5) { 
     372                        pan_L = (1.0 - fPanValue) * 2; 
     373                        pan_R = 1.0; 
     374                } 
     375                else { 
     376                        pan_L = 1.0; 
     377                        pan_R = fPanValue * 2; 
     378                } 
     379 
     380 
     381                instr->set_pan_l( pan_L ); 
     382                instr->set_pan_r( pan_R ); 
     383 
     384                Hydrogen::get_instance()->setSelectedInstrumentNumber(nLine); 
     385 
     386                return true; 
    263387        } 
    264388