diff --git a/Timeline/Audio_Region.C b/Timeline/Audio_Region.C index a442151..cd5c4bc 100644 --- a/Timeline/Audio_Region.C +++ b/Timeline/Audio_Region.C @@ -251,7 +251,7 @@ Audio_Region::menu_cb ( const Fl_Menu_ *m ) { nframes_t offset = x_to_offset( Fl::event_x() ); - if ( offset < length() ) + if ( offset > 0 ) _loop = offset; } else @@ -656,12 +656,14 @@ Audio_Region::draw ( void ) if ( _loop ) { + const int x = timeline->ts_to_x( _loop - offset ); + /* FIXME: is there no way to draw these symbols direclty? */ fl_font( FL_SYMBOL, 14 ); fl_color( FL_WHITE ); - fl_draw( "@2>", X + timeline->ts_to_x( _loop - start ), y(), 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 ); + fl_draw( "@2>", X + x - 7, y(), 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 ); fl_color( FL_WHITE ); - fl_draw( "@2<", X + timeline->ts_to_x( _loop - start ), y() + h() - 14, 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 ); + fl_draw( "@2<", X + x - 7, y() + h() - 14, 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 ); } timeline->draw_measure_lines( X, Y, W, H, _box_color ); diff --git a/Timeline/Engine/Audio_File.H b/Timeline/Engine/Audio_File.H index aea0d80..10761c0 100644 --- a/Timeline/Engine/Audio_File.H +++ b/Timeline/Engine/Audio_File.H @@ -95,7 +95,7 @@ public: virtual void close ( void ) = 0; virtual void seek ( nframes_t offset ) = 0; virtual nframes_t read ( sample_t *buf, int channel, nframes_t len ) = 0; - virtual nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t end ) = 0; + virtual nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t len ) = 0; virtual nframes_t write ( sample_t *buf, nframes_t len ) = 0; virtual void finalize ( void ) { _peaks.finish_writing(); } diff --git a/Timeline/Engine/Audio_File_SF.C b/Timeline/Engine/Audio_File_SF.C index e32693d..ef2f164 100644 --- a/Timeline/Engine/Audio_File_SF.C +++ b/Timeline/Engine/Audio_File_SF.C @@ -206,22 +206,20 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len ) /** read samples from /start/ to /end/ into /buf/ */ nframes_t -Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end ) +Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t len ) { - assert( end > start ); - lock(); // open(); seek( start ); - nframes_t len = read( buf, channel, end - start ); + nframes_t cnt = read( buf, channel, len ); unlock(); // close(); - return len; + return cnt; } /** write /nframes/ from /buf/ to soundfile. Should be interleaved for diff --git a/Timeline/Engine/Audio_File_SF.H b/Timeline/Engine/Audio_File_SF.H index fce6e60..8ab9a75 100644 --- a/Timeline/Engine/Audio_File_SF.H +++ b/Timeline/Engine/Audio_File_SF.H @@ -57,7 +57,7 @@ public: void close ( void ); void seek ( nframes_t offset ); nframes_t read ( sample_t *buf, int channel, nframes_t len ); - nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t end ); + nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t len ); nframes_t write ( sample_t *buf, nframes_t nframes ); }; diff --git a/Timeline/Engine/Audio_Region.C b/Timeline/Engine/Audio_Region.C index 2fb8932..1b491de 100644 --- a/Timeline/Engine/Audio_Region.C +++ b/Timeline/Engine/Audio_Region.C @@ -108,7 +108,6 @@ Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channe // const nframes_t start = ofs + r.start + sofs; const nframes_t start = r.offset + sofs; const nframes_t len = min( cnt, nframes - ofs ); - const nframes_t end = start + len; if ( len == 0 ) return 0; @@ -117,7 +116,24 @@ Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channe // printf( "reading region ofs = %lu, sofs = %lu, %lu-%lu\n", ofs, sofs, start, end ); - cnt = _clip->read( buf + ofs, channel, start, end ); + if ( _loop ) + { + +/* /\* keep things simple *\/ */ +/* assert( _loop > len ); */ + + nframes_t lstart = r.offset + ( sofs % _loop ); + + cnt = _clip->read( buf + ofs, channel, lstart, len ); + +/* /\* read the part before the loop point *\/ */ +/* cnt = _clip->read( buf + ofs, channel, start, min( len, _loop - start ) ); */ +/* /\* read the part after the loop point *\/ */ +/* cnt += _clip->read( buf + ofs + cnt, channel, _loop, len - cnt ); */ + + } + else + cnt = _clip->read( buf + ofs, channel, start, len ); /* apply gain */