Changeset 533

Show
Ignore:
Timestamp:
09/29/08 01:34:32 (2 months ago)
Author:
gabriel
Message:

Merge rev 414:428 from trunk

Conflicts:

libs/hydrogen/src/hydrogen.cpp

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/jackMidi/gui/src/HydrogenApp.cpp

    r404 r533  
    351351void HydrogenApp::onEventQueueTimer() 
    352352{ 
     353        // use the timer to do schedule instrument slaughter; 
    353354        EventQueue *pQueue = EventQueue::get_instance(); 
    354355 
  • branches/jackMidi/gui/src/MainForm.cpp

    r531 r533  
    496496        h2app->setStatusBarMessage( trUtf8("Song saved."), 10000 ); 
    497497        //update SoundlibraryPanel 
     498        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
    498499        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    499500} 
     
    536537        } 
    537538        //update SoundlibraryPanel 
     539        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
    538540        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    539541} 
     
    622624         
    623625        //update SoundlibraryPanel 
     626        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
    624627        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    625628} 
     
    921924void MainForm::action_instruments_importLibrary() 
    922925{ 
    923   SoundLibraryImportDialog dialog( this ); 
    924   dialog.exec(); 
     926       SoundLibraryImportDialog dialog( this ); 
     927       dialog.exec(); 
    925928} 
    926929 
     
    929932void MainForm::action_instruments_saveLibrary() 
    930933{ 
    931   SoundLibrarySaveDialog dialog( this ); 
    932   dialog.exec(); 
    933  
    934   HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
     934       SoundLibrarySaveDialog dialog( this ); 
     935       dialog.exec(); 
     936        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
     937       HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    935938} 
    936939 
  • branches/jackMidi/gui/src/Mixer/Mixer.cpp

    r402 r533  
    247247void Mixer::soloClicked(uint nLine) 
    248248{ 
    249         Hydrogen *pEngine = Hydrogen::get_instance(); 
    250         Song *pSong = pEngine->getSong(); 
    251         InstrumentList *pInstrList = pSong->get_instrument_list(); 
    252         int nInstruments = pInstrList->get_size(); 
    253  
    254         bool isSoloClicked = m_pMixerLine[ nLine ]->isSoloClicked(); 
    255  
    256         if (!isSoloClicked) { 
    257                 for ( int i = 0; i < nInstruments; i++ ) { 
    258                         m_pMixerLine[i]->setSoloClicked( false ); 
    259                         m_pMixerLine[i]->setMuteClicked( true ); 
    260                         pInstrList->get( i )->set_muted( true ); 
    261                 } 
    262                 m_pMixerLine[nLine]->setSoloClicked( true ); 
    263                 m_pMixerLine[nLine]->setMuteClicked( false ); 
    264                 pInstrList->get( nLine )->set_muted( false ); 
    265         } 
    266         else { 
    267                 for ( int i = 0; i < nInstruments; i++ ) { 
    268                         m_pMixerLine[i]->setMuteClicked( false ); 
    269                         m_pMixerLine[i]->setSoloClicked( false ); 
    270                         pInstrList->get( i )->set_muted( false ); 
    271                 } 
    272         } 
    273  
    274 
    275  
    276  
     249        MixerLine * L = m_pMixerLine[ nLine ]; 
     250        L->setSoloClicked( !L->isSoloClicked() ); 
     251        soloClicked( L ); 
     252//      Hydrogen *pEngine = Hydrogen::get_instance(); 
     253//      Song *pSong = pEngine->getSong(); 
     254//      InstrumentList *pInstrList = pSong->get_instrument_list(); 
     255//      int nInstruments = pInstrList->get_size(); 
     256//  
     257//      bool isSoloClicked = m_pMixerLine[ nLine ]->isSoloClicked(); 
     258//  
     259//      if (!isSoloClicked) { 
     260//              for ( int i = 0; i < nInstruments; i++ ) { 
     261//                      m_pMixerLine[i]->setSoloClicked( false ); 
     262//                      m_pMixerLine[i]->setMuteClicked( true ); 
     263//                      pInstrList->get( i )->set_muted( true ); 
     264//              } 
     265//              m_pMixerLine[nLine]->setSoloClicked( true ); 
     266//              m_pMixerLine[nLine]->setMuteClicked( false ); 
     267//              pInstrList->get( nLine )->set_muted( false ); 
     268//      } 
     269//      else { 
     270//              for ( int i = 0; i < nInstruments; i++ ) { 
     271//                      m_pMixerLine[i]->setMuteClicked( false ); 
     272//                      m_pMixerLine[i]->setSoloClicked( false ); 
     273//                      pInstrList->get( i )->set_muted( false ); 
     274//              } 
     275//      } 
     276 
     277
     278 
     279bool Mixer::isSoloClicked( uint n ) 
     280
     281        if ( n >= MAX_INSTRUMENTS || m_pMixerLine[ n ] == NULL ) { 
     282                return false; 
     283        } 
     284        return m_pMixerLine[ n ]->isSoloClicked(); 
     285
    277286 
    278287void Mixer::noteOnClicked( MixerLine* ref ) 
  • branches/jackMidi/gui/src/Mixer/Mixer.h

    r402 r533  
    5252                void resizeEvent ( QResizeEvent *ev ); 
    5353                void soloClicked(uint nLine); 
     54                bool isSoloClicked(uint nLine); 
    5455 
    5556                void getPeaksInMixerLine( uint nMixerLine, float& fPeak_L, float& fPeak_R ); 
  • branches/jackMidi/gui/src/PatternEditor/DrumPatternEditor.cpp

    r404 r533  
    193193                                Note *pNote2 = new Note( pSelectedInstrument, 0, fVelocity, fPan_L, fPan_R, nLength, fPitch); 
    194194                                AudioEngine::get_instance()->get_sampler()->note_on(pNote2); 
    195 //                              pSelectedInstrument->enqueue(); 
    196195                        } 
    197196                } 
  • branches/jackMidi/gui/src/PatternEditor/PatternEditorInstrumentList.cpp

    r404 r533  
    139139 
    140140 
     141void InstrumentLine::setSoloed( bool soloed ) 
     142{ 
     143        m_pSoloBtn->setPressed( soloed ); 
     144} 
     145 
     146 
    141147 
    142148void InstrumentLine::muteClicked() 
     
    213219        Instrument *pSelectedInstrument = H->getSong()->get_instrument_list()->get( nSelectedInstrument ); 
    214220         
    215         std::multimap <int, Note*>::iterator pos; 
    216         for ( pos = pCurrentPattern->note_map.begin(); pos != pCurrentPattern->note_map.end(); ++pos ) { 
    217                 Note *pNote = pos->second; 
    218                 assert( pNote ); 
    219                 if ( pNote->get_instrument() != pSelectedInstrument ) { 
    220                         continue; 
    221                 } 
    222   
    223                 delete pNote; 
    224                 pCurrentPattern->note_map.erase( pos ); 
    225         } 
    226         AudioEngine::get_instance()->unlock();  // unlock the audio engine 
     221        pCurrentPattern->purge_instrument( pSelectedInstrument ); 
     222//      std::multimap <int, Note*>::iterator pos; 
     223//      for ( pos = pCurrentPattern->note_map.begin(); pos != pCurrentPattern->note_map.end(); ++pos ) { 
     224//              Note *pNote = pos->second; 
     225//              assert( pNote ); 
     226//              if ( pNote->get_instrument() != pSelectedInstrument ) { 
     227//                      continue; 
     228//              } 
     229//  
     230//              delete pNote; 
     231//              pCurrentPattern->note_map.erase( pos ); 
     232//      } 
     233//      AudioEngine::get_instance()->unlock();  // unlock the audio engine 
    227234 
    228235        // this will force an update... 
     
    361368{ 
    362369        Hydrogen *pEngine = Hydrogen::get_instance(); 
     370        pEngine->removeInstrument( m_nInstrumentNumber, false ); 
    363371         
    364372        AudioEngine::get_instance()->lock("InstrumentLine::functionDeleteInstrument"); 
    365         Instrument *pInstr = pEngine->getSong()->get_instrument_list()->get( m_nInstrumentNumber );  
    366  
    367         // if the instrument was the last on the instruments list, select the next-last  
    368         if ( m_nInstrumentNumber >= (int)pEngine->getSong()->get_instrument_list()->get_size() -1 ) {  
    369                 Hydrogen::get_instance()->setSelectedInstrumentNumber(std::max(0, m_nInstrumentNumber - 1) );  
    370         }  
    371  
    372         // delete the instrument from the instruments list  
    373         pEngine->getSong()->get_instrument_list()->del( m_nInstrumentNumber );  
    374         pEngine->getSong()->__is_modified = true;  
    375  
    376  
    377         // delete all the notes using this instrument  
    378         PatternList* pPatternList = pEngine->getSong()->get_pattern_list();  
    379         for ( int nPattern = 0; nPattern < (int)pPatternList->get_size(); ++nPattern ) {  
    380                 H2Core::Pattern *pPattern = pPatternList->get( nPattern );  
    381  
    382                 std::multimap <int, Note*>::iterator pos;  
    383                 for ( pos = pPattern->note_map.begin(); pos != pPattern->note_map.end(); ++pos ) {  
    384                 Note *pNote = pos->second;  
    385                         assert( pNote );  
    386                         if ( pNote->get_instrument() == pInstr ) {  
    387                                 delete pNote;  
    388                                 pPattern->note_map.erase( pos );  
    389                         }  
    390                 }  
    391         }  
    392  
    393         // stop all notes playing  
    394         AudioEngine::get_instance()->get_sampler()->stop_playing_notes();  
    395  
    396         delete pInstr;  
    397  
    398373#ifdef JACK_SUPPORT 
    399374        pEngine->renameJackPorts(); 
    400375#endif 
    401376        AudioEngine::get_instance()->unlock(); 
    402  
    403         // this will force an update...  
    404         EventQueue::get_instance()->push_event( EVENT_SELECTED_INSTRUMENT_CHANGED, -1 );  
    405377} 
    406378 
     
    517489        Song *pSong = pEngine->getSong(); 
    518490        InstrumentList *pInstrList = pSong->get_instrument_list(); 
     491        Mixer * mixer = HydrogenApp::getInstance()->getMixer(); 
    519492 
    520493        unsigned nSelectedInstr = pEngine->getSelectedInstrumentNumber(); 
     
    551524                        pLine->setSelected( nInstr == nSelectedInstr ); 
    552525                        pLine->setMuted( pInstr->is_muted() ); 
     526                        if ( mixer ) { 
     527                                pLine->setSoloed( mixer->isSoloClicked( nInstr ) ); 
     528                        } 
    553529 
    554530                } 
  • branches/jackMidi/gui/src/PatternEditor/PatternEditorInstrumentList.h

    r402 r533  
    5353                void setNumber(int nIndex); 
    5454                void setMuted(bool isMuted); 
     55                void setSoloed( bool soloed ); 
    5556 
    5657        private slots: 
  • branches/jackMidi/gui/src/SongEditor/SongEditor.cpp

    r402 r533  
    993993        int err = fileMng.savePattern( song , nSelectedPattern, patternname, realpatternname, 1 ); 
    994994        if ( err != 0 ) { 
    995                 _ERRORLOG( "Error saving the pattern" ); 
     995                switch ( err ){ 
     996                        case 1: //file exists  
     997                                QMessageBox::information ( this, "Hydrogen", trUtf8 ( "Error saving pattern!\nThe pattern-file exists." )); 
     998                                return; //exit patternPopup_save without update the drumkitlist  
     999                        default: //anything else 
     1000                                _ERRORLOG( "Error saving the pattern" ); 
     1001                                break; 
     1002 
     1003        } 
    9961004        } 
    9971005 
     
    10011009        usleep ( 10000 ); 
    10021010#endif  
     1011        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
    10031012        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    10041013} 
  • branches/jackMidi/gui/src/SoundLibrary/SoundLibraryImportDialog.cpp

    r402 r533  
    403403 
    404404                        // update the drumkit list 
     405                        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
    405406                        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    406407                        updateSoundLibraryList(); 
     
    448449                QMessageBox::information( this, "Hydrogen", QString( trUtf8( "SoundLibrary imported in %1" ).arg( dataDir )  ) ); 
    449450                // update the drumkit list 
     451                HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
    450452                HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    451453                setCursor( QCursor( Qt::ArrowCursor ) ); 
  • branches/jackMidi/gui/src/SoundLibrary/SoundLibraryPanel.cpp

    r531 r533  
    7979        m_pPatternMenu->addSeparator(); 
    8080        m_pPatternMenu->addAction( trUtf8( "Load" ), this, SLOT( on_patternLoadAction() ) ); 
     81        m_pPatternMenu->addAction( trUtf8( "Delete" ), this, SLOT( on_patternDeleteAction() ) ); 
    8182 
    8283        m_pPatternMenuList = new QMenu( this ); 
     
    103104        this->setLayout( pVBox ); 
    104105 
     106        expandpatternlist = false; 
     107        expandsongslist = false; 
     108 
    105109        updateDrumkitList(); 
    106110} 
     
    138142                m_pSongItem->setText( 0, trUtf8( "Songs" ) ); 
    139143                m_pSongItem->setToolTip( 0, "double click to expand the list" ); 
     144                m_pSoundLibraryTree->setItemExpanded( m_pSongItem, expandsongslist ); 
    140145 
    141146                for (uint i = 0; i < songList.size(); i++)  
     
    159164                m_pPatternItem->setText( 0, trUtf8( "Patterns" ) ); 
    160165                m_pPatternItem->setToolTip( 0, "double click to expand the list" ); 
    161  
     166                m_pSoundLibraryTree->setItemExpanded( m_pPatternItem, expandpatternlist ); 
     167                         
    162168//this is to push the mng.getPatternList in all patterns/drumkit dirs 
    163169                for (uint i = 0; i < patternDirList.size(); ++i) { 
     
    406412                 
    407413                        QString patternName = m_pSoundLibraryTree->currentItem()->text( 0 ) + ".h2pattern"; 
     414                        QString drumkitname = m_pSoundLibraryTree->currentItem()->toolTip ( 0 ); 
    408415                         
    409416                        QString sDirectory = ""; 
     
    420427                        for (uint i = 0; i < allPatternDirList.size(); ++i) { 
    421428                                QString testName = allPatternDirList[i]; 
    422                                 if( testName.contains( patternName )){ 
     429                                if( testName.contains( patternName ) && testName.contains( drumkitname )){ 
    423430                 
    424431                                        sDirectory = allPatternDirList[i]; 
     
    535542 
    536543        Drumkit::removeDrumkit( sSoundLibrary ); 
    537  
    538         HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
     544        test_expandedItems(); 
     545        updateDrumkitList(); 
    539546} 
    540547 
     
    655662 
    656663        QString patternName = m_pSoundLibraryTree->currentItem()->text( 0 ) + ".h2pattern"; 
     664        QString drumkitname = m_pSoundLibraryTree->currentItem()->toolTip ( 0 ); 
    657665        Hydrogen *engine = Hydrogen::get_instance(); 
    658666        Song *song = engine->getSong(); 
     
    672680        for (uint i = 0; i < allPatternDirList.size(); ++i) { 
    673681                QString testName = allPatternDirList[i]; 
    674                 if( testName.contains( patternName )){ 
    675  
    676                         sDirectory = allPatternDirList[i]; 
    677                  
     682                if( testName.contains( patternName ) && testName.contains( drumkitname )){ 
     683                        sDirectory = allPatternDirList[i];               
    678684                }  
    679685        } 
     
    695701} 
    696702 
     703 
     704void SoundLibraryPanel::on_patternDeleteAction() 
     705{ 
     706        LocalFileMng mng; 
     707 
     708        QString patternName = m_pSoundLibraryTree->currentItem()->text( 0 ) + ".h2pattern"; 
     709        QString drumkitname = m_pSoundLibraryTree->currentItem()->toolTip ( 0 ); 
     710         
     711        QString sDirectory = ""; 
     712 
     713        std::vector<QString> patternDirList = mng.getPatternDirList(); 
     714 
     715                for (uint i = 0; i < patternDirList.size(); ++i) { 
     716                        QString absPath =  patternDirList[i]; 
     717                        mng.getPatternList( absPath ); 
     718                } 
     719 
     720        std::vector<QString> allPatternDirList = mng.getallPatternList(); 
     721 
     722        for (uint i = 0; i < allPatternDirList.size(); ++i) { 
     723                QString testName = allPatternDirList[i]; 
     724                if( testName.contains( patternName ) && testName.contains( drumkitname )){ 
     725                        sDirectory = allPatternDirList[i];               
     726                }  
     727        } 
     728 
     729        int res = QMessageBox::information( this, "Hydrogen", tr( "Warning, the selected pattern will be deleted from disk.\nAre you sure?"), tr("&Ok"), tr("&Cancel"), 0, 1 ); 
     730        if ( res == 1 ) { 
     731                return; 
     732        } 
     733 
     734        QFile rmfile(sDirectory ); 
     735        bool err = rmfile.remove(); 
     736        if ( err == false ) 
     737        { 
     738                _ERRORLOG ( "Error removing the pattern" ); 
     739        } 
     740 
     741        test_expandedItems(); 
     742        updateDrumkitList(); 
     743} 
     744 
     745 
     746void SoundLibraryPanel::test_expandedItems() 
     747{ 
     748        expandsongslist = m_pSoundLibraryTree->isItemExpanded( m_pSongItem ); 
     749        expandpatternlist = m_pSoundLibraryTree->isItemExpanded( m_pPatternItem ); 
     750} 
  • branches/jackMidi/gui/src/SoundLibrary/SoundLibraryPanel.h

    r402 r533  
    4545 
    4646                void updateDrumkitList(); 
    47  
     47                void test_expandedItems(); 
    4848 
    4949        private slots: 
     
    6161                void on_songLoadAction(); 
    6262                void on_patternLoadAction(); 
     63                void on_patternDeleteAction(); 
    6364 
    6465        private: 
     
    8182                std::vector<H2Core::Drumkit*> m_systemDrumkitInfoList; 
    8283                std::vector<H2Core::Drumkit*> m_userDrumkitInfoList; 
     84                bool expandpatternlist; 
     85                bool expandsongslist; 
     86         
    8387 
    8488 
  • branches/jackMidi/gui/src/SoundLibrary/SoundLibraryPropertiesDialog.cpp

    r531 r533  
    133133        //reload if necessary 
    134134        if ( reload == true ){ 
     135                HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); 
    135136                HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); 
    136137        } 
  • branches/jackMidi/libs/hydrogen/include/hydrogen/Pattern.h

    r404 r533  
    3131 
    3232class Note; 
     33class Instrument; 
    3334 
    3435/// 
     
    4243        Pattern( const QString& name, const QString& category, unsigned lenght = MAX_NOTES ); 
    4344        ~Pattern(); 
     45 
     46        /** 
     47          Delete notes that pertain to instrument I. 
     48          The function is thread safe (it locks the audio data while deleting notes) 
     49        */ 
     50        void purge_instrument( Instrument * I ); 
     51         
     52        /** 
     53          Check if there are any notes pertaining to I 
     54        */ 
     55        bool references_instrument( Instrument * I ); 
    4456         
    4557        static Pattern* get_empty_pattern(); 
  • branches/jackMidi/libs/hydrogen/include/hydrogen/Song.h

    r404 r533  
    7979        Song( const QString& name, const QString& author, float bpm, float volume ); 
    8080        ~Song(); 
     81         
     82        /** 
     83          Remove all the notes in the song that play on instrument I. 
     84          The function is real-time safe (it locks the audio data while deleting notes) 
     85        */ 
     86        void purge_instrument( Instrument* I ); 
    8187 
    8288        void set_volume( float volume ) { 
  • branches/jackMidi/libs/hydrogen/include/hydrogen/hydrogen.h

    r404 r533  
    120120 
    121121        int loadDrumkit( Drumkit *drumkitInfo ); 
    122         void functionDeleteInstrument( int instrumentnumber);    
     122         
     123        /// delete an instrument. If `conditional` is true, and there are patterns that 
     124        /// use this instrument, it's not deleted anyway 
     125        void removeInstrument( int instrumentnumber, bool conditional ); 
    123126 
    124127        //return the name of the current drumkit 
     
    191194        void setNewBpmJTM( float bpmJTM); 
    192195        void ComputeHumantimeFrames(uint32_t nFrames); 
     196         
     197        void kill_instruments(); 
    193198 
    194199private: 
     
    201206        Song::SongMode m_oldEngineMode; 
    202207        bool m_bOldLoopEnabled; 
     208        std::list<Instrument*> instrument_death_row; /// Deleting instruments too soon leads to potential crashes. 
    203209}; 
    204210 
  • branches/jackMidi/libs/hydrogen/include/hydrogen/instrument.h

    r404 r533  
    2727#include <hydrogen/globals.h> 
    2828#include <hydrogen/Object.h> 
     29#include <cassert> 
    2930 
    3031namespace H2Core 
     
    104105        ); 
    105106         
     107        /// create a new object without anything in it. 
     108        static Instrument * create_empty(); 
    106109        ~Instrument(); 
    107110 
     111        /// creates a new object; loads samples from drumkit/instrument. 
    108112        static Instrument* load_instrument( 
    109113            const QString& drumkit_name, 
     
    111115        ); 
    112116         
     117        /// loads state _and_ samples into an Instrument from a `placeholder` instrument 
     118        /// (i.e. an Instrument that has everything but the actal samples.) 
     119        void load_from_placeholder( Instrument* placeholder, bool is_live = true ); 
     120         
     121        /// loads instrument from path into a `live` Instrument object. 
     122        void load_from_name( 
     123            const QString& drumkit_name, 
     124            const QString& instrument_name, 
     125            bool is_live = true 
     126        ); 
    113127 
    114128        /** 
    115129        \brief Returns a layer in the list 
    116130         */ 
    117         InstrumentLayer* get_layer( int index ); 
     131        inline InstrumentLayer* get_layer( int index ); 
    118132 
    119133        /** 
     
    133147                __id = id; 
    134148        } 
    135         const QString& get_id() { 
     149        inline const QString& get_id() { 
    136150                return __id; 
    137151        } 
     
    145159                __mute_group = group; 
    146160        } 
    147         int get_mute_group() { 
     161        inline int get_mute_group() { 
    148162                return __mute_group; 
    149163        } 
     
    152166                __muted = muted; 
    153167        } 
    154         bool is_muted() { 
     168        inline bool is_muted() { 
    155169                return __muted; 
    156170        } 
    157171 
    158         float get_pan_l() { 
     172        inline float get_pan_l() { 
    159173                return __pan_l; 
    160174        } 
     
    163177        } 
    164178 
    165         float get_pan_r() { 
     179        inline float get_pan_r() { 
    166180                return __pan_r; 
    167181        } 
     
    170184        } 
    171185 
    172         float get_gain() { 
     186        inline float get_gain() { 
    173187                return __gain; 
    174188        } 
     
    177191        } 
    178192 
    179         float get_volume() { 
     193        inline float get_volume() { 
    180194                return __volume; 
    181195        } 
     
    184198        } 
    185199 
    186         bool is_filter_active() { 
     200        inline bool is_filter_active() { 
    187201                return __filter_active; 
    188202        } 
     
    191205        } 
    192206 
    193         float get_filter_resonance() { 
     207        inline float get_filter_resonance() { 
    194208                return __filter_resonance; 
    195209        } 
     
    198212        } 
    199213 
    200         float get_filter_cutoff() { 
     214        inline float get_filter_cutoff() { 
    201215                return __filter_cutoff; 
    202216        } 
     
    205219        } 
    206220 
    207         float get_peak_l() { 
     221        inline float get_peak_l() { 
    208222                return __peak_l; 
    209223        } 
     
    212226        } 
    213227 
    214         float get_peak_r() { 
     228        inline float get_peak_r() { 
    215229                return __peak_r; 
    216230        } 
     
    219233        } 
    220234 
    221         float get_fx_level( int index ) { 
     235        inline float get_fx_level( int index ) { 
    222236                return __fx_level[index]; 
    223237        } 
     
    226240        } 
    227241 
    228         float get_random_pitch_factor() { 
     242        inline float get_random_pitch_factor() { 
    229243                return __random_pitch_factor; 
    230244        } 
     
    240254        } 
    241255 
    242         bool is_active() { 
     256        inline bool is_active() { 
    243257                return __active; 
    244258        } 
     
    247261        } 
    248262 
    249         bool is_soloed() { 
     263        inline bool is_soloed() { 
    250264                return __soloed; 
    251265        } 
     
    253267                __soloed = soloed; 
    254268        } 
     269        inline void enqueue() { 
     270                __queued++; 
     271        } 
     272        inline void dequeue() { 
     273                assert( __queued > 0 ); 
     274                __queued--; 
     275        } 
     276        inline int is_queued() { 
     277                return __queued; 
     278        } 
    255279 
    256280private: 
     281        int __queued; 
    257282        InstrumentLayer* __layer_list[MAX_LAYERS]; 
    258283        ADSR* __adsr; 
  • branches/jackMidi/libs/hydrogen/src/hydrogen.cpp

    r404 r533  
    289289        AudioEngine::get_instance()->get_sampler()->stop_playing_notes(); 
    290290 
    291  
    292291        // delete all copied notes in the song notes queue 
    293292        while ( !m_songNoteQueue.empty() ) { 
     293                m_songNoteQueue.top()->get_instrument()->dequeue(); 
    294294                delete m_songNoteQueue.top(); 
    295295                m_songNoteQueue.pop(); 
     
    395395        // delete all copied notes in the song notes queue 
    396396        while(!m_songNoteQueue.empty()){ 
     397                m_songNoteQueue.top()->get_instrument()->dequeue(); 
    397398                delete m_songNoteQueue.top(); 
    398399                m_songNoteQueue.pop(); 
     
    522523                         
    523524                        m_songNoteQueue.pop();                  // rimuovo la nota dalla lista di note 
    524  
     525                        pNote->get_instrument()->dequeue(); 
    525526                        // raise noteOn event 
    526527                        int nInstrument = m_pSong->get_instrument_list()->get_pos( pNote->get_instrument() ); 
     
    624625 
    625626        while (!m_songNoteQueue.empty()) {       // delete all copied notes in the song notes queue 
     627                m_songNoteQueue.top()->get_instrument()->dequeue(); 
    626628                delete m_songNoteQueue.top(); 
    627629                m_songNoteQueue.pop(); 
     
    10371039                                // printf ("tick=%d  pos=%d\n", tick, note->getPosition()); 
    10381040                                m_midiNoteQueue.pop_front(); 
     1041                                note->get_instrument()->enqueue(); 
    10391042                                m_songNoteQueue.push( note ); 
    10401043                        } else { 
     
    11781181 
    11791182                                Note *pMetronomeNote = new Note( m_pMetronomeInstrument, tick, fVelocity, 0.5, 0.5, -1, fPitch ); 
     1183                                m_pMetronomeInstrument->enqueue(); 
    11801184                                m_songNoteQueue.push( pMetronomeNote ); 
    11811185                        } 
     
    12201224 
    12211225                                                pCopiedNote->m_nHumanizeDelay = nOffset;        // humanize time 
     1226                                                pNote->get_instrument()->enqueue(); 
    12221227                                                m_songNoteQueue.push( pCopiedNote ); 
    12231228                                                //pCopiedNote->dumpInfo(); 
     
    16541659        audioEngine_stopAudioDrivers(); 
    16551660        audioEngine_destroy(); 
     1661        kill_instruments(); 
    16561662        instance = NULL; 
    16571663} 
     
    20782084int Hydrogen::loadDrumkit( Drumkit *drumkitInfo ) 
    20792085{ 
    2080         _INFOLOG( drumkitInfo->getName() ); 
     2086        INFOLOG( drumkitInfo->getName() ); 
    20812087        m_currentDrumkit = drumkitInfo->getName(); 
    20822088        LocalFileMng fileMng; 
     
    21222128                        assert( pInstr ); 
    21232129                } else { 
    2124                         pInstr = new Instrument( "", "", new ADSR() );  
    2125                         AudioEngine::get_instance()->lock( "Hydrogen::loadDrumkit" );  
     2130                        pInstr = Instrument::create_empty(); 
     2131                        // The instrument isn't playing yet; no need for locking :-) - Jakob Lund. 
     2132                        // AudioEngine::get_instance()->lock( "Hydrogen::loadDrumkit" ); 
    21262133                        songInstrList->add( pInstr ); 
    2127                         AudioEngine::get_instance()->unlock(); 
     2134                        // AudioEngine::get_instance()->unlock(); 
    21282135                } 
    21292136 
     
    21332140                 
    21342141                // creo i nuovi layer in base al nuovo strumento 
    2135                 for ( unsigned nLayer = 0; nLayer < MAX_LAYERS; ++nLayer ) {  
    2136                         InstrumentLayer *pNewLayer = pNewInstr->get_layer( nLayer );  
    2137                         if ( pNewLayer != NULL ) {  
    2138                                 Sample *pNewSample = pNewLayer->get_sample();  
    2139                                 QString sSampleFilename = sDrumkitPath + drumkitInfo->getName() + "/" + pNewSample->get_filename();  
    2140                                 _INFOLOG( "    |-> Loading layer [ " + sSampleFilename + " ]" );  
    2141  
    2142                                 // carico il nuovo sample e creo il nuovo layer  
    2143                                 Sample *pSample = Sample::load( sSampleFilename );  
    2144 //                              pSample->setFilename( pNewSample->getFilename() );      // riuso il path del nuovo sample (perche' e' gia relativo al path del drumkit)  
    2145                                 InstrumentLayer *pOldLayer = pInstr->get_layer( nLayer );  
    2146  
    2147                                 if ( pSample == NULL ) {  
    2148                                         //_ERRORLOG( "Error Loading drumkit: NULL sample, now using /emptySample.wav" );  
    2149                                         //pSample = Sample::load(string(DataPath::getDataPath() ).append( "/emptySample.wav" ));  
    2150                                         //pSample->m_sFilename = string(DataPath::getDataPath() ).append( "/emptySample.wav" );  
    2151                                         _ERRORLOG( "Error loading sample. Creating a new empty layer." );  
    2152                                         AudioEngine::get_instance()->lock( "Hydrogen::loadDrumkit" );  
    2153                                         pInstr->set_layer( NULL, nLayer );  
    2154                                         AudioEngine::get_instance()->unlock();  
    2155                                         delete pOldLayer;  
    2156                                         continue;  
    2157                                 }  
    2158                                 InstrumentLayer *pLayer = new InstrumentLayer( pSample );  
    2159                                 pLayer->set_start_velocity( pNewLayer->get_start_vel