diff --git a/Timeline/Engine/Audio_Region.C b/Timeline/Engine/Audio_Region.C index f83741c..2fb8932 100644 --- a/Timeline/Engine/Audio_Region.C +++ b/Timeline/Engine/Audio_Region.C @@ -201,7 +201,7 @@ Audio_Region::write ( nframes_t nframes ) ++W; Fl::lock(); sequence()->damage( FL_DAMAGE_ALL, x() + w() - W, y(), W, h() ); - Fl::awake(); +// Fl::awake(); Fl::unlock(); } } @@ -215,6 +215,8 @@ Audio_Region::write ( nframes_t nframes ) bool Audio_Region::finalize ( nframes_t frame ) { + DMESSAGE( "finalizing capture region" ); + _range.length = frame - _range.start; log_end(); diff --git a/Timeline/Engine/Disk_Stream.C b/Timeline/Engine/Disk_Stream.C index c0c3e90..9099271 100644 --- a/Timeline/Engine/Disk_Stream.C +++ b/Timeline/Engine/Disk_Stream.C @@ -76,9 +76,7 @@ Disk_Stream::~Disk_Stream ( ) shutdown(); - /* FIXME: we must wait on the thread to finish here!!! */ - - _track = NULL; + _track = NULL; sem_destroy( &_blocks ); @@ -126,6 +124,17 @@ Disk_Stream::base_flush ( bool is_output ) } +/** signal thread to terminate, then detach it */ +void +Disk_Stream::detach ( void ) +{ + _terminate = true; + + block_processed(); + + pthread_detach( _thread ); +} + /** stop the IO thread. */ void Disk_Stream::shutdown ( void ) @@ -136,9 +145,7 @@ Disk_Stream::shutdown ( void ) block_processed(); if ( _thread ) - pthread_detach( _thread ); - - _thread = 0; + pthread_join( _thread, NULL ); } Track * @@ -157,6 +164,8 @@ Disk_Stream::sequence ( void ) const void Disk_Stream::run ( void ) { + ASSERT( ! _thread, "Thread is already running" ); + if ( pthread_create( &_thread, NULL, &Disk_Stream::disk_thread, this ) != 0 ) FATAL( "Could not create IO thread!" ); } diff --git a/Timeline/Engine/Disk_Stream.H b/Timeline/Engine/Disk_Stream.H index 1bacede..c12c13c 100644 --- a/Timeline/Engine/Disk_Stream.H +++ b/Timeline/Engine/Disk_Stream.H @@ -81,10 +81,7 @@ protected: { while ( ! sem_wait( &_blocks ) && errno == EINTR ); - if ( _terminate ) - return false; - else - return true; + return ! _terminate; } virtual void disk_thread ( void ) = 0; @@ -92,6 +89,10 @@ protected: void base_flush ( bool is_output ); virtual void flush ( void ) = 0; + void run ( void ); + void shutdown ( void ); + void detach ( void ); + public: /* must be set before any Disk_Streams are created */ @@ -109,9 +110,6 @@ public: /* void seek ( nframes_t frame ); */ /* bool seek_pending ( void ); */ - void run ( void ); - void shutdown ( void ); - virtual nframes_t process ( nframes_t nframes ) = 0; int buffer_percent ( void ); diff --git a/Timeline/Engine/Playback_DS.C b/Timeline/Engine/Playback_DS.C index 9ab8559..f7a6aea 100644 --- a/Timeline/Engine/Playback_DS.C +++ b/Timeline/Engine/Playback_DS.C @@ -196,6 +196,9 @@ Playback_DS::disk_thread ( void ) #ifndef AVOID_UNNECESSARY_COPYING delete[] cbuf; #endif + + _terminate = false; + _thread = 0; } /* THREAD: RT */ diff --git a/Timeline/Engine/Record_DS.C b/Timeline/Engine/Record_DS.C index b640228..3f94f1f 100644 --- a/Timeline/Engine/Record_DS.C +++ b/Timeline/Engine/Record_DS.C @@ -191,13 +191,17 @@ Record_DS::disk_thread ( void ) delete[] cbuf; #endif + DMESSAGE( "finalzing capture" ); + /* now finalize the recording */ track()->finalize( _capture, _stop_frame ); delete _capture; _capture = NULL; + _thread = 0; _terminate = false; + DMESSAGE( "capture thread gone" ); } @@ -241,7 +245,7 @@ Record_DS::stop ( nframes_t frame ) _stop_frame = frame; - shutdown(); + detach(); DMESSAGE( "recording finished" ); } diff --git a/Timeline/Engine/Track.C b/Timeline/Engine/Track.C index d234905..eae592b 100644 --- a/Timeline/Engine/Track.C +++ b/Timeline/Engine/Track.C @@ -68,7 +68,6 @@ Track::configure_outputs ( int n ) Playback_DS *ds = playback_ds; playback_ds = NULL; - ds->shutdown(); delete ds; } @@ -116,7 +115,6 @@ Track::configure_inputs ( int n ) Record_DS *ds = record_ds; record_ds = NULL; - ds->shutdown(); delete ds; } @@ -250,6 +248,7 @@ void Track::finalize ( Capture *c, nframes_t frame ) { c->region->finalize( frame ); + DMESSAGE( "finalizing audio file" ); c->audio_file->finalize(); delete c->audio_file;