InstrumentComponent* InstrumentComponent::load_from( XMLNode* node, const QString& dk_path ) { int id = node->read_int( "component_id", EMPTY_INSTR_ID, false, false ); if ( id==EMPTY_INSTR_ID ) { return nullptr; } InstrumentComponent* pInstrumentComponent = new InstrumentComponent( id ); pInstrumentComponent->set_gain( node->read_float( "gain", 1.0f, true, false ) ); XMLNode layer_node = node->firstChildElement( "layer" ); int n = 0; while ( !layer_node.isNull() ) { if ( n >= maxLayers ) { ERRORLOG( QString( "n (%1) >= maxLayers (%2)" ).arg( n ).arg( maxLayers ) ); break; } pInstrumentComponent->set_layer( InstrumentLayer::load_from( &layer_node, dk_path ), n ); n++; layer_node = layer_node.nextSiblingElement( "layer" ); } return pInstrumentComponent; }
void InstrumentEditor::rotaryChanged(Rotary *ref) { float fVal = ref->getValue(); if ( m_pInstrument ) { if ( ref == m_pRandomPitchRotary ){ m_pInstrument->set_random_pitch_factor( fVal ); } else if ( ref == m_pCutoffRotary ) { m_pInstrument->set_filter_cutoff( fVal ); } else if ( ref == m_pResonanceRotary ) { if ( fVal > 0.95f ) { fVal = 0.95f; } m_pInstrument->set_filter_resonance( fVal ); } else if ( ref == m_pAttackRotary ) { m_pInstrument->get_adsr()->set_attack( fVal * fVal * 100000 ); } else if ( ref == m_pDecayRotary ) { m_pInstrument->get_adsr()->set_decay( fVal * fVal * 100000 ); } else if ( ref == m_pSustainRotary ) { m_pInstrument->get_adsr()->set_sustain( fVal ); } else if ( ref == m_pReleaseRotary ) { m_pInstrument->get_adsr()->set_release( 256.0 + fVal * fVal * 100000 ); } else if ( ref == m_pLayerGainRotary ) { fVal = fVal * 5.0; char tmp[20]; sprintf( tmp, "%#.2f", fVal ); m_pLayerGainLCD->setText( tmp ); InstrumentComponent* pCompo = m_pInstrument->get_component(m_nSelectedComponent); if( pCompo ) { H2Core::InstrumentLayer *pLayer = pCompo->get_layer( m_nSelectedLayer ); if ( pLayer ) { pLayer->set_gain( fVal ); m_pWaveDisplay->updateDisplay( pLayer ); } } } else if ( ref == m_pCompoGainRotary ) { fVal = fVal * 5.0; char tmp[20]; sprintf( tmp, "%#.2f", fVal ); m_pCompoGainLCD->setText( tmp ); InstrumentComponent* pCompo = m_pInstrument->get_component(m_nSelectedComponent); pCompo->set_gain( fVal ); } else if ( ref == m_pLayerPitchCoarseRotary ) { //fVal = fVal * 24.0 - 12.0; m_pLayerPitchCoarseLCD->setText( QString( "%1" ).arg( (int)fVal ) ); InstrumentComponent* pCompo = m_pInstrument->get_component(m_nSelectedComponent); if( pCompo ) { H2Core::InstrumentLayer *pLayer = pCompo->get_layer( m_nSelectedLayer ); if ( pLayer ) { int nCoarse = (int)m_pLayerPitchCoarseRotary->getValue(); float fFine = m_pLayerPitchFineRotary->getValue() / 100.0; pLayer->set_pitch( nCoarse + fFine ); INFOLOG( QString("pitch: %1").arg( pLayer->get_pitch() ) ); } } } else if ( ref == m_pLayerPitchFineRotary ) { m_pLayerPitchFineLCD->setText( QString( "%1" ).arg( fVal ) ); InstrumentComponent* pCompo = m_pInstrument->get_component(m_nSelectedComponent); if( pCompo ) { H2Core::InstrumentLayer *pLayer = pCompo->get_layer( m_nSelectedLayer ); if ( pLayer ) { int nCoarse = (int)m_pLayerPitchCoarseRotary->getValue(); float fFine = m_pLayerPitchFineRotary->getValue() / 100.0; pLayer->set_pitch( nCoarse + fFine ); INFOLOG( QString("pitch: %1").arg( pLayer->get_pitch()) ); } } } else if ( ref == m_pInstrumentGain ) { fVal = fVal * 5.0; char tmp[20]; sprintf( tmp, "%#.2f", fVal ); m_pInstrumentGainLCD->setText( tmp ); m_pInstrument->set_gain( fVal ); } else { ERRORLOG( "[rotaryChanged] unhandled rotary" ); } } }
void InstrumentEditor::compoChangeAddDelete(QAction* pAction) { QString sSelectedAction = pAction->text(); Hydrogen * pEngine = Hydrogen::get_instance(); if( sSelectedAction.compare("add") == 0 ) { if ( m_pInstrument ) { bool bIsOkPressed; QString sNewName = QInputDialog::getText( this, "Hydrogen", trUtf8( "Component name" ), QLineEdit::Normal, "New Component", &bIsOkPressed ); if ( bIsOkPressed ) { DrumkitComponent* pDrumkitComponent = new DrumkitComponent( findFreeDrumkitComponentId(), sNewName ); pEngine->getSong()->get_components()->push_back( pDrumkitComponent ); //InstrumentComponent* instrument_component = new InstrumentComponent( dm_component->get_id() ); //instrument_component->set_gain( 1.0f ); //m_pInstrument->get_components()->push_back( instrument_component ); m_nSelectedComponent = pDrumkitComponent->get_id(); m_pLayerPreview->set_selected_component( pDrumkitComponent->get_id() ); selectedInstrumentChangedEvent(); // this will force an update... EventQueue::get_instance()->push_event( EVENT_SELECTED_INSTRUMENT_CHANGED, -1 ); #ifdef H2CORE_HAVE_JACK pEngine->renameJackPorts(pEngine->getSong()); #endif } else { // user entered nothing or pressed Cancel } } } else if( sSelectedAction.compare("delete") == 0 ) { std::vector<DrumkitComponent*>* pDrumkitComponents = pEngine->getSong()->get_components(); if(pDrumkitComponents->size() == 1){ return; } DrumkitComponent* pDrumkitComponent = pEngine->getSong()->get_component( m_nSelectedComponent ); InstrumentList* pInstruments = pEngine->getSong()->get_instrument_list(); for ( int n = ( int )pInstruments->size() - 1; n >= 0; n-- ) { Instrument* pInstrument = pInstruments->get( n ); for( int o = 0 ; o < pInstrument->get_components()->size() ; o++ ) { InstrumentComponent* pInstrumentComponent = pInstrument->get_components()->at( o ); if( pInstrumentComponent->get_drumkit_componentID() == pDrumkitComponent->get_id() ) { for( int nLayer = 0; nLayer < MAX_LAYERS; nLayer++ ) { InstrumentLayer* pLayer = pInstrumentComponent->get_layer( nLayer ); if( pLayer ) delete pLayer; } pInstrument->get_components()->erase( pInstrument->get_components()->begin() + o );; break; } } } for ( int n = 0 ; n < pDrumkitComponents->size() ; n++ ) { DrumkitComponent* pTmpDrumkitComponent = pDrumkitComponents->at( n ); if( pTmpDrumkitComponent->get_id() == pDrumkitComponent->get_id() ) { pDrumkitComponents->erase( pDrumkitComponents->begin() + n ); break; } } m_nSelectedComponent = pDrumkitComponents->front()->get_id(); selectedInstrumentChangedEvent(); // this will force an update... EventQueue::get_instance()->push_event( EVENT_SELECTED_INSTRUMENT_CHANGED, -1 ); } else if( sSelectedAction.compare("rename") == 0 ) { labelCompoClicked( NULL ); } else { m_nSelectedComponent = -1; std::vector<DrumkitComponent*>* pDrumkitComponents = pEngine->getSong()->get_components(); for (std::vector<DrumkitComponent*>::iterator it = pDrumkitComponents->begin() ; it != pDrumkitComponents->end(); ++it) { DrumkitComponent* pDrumkitComponent = *it; if( pDrumkitComponent->get_name().compare( sSelectedAction ) == 0) { m_nSelectedComponent = pDrumkitComponent->get_id(); m_pCompoNameLbl->setText( pDrumkitComponent->get_name() ); break; } } if( m_pInstrument && !m_pInstrument->get_component(m_nSelectedComponent)) { INFOLOG("Component needs to be added"); InstrumentComponent* pInstrComponent = new InstrumentComponent( m_nSelectedComponent ); pInstrComponent->set_gain( 1.0f ); m_pInstrument->get_components()->push_back( pInstrComponent ); #ifdef H2CORE_HAVE_JACK pEngine->renameJackPorts(pEngine->getSong()); #endif } m_pLayerPreview->set_selected_component(m_nSelectedComponent); selectedInstrumentChangedEvent(); // this will force an update... EventQueue::get_instance()->push_event( EVENT_SELECTED_INSTRUMENT_CHANGED, -1 ); } }
void Instrument::load_from( Drumkit* pDrumkit, Instrument* pInstrument, bool is_live ) { this->get_components()->clear(); for (std::vector<InstrumentComponent*>::iterator it = pInstrument->get_components()->begin() ; it != pInstrument->get_components()->end(); ++it) { InstrumentComponent* pSrcComponent = *it; InstrumentComponent* pMyComponent = new InstrumentComponent( pSrcComponent->get_drumkit_componentID() ); pMyComponent->set_gain( pSrcComponent->get_gain() ); this->get_components()->push_back( pMyComponent ); for ( int i=0; i<MAX_LAYERS; i++ ) { InstrumentLayer* src_layer = pSrcComponent->get_layer( i ); InstrumentLayer* my_layer = pMyComponent->get_layer( i ); if( src_layer==0 ) { if ( is_live ) AudioEngine::get_instance()->lock( RIGHT_HERE ); pMyComponent->set_layer( NULL, i ); if ( is_live ) AudioEngine::get_instance()->unlock(); } else { QString sample_path = pDrumkit->get_path() + "/" + src_layer->get_sample()->get_filename(); Sample* sample = Sample::load( sample_path ); if ( sample==0 ) { _ERRORLOG( QString( "Error loading sample %1. Creating a new empty layer." ).arg( sample_path ) ); if ( is_live ) AudioEngine::get_instance()->lock( RIGHT_HERE ); pMyComponent->set_layer( NULL, i ); if ( is_live ) AudioEngine::get_instance()->unlock(); } else { if ( is_live ) AudioEngine::get_instance()->lock( RIGHT_HERE ); pMyComponent->set_layer( new InstrumentLayer( src_layer, sample ), i ); if ( is_live ) AudioEngine::get_instance()->unlock(); } } delete my_layer; } } if ( is_live ) AudioEngine::get_instance()->lock( RIGHT_HERE ); this->set_id( pInstrument->get_id() ); this->set_name( pInstrument->get_name() ); this->set_drumkit_name( pDrumkit->get_name() ); this->set_gain( pInstrument->get_gain() ); this->set_volume( pInstrument->get_volume() ); this->set_pan_l( pInstrument->get_pan_l() ); this->set_pan_r( pInstrument->get_pan_r() ); this->set_adsr( new ADSR( *( pInstrument->get_adsr() ) ) ); this->set_filter_active( pInstrument->is_filter_active() ); this->set_filter_cutoff( pInstrument->get_filter_cutoff() ); this->set_filter_resonance( pInstrument->get_filter_resonance() ); this->set_random_pitch_factor( pInstrument->get_random_pitch_factor() ); this->set_muted( pInstrument->is_muted() ); this->set_mute_group( pInstrument->get_mute_group() ); this->set_midi_out_channel( pInstrument->get_midi_out_channel() ); this->set_midi_out_note( pInstrument->get_midi_out_note() ); this->set_stop_notes( pInstrument->is_stop_notes() ); this->set_hihat_grp( pInstrument->get_hihat_grp() ); this->set_lower_cc( pInstrument->get_lower_cc() ); this->set_higher_cc( pInstrument->get_higher_cc() ); if ( is_live ) AudioEngine::get_instance()->unlock(); }