Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

860 lines
22KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Sequence.H"
  19. #include "Audio_Region.H"
  20. #include "Timeline.H"
  21. #include "Waveform.H"
  22. #include "Audio_Sequence.H"
  23. #include "Track.H"
  24. #include "dsp.h"
  25. #include <FL/fl_draw.H>
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Group.H>
  28. #include <FL/Fl_Widget.H>
  29. #include <FL/Fl_Box.H>
  30. #include <FL/Fl_Menu_Item.H>
  31. #include <stdio.h>
  32. #include <algorithm>
  33. // using std::algorithm;
  34. using namespace std;
  35. extern Timeline *timeline;
  36. bool Audio_Region::inherit_track_color = true;
  37. Fl_Boxtype Audio_Region::_box = FL_UP_BOX;
  38. Fl_Color Audio_Region::_selection_color = FL_MAGENTA;
  39. static Fl_Color fl_invert_color ( Fl_Color c )
  40. {
  41. unsigned char r, g, b;
  42. Fl::get_color( c, r, g, b );
  43. return fl_rgb_color( 255 - r, 255 - g, 255 - b );
  44. }
  45. #if 0
  46. /* perhaps use map? */
  47. map_PRIM ( set )
  48. {
  49. /* if ( narg % 2 != 0 ) */
  50. /* printf( "invalid number of arguments\n" ); */
  51. int id = atoi( arg );
  52. map_ARG_NEXT( arg, end );
  53. Logable *l = Loggable::find( id );
  54. char **sa = malloc( sizeof( char * ) * narg + 1 );
  55. for ( int i = 0; i < narg; ++i )
  56. sa[ i ] = strdup( map_ARG_NEXT( arg, end ) );
  57. l->set( sa );
  58. map_RESULT( "" );
  59. }
  60. #endif
  61. void
  62. Audio_Region::init ( void )
  63. {
  64. _sequence = NULL;
  65. _r->offset = 0;
  66. _r->start = 0;
  67. _r->end = 0;
  68. _scale = 1.0f;
  69. _clip = NULL;
  70. _box_color = FL_CYAN;
  71. _color = FL_BLUE;
  72. _fade_in.length = 256;
  73. _fade_in.type = Fade::Sigmoid;
  74. _fade_out = _fade_in;
  75. }
  76. /* copy constructor */
  77. Audio_Region::Audio_Region ( const Audio_Region & rhs )
  78. {
  79. *((Sequence_Region*)this) = (Sequence_Region &)rhs;
  80. _clip = rhs._clip;
  81. _scale = rhs._scale;
  82. _fade_in = rhs._fade_in;
  83. _fade_out = rhs._fade_out;
  84. log_create();
  85. }
  86. Sequence_Widget *
  87. Audio_Region::clone ( const Sequence_Widget *r )
  88. {
  89. return new Audio_Region( *(Audio_Region*)r );
  90. }
  91. /* */
  92. Audio_Region::Audio_Region ( Audio_File *c )
  93. {
  94. init();
  95. _clip = c;
  96. _r->end = _clip->length();
  97. log_create();
  98. }
  99. /* used when DND importing */
  100. Audio_Region::Audio_Region ( Audio_File *c, Sequence *t, nframes_t o )
  101. {
  102. init();
  103. _clip = c;
  104. _r->end = _clip->length();
  105. _sequence = t;
  106. _r->offset = o;
  107. sequence()->add( this );
  108. int sum = 0;
  109. const char *s = rindex( _clip->name(), '/' );
  110. if ( ! s )
  111. s = _clip->name();
  112. for ( int i = strlen( s ); i--; )
  113. sum += s[ i ];
  114. while ( sum >> 8 )
  115. sum = (sum & 0xFF) + (sum >> 8);
  116. _color = (Fl_Color)sum;
  117. /* _color = fl_color_average( FL_YELLOW, (Fl_Color)sum, 0.80 ); */
  118. // _color = FL_YELLOW;
  119. _box_color = FL_WHITE;
  120. log_create();
  121. }
  122. int
  123. Audio_Region::handle ( int m )
  124. {
  125. static int ox, oy;
  126. static enum trim_e trimming;
  127. static bool copied = false;
  128. static nframes_t os;
  129. if ( ! active_r() )
  130. return 0;
  131. // int X = Fl::event_x() - _track->x();
  132. int X = Fl::event_x();
  133. int Y = Fl::event_y();
  134. int ret;
  135. if ( Sequence_Region::handle( m ) )
  136. return 1;
  137. Logger _log( this );
  138. //log_r->start();
  139. switch ( m )
  140. {
  141. case FL_KEYBOARD:
  142. {
  143. if ( Fl::event_key() == FL_F + 3 )
  144. {
  145. nframes_t offset = x_to_offset( X );
  146. if ( offset < length() )
  147. _fade_in.length = offset;
  148. DMESSAGE( "setting fade in length to %lu", _fade_in.length );
  149. redraw();
  150. return 1;
  151. }
  152. else if ( Fl::event_key() == FL_F + 4 )
  153. {
  154. long offset = length() - x_to_offset( X );
  155. if ( offset > 0 )
  156. _fade_out.length = offset;
  157. DMESSAGE( "setting fade out length to %lu", _fade_in.length );
  158. redraw();
  159. return 1;
  160. }
  161. return 0;
  162. }
  163. case FL_PUSH:
  164. {
  165. /* splitting */
  166. if ( Fl::event_shift() && ! Fl::event_ctrl() )
  167. {
  168. switch ( Fl::event_button() )
  169. {
  170. case 2:
  171. {
  172. /* split */
  173. if ( ! copied )
  174. {
  175. Loggable::block_start();
  176. Audio_Region *copy = new Audio_Region( *this );
  177. trim( RIGHT, X );
  178. copy->trim( LEFT, X );
  179. sequence()->add( copy );
  180. log_end();
  181. Loggable::block_end();
  182. return 0;
  183. }
  184. }
  185. default:
  186. return 0;
  187. break;
  188. }
  189. return 1;
  190. }
  191. else
  192. {
  193. ox = x() - X;
  194. oy = y() - Y;
  195. /* for panning */
  196. os = _r->start;
  197. /* normalization and selection */
  198. if ( Fl::event_button2() )
  199. {
  200. if ( Fl::event_ctrl() )
  201. normalize();
  202. else
  203. {
  204. if ( Sequence_Widget::current() == this )
  205. {
  206. if ( selected() )
  207. deselect();
  208. else
  209. select();
  210. }
  211. }
  212. redraw();
  213. return 1;
  214. }
  215. else if ( Fl::event_button1() && Fl::event_ctrl() )
  216. {
  217. /* duplication */
  218. return 1;
  219. }
  220. else if ( Fl::test_shortcut( FL_BUTTON3 ) && ! Fl::event_shift() )
  221. {
  222. /* context menu */
  223. Fade::fade_type_e it = _fade_in.type;
  224. Fade::fade_type_e ot = _fade_out.type;
  225. Fl_Menu_Item menu[] =
  226. {
  227. { "Fade", 0, 0, 0, FL_SUBMENU },
  228. { "In", 0, 0, 0, FL_SUBMENU },
  229. { "Linear", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Linear ? FL_MENU_VALUE : 0 ) },
  230. { "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
  231. { "Logarithmic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
  232. { "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
  233. { 0 },
  234. { "Out", 0, 0, 0, FL_SUBMENU },
  235. { "Linear", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Linear ? FL_MENU_VALUE : 0 ) },
  236. { "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
  237. { "Logarothmic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
  238. { "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
  239. { 0 },
  240. { 0 },
  241. { 0 },
  242. };
  243. const Fl_Menu_Item *r = menu->popup( X, Y, "Audio_Region" );
  244. if ( r )
  245. {
  246. if ( r > &menu[1] && r < &menu[6] )
  247. _fade_in.type = (Fade::fade_type_e)(int)(r - &menu[2]);
  248. else if ( r > &menu[7] && r < &menu[12] )
  249. _fade_out.type = (Fade::fade_type_e)(int)(r - &menu[8]);
  250. redraw();
  251. }
  252. return 0;
  253. }
  254. else
  255. return Sequence_Widget::handle( m );
  256. }
  257. break;
  258. }
  259. case FL_RELEASE:
  260. {
  261. Sequence_Widget::handle( m );
  262. copied = false;
  263. return 1;
  264. }
  265. case FL_DRAG:
  266. if ( ! _drag )
  267. {
  268. begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  269. _log.hold();
  270. }
  271. /* panning */
  272. if ( Fl::event_state() & FL_SHIFT &&
  273. Fl::event_state() & FL_CTRL )
  274. {
  275. int d = (ox + X) - x();
  276. long td = timeline->x_to_ts( d );
  277. nframes_t W = _r->end - _r->start;
  278. if ( td > 0 && os < td )
  279. _r->start = 0;
  280. else
  281. _r->start = os - td;
  282. _r->end = _r->start + W;
  283. sequence()->redraw();
  284. return 1;
  285. }
  286. /* duplication */
  287. if ( Fl::event_state() & FL_CTRL )
  288. {
  289. if ( _drag->state == 0 )
  290. {
  291. sequence()->add( new Audio_Region( *this ) );
  292. _drag->state = 1;
  293. return 1;
  294. }
  295. }
  296. ret = Sequence_Widget::handle( m );
  297. return ret | 1;
  298. default:
  299. return Sequence_Widget::handle( m );
  300. break;
  301. }
  302. }
  303. /** Draws the curve for a single fade. /X/ and /W/ repersent the
  304. portion of the region covered by this draw, which may or may not
  305. cover the fade in question. */
  306. void
  307. Audio_Region::draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool line, int X, int W )
  308. {
  309. const int dy = y() + Fl::box_dy( box() );
  310. const int dh = h() - Fl::box_dh( box() );
  311. const int height = dh;
  312. const int width = timeline->ts_to_x( fade.length );
  313. fl_color( fl_lighter( FL_BLACK ) );
  314. fl_push_matrix();
  315. if ( dir == Fade::In )
  316. fl_translate( line_x(), dy );
  317. else
  318. {
  319. fl_translate( line_x() + abs_w(), dy );
  320. /* flip */
  321. fl_scale( -1.0, 1.0 );
  322. }
  323. fl_scale( width, height );
  324. if ( line )
  325. fl_begin_line();
  326. else
  327. fl_begin_polygon();
  328. fl_vertex( 0.0, 0.0 );
  329. fl_vertex( 0.0, 1.0 );
  330. // if ( draw_real_fade_curve )
  331. {
  332. nframes_t tsx = timeline->x_to_ts( 1 );
  333. nframes_t ts = 0;
  334. for ( int i = 0; i < width; ++i, ts += tsx )
  335. fl_vertex( i / (float)width, 1.0f - fade.gain( ts / (float)fade.length ) );
  336. }
  337. fl_vertex( 1.0, 0.0 );
  338. if ( line )
  339. fl_end_line();
  340. else
  341. fl_end_polygon();
  342. fl_pop_matrix();
  343. }
  344. static void
  345. damager ( void *v )
  346. {
  347. Rectangle *r = (Rectangle*)v;
  348. printf( "damaging from timeout\n" );
  349. timeline->damage( FL_DAMAGE_ALL, r->x, r->y, r->w, r->h );
  350. delete r;
  351. }
  352. void
  353. Audio_Region::draw_box( void )
  354. {
  355. /* dirty hack to keep the box from flipping to vertical at small sizes */
  356. fl_push_clip( x(), y(), w(), h() );
  357. Fl_Color selection_color = _selection_color;
  358. Fl_Color color = Audio_Region::inherit_track_color ? sequence()->track()->color() : _box_color;
  359. color = fl_color_average( color, sequence()->color(), 0.75f );
  360. if ( this == ((Audio_Sequence*)sequence())->capture() )
  361. {
  362. color = FL_RED;
  363. }
  364. else if ( ! active_r() )
  365. {
  366. color = fl_inactive( color );
  367. selection_color = fl_inactive( selection_color );
  368. }
  369. if ( selected() )
  370. fl_draw_box( fl_down( box() ), x() - 10, y(), w() + 50, h(), selection_color );
  371. else
  372. fl_draw_box( box(), x() - 10, y(), w() + 50, h(), color );
  373. /* draw fades */
  374. draw_fade( _fade_in, Fade::In, false, x(), w() );
  375. draw_fade( _fade_out, Fade::Out, false, x(), w() );
  376. fl_pop_clip();
  377. }
  378. /** Draw (part of) region. X, Y, W and H are the rectangle we're clipped to. */
  379. void
  380. Audio_Region::draw ( void )
  381. {
  382. /* intersect clip with region */
  383. int X, Y, W, H;
  384. fl_clip_box( x(), y(), w(), h(), X, Y, W, H );
  385. if ( ! ( W > 0 && H > 0 ) )
  386. /* no coverage */
  387. return;
  388. /* account for waveform outlines... */
  389. X -= 2;
  390. W += 4;
  391. int OX = scroll_x();
  392. int ox = timeline->ts_to_x( _r->offset );
  393. if ( ox > OX + sequence()->w() ||
  394. ox < OX && ox + abs_w() < OX )
  395. /* not in viewport */
  396. return;
  397. int rw = timeline->ts_to_x( _r->end - _r->start );
  398. // nframes_t end = _r->offset + ( _r->end - _r->start );
  399. /* calculate waveform offset due to scrolling */
  400. nframes_t offset = 0;
  401. if ( ox < OX )
  402. {
  403. offset = timeline->x_to_ts( OX - ox );
  404. rw -= OX - ox;
  405. }
  406. rw = min( rw, sequence()->w() );
  407. int rx = x();
  408. fl_push_clip( rx, Y, rw, H );
  409. /* get actual peak data */
  410. int channels;
  411. int peaks;
  412. Peak *pbuf;
  413. // const nframes_t start = _r->start + offset + timeline->x_to_ts( X - rx );
  414. nframes_t start = _r->start + offset;
  415. /* compensate for ??? */
  416. if ( X - rx > 0 )
  417. start += timeline->x_to_ts( X - rx );
  418. const int peaks_needed = min( timeline->ts_to_x( _clip->length() - start ), W );
  419. if ( _clip->read_peaks( timeline->fpp(),
  420. start,
  421. start + timeline->x_to_ts( peaks_needed ),
  422. &peaks, &pbuf, &channels ) &&
  423. peaks )
  424. {
  425. assert( pbuf );
  426. /* draw fade curve outlines--this is only here because of crossfades */
  427. draw_fade( _fade_in, Fade::In, true, X, W );
  428. draw_fade( _fade_out, Fade::Out, true, X, W );
  429. int ch = (h() - Fl::box_dh( box() )) / channels;
  430. /* scale it */
  431. for ( int j = peaks * channels; j--; )
  432. {
  433. pbuf[ j ].min *= _scale;
  434. pbuf[ j ].max *= _scale;
  435. }
  436. for ( int i = 0; i < channels; ++i )
  437. {
  438. // Peak *pb = pbuf + (peaks * i);
  439. /* int fw = timeline->ts_to_x( fade.length ); */
  440. /* /\* if ( draw_fade_waveform ) *\/ */
  441. /* for ( int j = min( fw, peaks ); j--; ) */
  442. /* { */
  443. /* const float g = fade.gain( j * timeline->fpp() ); */
  444. /* pb[ j ].min *= g; */
  445. /* pb[ j ].max *= g; */
  446. /* } */
  447. Waveform::draw( X,
  448. (y() + Fl::box_dy( box() )) + (i * ch),
  449. W,
  450. ch,
  451. pbuf + i, peaks, channels,
  452. selected() ? fl_invert_color( _color ) : _color );
  453. }
  454. }
  455. if ( peaks < peaks_needed )
  456. {
  457. /* couldn't read peaks--perhaps they're being generated. Try again later. */
  458. Fl::add_timeout( 0.1f, damager, new Rectangle( X, y(), W, h() ) );
  459. }
  460. /* FIXME: only draw as many as are necessary! */
  461. timeline->draw_measure_lines( X, Y, W, H, _box_color );
  462. /* fl_color( FL_BLACK ); */
  463. /* fl_line( rx, Y, rx, Y + H ); */
  464. /* fl_line( rx + rw - 1, Y, rx + rw - 1, Y + H ); */
  465. draw_label( _clip->name(), align() );
  466. /* if ( current() ) */
  467. /* { */
  468. /* /\* draw length bubble *\/ */
  469. /* char pat[40]; */
  470. /* snprintf( pat, sizeof( pat ), "%dm:%.1fs", (int)(length() / timeline->sample_rate()) / 60, (double)length() / timeline->sample_rate() ); */
  471. /* draw_label( pat, (Fl_Align)(FL_ALIGN_INSIDE | FL_ALIGN_CENTER), FL_GREEN ); */
  472. /* } */
  473. fl_pop_clip();
  474. }
  475. void
  476. Audio_Region::normalize ( void )
  477. {
  478. printf( "normalize: start=%lu end=%lu\n", _r->start, _r->end );
  479. /* FIXME: figure out a way to do this via the peak server */
  480. int peaks, channels;
  481. Peak *pbuf;
  482. if ( _clip->read_peaks( length(), _r->start, _r->end, &peaks, &pbuf, &channels ) &&
  483. peaks )
  484. _scale = pbuf->normalization_factor();
  485. }
  486. /**********/
  487. /* Engine */
  488. /**********/
  489. /** Apply a (portion of) fade from /start/ to /end/ assuming a
  490. * buffer size of /nframes/. /start/ and /end/ are relative to the
  491. * given buffer, and /start/ may be negative. */
  492. void
  493. Audio_Region::Fade::apply ( sample_t *buf, Audio_Region::Fade::fade_dir_e dir, long start, nframes_t end, nframes_t nframes ) const
  494. {
  495. // printf( "apply fade %s: start=%ld end=%lu\n", dir == Fade::Out ? "out" : "in", start, end );
  496. if ( ! nframes )
  497. return;
  498. const nframes_t i = start > 0 ? start : 0;
  499. const nframes_t e = end > nframes ? nframes : end;
  500. assert( i < nframes );
  501. const float inc = increment();
  502. float fi = ( i - start ) / (float)length;
  503. // buf += i;
  504. buf = &buf[ i ];
  505. nframes_t n = e - i;
  506. assert( i + n <= nframes );
  507. if ( dir == Fade::Out )
  508. {
  509. fi = 1.0f - fi;
  510. for ( ; n--; fi -= inc )
  511. *(buf++) *= gain( fi );
  512. }
  513. else
  514. for ( ; n--; fi += inc )
  515. *(buf++) *= gain( fi );
  516. }
  517. /* THREAD: IO */
  518. /** read the overlapping part of /channel/ at /pos/ for /nframes/ of
  519. this region into /buf/, where /pos/ is in timeline frames */
  520. /* this runs in the diskstream thread. */
  521. /* FIXME: it is far more efficient to read all the channels from a
  522. multichannel source at once... But how should we handle the case of a
  523. mismatch between the number of channels in this region's source and
  524. the number of channels on the track/buffer this data is being read
  525. for? Would it not be better to simply buffer and deinterlace the
  526. frames in the Audio_File class instead, so that sequential requests
  527. for different channels at the same position avoid hitting the disk
  528. again? */
  529. nframes_t
  530. Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) const
  531. {
  532. const Range r = _range;
  533. const nframes_t length = r.end - r.start;
  534. /* do nothing if we aren't covered by this frame range */
  535. if ( pos > r.offset + length || pos + nframes < r.offset )
  536. return 0;
  537. /* calculate offsets into file and sample buffer */
  538. nframes_t sofs, ofs, cnt;
  539. cnt = nframes;
  540. if ( pos < r.offset )
  541. {
  542. sofs = 0;
  543. ofs = r.offset - pos;
  544. cnt -= ofs;
  545. }
  546. else
  547. {
  548. ofs = 0;
  549. sofs = pos - r.offset;
  550. }
  551. if ( ofs >= nframes )
  552. return 0;
  553. // const nframes_t start = ofs + r.start + sofs;
  554. const nframes_t start = r.start + sofs;
  555. const nframes_t len = min( cnt, nframes - ofs );
  556. const nframes_t end = start + len;
  557. if ( len == 0 )
  558. return 0;
  559. /* now that we know how much and where to read, get on with it */
  560. // printf( "reading region ofs = %lu, sofs = %lu, %lu-%lu\n", ofs, sofs, start, end );
  561. cnt = _clip->read( buf + ofs, channel, start, end );
  562. /* apply gain */
  563. buffer_apply_gain( buf + ofs, cnt, _scale );
  564. /* perform declicking if necessary */
  565. /* FIXME: keep the declick defults someplace else */
  566. Fade declick;
  567. declick.length = 256;
  568. declick.type = Fade::Linear;
  569. {
  570. Fade fade;
  571. fade = declick < _fade_in ? _fade_in : declick;
  572. /* do fade in if necessary */
  573. if ( sofs < fade.length )
  574. {
  575. const long d = 0 - sofs;
  576. assert( cnt <= nframes );
  577. fade.apply( buf + ofs, Fade::In, d, d + fade.length, cnt );
  578. }
  579. fade = declick < _fade_out ? _fade_out : declick;
  580. /* do fade out if necessary */
  581. // if ( start + cnt + fade.length > r.end )
  582. if ( start + fade.length > r.end )
  583. {
  584. const nframes_t d = r.end - start;
  585. assert( cnt <= nframes );
  586. fade.apply( buf, Fade::Out, cnt + (long)d - fade.length, cnt + d, cnt );
  587. }
  588. }
  589. // printf( "read %lu frames\n", cnt );
  590. return cnt;
  591. }
  592. /* THREAD: IO */
  593. /** write /nframes/ from /buf/ to source. /buf/ is interleaved and
  594. must match the channel layout of the write source! */
  595. nframes_t
  596. Audio_Region::write ( nframes_t nframes )
  597. {
  598. _range.end += nframes;
  599. /* FIXME: too much? */
  600. // _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), 10/* FIXME: guess */, h() );
  601. if ( 0 == ( timeline->ts_to_x( _range.end ) % 20 ) )
  602. {
  603. nframes_t oldl = _clip->length();
  604. /* FIXME: hack */
  605. _clip->close();
  606. _clip->open();
  607. int W = timeline->ts_to_x( _clip->length() - oldl );
  608. /* why - 1? */
  609. if ( W )
  610. {
  611. ++W;
  612. sequence()->damage( FL_DAMAGE_ALL, x() + w() - W, y(), W, h() );
  613. }
  614. }
  615. return nframes;
  616. }
  617. /** prepare for capturing */
  618. void
  619. Audio_Region::prepare ( void )
  620. {
  621. log_start();
  622. }
  623. /** finalize region capture. Assumes that this *is* a captured region
  624. and that no other regions refer to the same source */
  625. bool
  626. Audio_Region::finalize ( nframes_t frame )
  627. {
  628. log_end();
  629. _clip->close();
  630. _clip->open();
  631. /* FIXME: should we attempt to truncate the file? */
  632. _range.end = frame - _range.offset;
  633. redraw();
  634. return true;
  635. }