Show
Ignore:
Timestamp:
08/21/08 23:52:14 (5 years ago)
Author:
jakoblund
Message:

Make deletion of instruments crash-proof by using a per-note reference count

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/libs/hydrogen/src/sampler/sampler.cpp

    r260 r371  
    109109                Note *oldNote = __playing_notes_queue[ 0 ]; 
    110110                __playing_notes_queue.erase( __playing_notes_queue.begin() ); 
     111                oldNote->get_instrument()->dequeue(); 
    111112                delete oldNote; // FIXME: send note-off instead of removing the note from the list? 
    112113        } 
     
    121122                if ( res == 1 ) {       // la nota e' finita 
    122123                        __playing_notes_queue.erase( __playing_notes_queue.begin() + i ); 
     124                        pNote->get_instrument()->dequeue(); 
    123125                        delete pNote; 
    124126                        pNote = NULL; 
     
    658660                        if ( pNote->get_instrument() == instrument ) { 
    659661                                delete pNote; 
     662                                instrument->dequeue(); 
    660663                                __playing_notes_queue.erase( __playing_notes_queue.begin() + i ); 
    661664                        } 
     
    666669                for ( unsigned i = 0; i < __playing_notes_queue.size(); ++i ) { 
    667670                        Note *pNote = __playing_notes_queue[i]; 
     671                        pNote->get_instrument()->dequeue(); 
    668672                        delete pNote; 
    669673                } 
     
    689693        stop_playing_notes( __preview_instrument ); 
    690694        note_on( previewNote ); 
     695        __preview_instrument->enqueue(); 
    691696 
    692697        AudioEngine::get_instance()->unlock(); 
     
    697702void Sampler::preview_instrument( Instrument* instr ) 
    698703{ 
     704        Instrument * old_preview; 
    699705        AudioEngine::get_instance()->lock( "Sampler::previewInstrument" ); 
    700706 
    701707        stop_playing_notes( __preview_instrument ); 
    702708 
    703         delete __preview_instrument; 
     709        old_preview = __preview_instrument 
    704710        __preview_instrument = instr; 
    705711 
     
    707713 
    708714        note_on( previewNote ); // exclusive note 
     715        instr->enqueue(); 
    709716        AudioEngine::get_instance()->unlock(); 
     717        delete old_preview; 
    710718} 
    711719