void SongEditorPanel::updatePlaybackFaderPeaks() { Sampler* pSampler = AudioEngine::get_instance()->get_sampler(); Preferences * pPref = Preferences::get_instance(); Instrument* pInstrument = pSampler->__playback_instrument; bool bShowPeaks = pPref->showInstrumentPeaks(); float fallOff = pPref->getMixerFalloffSpeed(); // fader float fOldPeak_L = m_pPlaybackTrackFader->getPeak_L(); float fOldPeak_R = m_pPlaybackTrackFader->getPeak_R(); float fNewPeak_L = pInstrument->get_peak_l(); pInstrument->set_peak_l( 0.0f ); // reset instrument peak float fNewPeak_R = pInstrument->get_peak_r(); pInstrument->set_peak_r( 0.0f ); // reset instrument peak if (!bShowPeaks) { fNewPeak_L = 0.0f; fNewPeak_R = 0.0f; } if ( fNewPeak_L >= fOldPeak_L) { // LEFT peak m_pPlaybackTrackFader->setPeak_L( fNewPeak_L ); } else { m_pPlaybackTrackFader->setPeak_L( fOldPeak_L / fallOff ); } if ( fNewPeak_R >= fOldPeak_R) { // Right peak m_pPlaybackTrackFader->setPeak_R( fNewPeak_R ); } else { m_pPlaybackTrackFader->setPeak_R( fOldPeak_R / fallOff ); } }
void Mixer::updateMixer() { Preferences *pPref = Preferences::get_instance(); bool bShowPeaks = pPref->showInstrumentPeaks(); Hydrogen *pEngine = Hydrogen::get_instance(); Song *pSong = pEngine->getSong(); InstrumentList *pInstrList = pSong->get_instrument_list(); std::vector<DrumkitComponent*>* compoList = pSong->get_components(); uint nSelectedInstr = pEngine->getSelectedInstrumentNumber(); float fallOff = pPref->getMixerFalloffSpeed(); uint nMuteClicked = 0; int nInstruments = pInstrList->size(); int nCompo = compoList->size(); for ( unsigned nInstr = 0; nInstr < MAX_INSTRUMENTS; ++nInstr ) { if ( nInstr >= nInstruments ) { // unused instrument! let's hide and destroy the mixerline! if ( m_pMixerLine[ nInstr ] ) { delete m_pMixerLine[ nInstr ]; m_pMixerLine[ nInstr ] = NULL; int newWidth = MIXER_STRIP_WIDTH * ( nInstruments + nCompo ); if ( m_pFaderPanel->width() != newWidth ) { m_pFaderPanel->resize( newWidth, height() ); } } continue; } else { if ( m_pMixerLine[ nInstr ] == NULL ) { // the mixerline doesn't exists..I'll create a new one! m_pMixerLine[ nInstr ] = createMixerLine( nInstr ); m_pFaderHBox->insertWidget( nInstr, m_pMixerLine[ nInstr ] ); int newWidth = MIXER_STRIP_WIDTH * ( nInstruments + nCompo ); if ( m_pFaderPanel->width() != newWidth ) { m_pFaderPanel->resize( newWidth, height() ); } } MixerLine *pLine = m_pMixerLine[ nInstr ]; Instrument *pInstr = pInstrList->get( nInstr ); assert( pInstr ); float fNewPeak_L = pInstr->get_peak_l(); pInstr->set_peak_l( 0.0f ); // reset instrument peak float fNewPeak_R = pInstr->get_peak_r(); pInstr->set_peak_r( 0.0f ); // reset instrument peak float fNewVolume = pInstr->get_volume(); bool bMuted = pInstr->is_muted(); QString sName = pInstr->get_name(); float fPan_L = pInstr->get_pan_l(); float fPan_R = pInstr->get_pan_r(); // fader float fOldPeak_L = pLine->getPeak_L(); float fOldPeak_R = pLine->getPeak_R(); if (!bShowPeaks) { fNewPeak_L = 0.0f; fNewPeak_R = 0.0f; } if ( fNewPeak_L >= fOldPeak_L) { // LEFT peak pLine->setPeak_L( fNewPeak_L ); } else { pLine->setPeak_L( fOldPeak_L / fallOff ); } if ( fNewPeak_R >= fOldPeak_R) { // Right peak pLine->setPeak_R( fNewPeak_R ); } else { pLine->setPeak_R( fOldPeak_R / fallOff ); } // fader position pLine->setVolume( fNewVolume ); // mute if ( bMuted ) { nMuteClicked++; } pLine->setMuteClicked( bMuted ); // instr name pLine->setName( sName ); // pan float fPanValue = 0.0; if (fPan_R == 1.0) { fPanValue = 1.0 - (fPan_L / 2.0); } else { fPanValue = fPan_R / 2.0; } pLine->setPan( fPanValue ); // activity if ( pLine->getActivity() > 0 ) { pLine->setActivity( m_pMixerLine[ nInstr ]->getActivity() - 30 ); pLine->setPlayClicked( true ); } else { pLine->setPlayClicked( false ); } for (uint nFX = 0; nFX < MAX_FX; nFX++) { pLine->setFXLevel( nFX, pInstr->get_fx_level( nFX ) ); } pLine->setSelected( nInstr == nSelectedInstr ); pLine->updateMixerLine(); } } for (std::vector<DrumkitComponent*>::iterator it = compoList->begin() ; it != compoList->end(); ++it) { DrumkitComponent* p_compo = *it; if( m_pComponentMixerLine.find(p_compo->get_id()) == m_pComponentMixerLine.end() ) { // the mixerline doesn't exists..I'll create a new one! m_pComponentMixerLine[ p_compo->get_id() ] = createComponentMixerLine( p_compo->get_id() ); m_pFaderHBox->addWidget( m_pComponentMixerLine[ p_compo->get_id() ] ); int newWidth = MIXER_STRIP_WIDTH * ( nInstruments + nCompo ); if ( m_pFaderPanel->width() != newWidth ) { m_pFaderPanel->resize( newWidth, height() ); } } ComponentMixerLine *pLine = m_pComponentMixerLine[ p_compo->get_id() ]; float fNewPeak_L = p_compo->get_peak_l(); p_compo->set_peak_l( 0.0f ); // reset instrument peak float fNewPeak_R = p_compo->get_peak_r(); p_compo->set_peak_r( 0.0f ); // reset instrument peak float fNewVolume = p_compo->get_volume(); bool bMuted = p_compo->is_muted(); QString sName = p_compo->get_name(); float fOldPeak_L = pLine->getPeak_L(); float fOldPeak_R = pLine->getPeak_R(); if (!bShowPeaks) { fNewPeak_L = 0.0f; fNewPeak_R = 0.0f; } if ( fNewPeak_L >= fOldPeak_L) { // LEFT peak pLine->setPeak_L( fNewPeak_L ); } else { pLine->setPeak_L( fOldPeak_L / fallOff ); } if ( fNewPeak_R >= fOldPeak_R) { // Right peak pLine->setPeak_R( fNewPeak_R ); } else { pLine->setPeak_R( fOldPeak_R / fallOff ); } // fader position pLine->setVolume( fNewVolume ); // mute if ( bMuted ) { nMuteClicked++; } pLine->setMuteClicked( bMuted ); // instr name pLine->setName( sName ); pLine->updateMixerLine(); } if( compoList->size() < m_pComponentMixerLine.size() ) { std::vector<int>* p_ids_to_delete = new std::vector<int>(); for (std::map<int, ComponentMixerLine*>::iterator it=m_pComponentMixerLine.begin(); it!=m_pComponentMixerLine.end(); ++it) { bool p_foundExistingRelatedComponent = false; for ( std::vector<DrumkitComponent*>::iterator it2 = compoList->begin() ; it2 != compoList->end(); ++it2 ) { DrumkitComponent* p_compo = *it2; if( p_compo->get_id() == it->first ) { p_foundExistingRelatedComponent = true; break; } } if( !p_foundExistingRelatedComponent ) p_ids_to_delete->push_back( it->first ) ; } for ( std::vector<int>::iterator it = p_ids_to_delete->begin() ; it != p_ids_to_delete->end(); ++it ) { int p_compoID = *it; delete m_pComponentMixerLine[p_compoID]; m_pComponentMixerLine.erase( p_compoID ); int newWidth = MIXER_STRIP_WIDTH * ( nInstruments + nCompo ); if ( m_pFaderPanel->width() != newWidth ) { m_pFaderPanel->resize( newWidth, height() ); } } } if (nMuteClicked == nInstruments - 1) { // find the not muted button for (uint i = 0; i < nInstruments; i++) { Instrument *instr = pInstrList->get(i); if (instr->is_muted() == false) { m_pMixerLine[i]->setSoloClicked(true); break; } } } else { for (uint i = 0; i < nInstruments; i++) { m_pMixerLine[i]->setSoloClicked(false); } } // update MasterPeak float oldPeak_L = m_pMasterLine->getPeak_L(); float newPeak_L = pEngine->getMasterPeak_L(); pEngine->setMasterPeak_L(0.0); float oldPeak_R = m_pMasterLine->getPeak_R(); float newPeak_R = pEngine->getMasterPeak_R(); pEngine->setMasterPeak_R(0.0); if (!bShowPeaks) { newPeak_L = 0.0; newPeak_R = 0.0; } if (newPeak_L >= oldPeak_L) { m_pMasterLine->setPeak_L( newPeak_L ); } else { m_pMasterLine->setPeak_L( oldPeak_L / fallOff ); } if (newPeak_R >= oldPeak_R) { m_pMasterLine->setPeak_R(newPeak_R); } else { m_pMasterLine->setPeak_R( oldPeak_R / fallOff ); } // set master fader position float newVolume = pSong->get_volume(); float oldVolume = m_pMasterLine->getVolume(); if (oldVolume != newVolume) { m_pMasterLine->setVolume(newVolume); } m_pMasterLine->updateMixerLine(); #ifdef H2CORE_HAVE_LADSPA // LADSPA for (uint nFX = 0; nFX < MAX_FX; nFX++) { LadspaFX *pFX = Effects::get_instance()->getLadspaFX( nFX ); if ( pFX ) { m_pLadspaFXLine[nFX]->setName( pFX->getPluginName() ); float fNewPeak_L = 0.0; float fNewPeak_R = 0.0; float fOldPeak_L = 0.0; float fOldPeak_R = 0.0; m_pLadspaFXLine[nFX]->getPeaks( &fOldPeak_L, &fOldPeak_R ); if (fNewPeak_L < fOldPeak_L) fNewPeak_L = fOldPeak_L / fallOff; if (fNewPeak_R < fOldPeak_R) fNewPeak_R = fOldPeak_R / fallOff; m_pLadspaFXLine[nFX]->setPeaks( fNewPeak_L, fNewPeak_R ); m_pLadspaFXLine[nFX]->setFxActive( pFX->isEnabled() ); m_pLadspaFXLine[nFX]->setVolume( pFX->getVolume() ); } else { m_pLadspaFXLine[nFX]->setName( "No plugin" ); m_pLadspaFXLine[nFX]->setFxActive( false ); m_pLadspaFXLine[nFX]->setVolume( 0.0 ); } } // ~LADSPA #endif }