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.

783 lines
21KB

  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 <FL/fl_draw.H>
  19. #include <FL/Fl.H>
  20. #include <FL/Fl_Widget.H>
  21. #include <FL/Fl_Menu_Item.H>
  22. #include <FL/fl_show_colormap.H>
  23. #include "Sequence.H"
  24. #include "Audio_Region.H"
  25. #include "Timeline.H"
  26. #include "Waveform.H"
  27. #include "Audio_Sequence.H"
  28. #include "Track.H"
  29. #include "Engine/Audio_File.H"
  30. #include <algorithm>
  31. using std::min;
  32. using std::max;
  33. extern Timeline *timeline;
  34. bool Audio_Region::inherit_track_color = true;
  35. Fl_Boxtype Audio_Region::_box = FL_UP_BOX;
  36. Fl_Color Audio_Region::_selection_color = FL_MAGENTA;
  37. static Fl_Color fl_invert_color ( Fl_Color c )
  38. {
  39. unsigned char r, g, b;
  40. Fl::get_color( c, r, g, b );
  41. return fl_rgb_color( 255 - r, 255 - g, 255 - b );
  42. }
  43. void
  44. Audio_Region::get ( Log_Entry &e ) const
  45. {
  46. e.add( ":source", _clip ? _clip->name() : "" );
  47. e.add( ":gain", _scale );
  48. e.add( ":fade-in-type", _fade_in.type );
  49. e.add( ":fade-in-duration", _fade_in.length );
  50. e.add( ":fade-out-type", _fade_out.type );
  51. e.add( ":fade-out-duration", _fade_out.length );
  52. Sequence_Region::get( e );
  53. e.add( ":offset", _r->offset );
  54. e.add( ":loop", _loop );
  55. }
  56. void
  57. Audio_Region::set ( Log_Entry &e )
  58. {
  59. for ( int i = 0; i < e.size(); ++i )
  60. {
  61. const char *s, *v;
  62. e.get( i, &s, &v );
  63. if ( ! strcmp( s, ":gain" ) )
  64. _scale = atof( v );
  65. else if ( ! strcmp( s, ":color" ) )
  66. _box_color = (Fl_Color)atoi( v );
  67. else if ( ! strcmp( s, ":fade-in-type" ) )
  68. _fade_in.type = (Fade::fade_type_e)atoi( v );
  69. else if ( ! strcmp( s, ":fade-in-duration" ) )
  70. _fade_in.length = atoll( v );
  71. else if ( ! strcmp( s, ":fade-out-type" ) )
  72. _fade_out.type = (Fade::fade_type_e)atoi( v );
  73. else if ( ! strcmp( s, ":fade-out-duration" ) )
  74. _fade_out.length = atoll( v );
  75. else if ( ! strcmp( s, ":offset" ) )
  76. _r->offset = atoll( v );
  77. else if ( ! strcmp( s, ":loop" ) )
  78. _loop = atoll( v );
  79. else if ( ! strcmp( s, ":source" ) )
  80. {
  81. if ( ! ( _clip = Audio_File::from_file( v ) ) )
  82. {
  83. printf( "Grave error: could not open source \"%s\"\n", v );
  84. }
  85. }
  86. }
  87. Sequence_Region::set( e );
  88. }
  89. void
  90. Audio_Region::init ( void )
  91. {
  92. _loop = 0;
  93. _sequence = NULL;
  94. _scale = 1.0f;
  95. _clip = NULL;
  96. _box_color = FL_CYAN;
  97. _color = FL_BLUE;
  98. _fade_in.length = 256;
  99. _fade_in.type = Fade::Sigmoid;
  100. _fade_out = _fade_in;
  101. }
  102. /* copy constructor */
  103. Audio_Region::Audio_Region ( const Audio_Region & rhs ) : Sequence_Region( rhs )
  104. {
  105. // *((Sequence_Region*)this) = (Sequence_Region &)rhs;
  106. _clip = rhs._clip->duplicate();
  107. _scale = rhs._scale;
  108. _fade_in = rhs._fade_in;
  109. _fade_out = rhs._fade_out;
  110. _loop = rhs._loop;
  111. log_create();
  112. }
  113. /* */
  114. Audio_Region::Audio_Region ( Audio_File *c )
  115. {
  116. init();
  117. _clip = c;
  118. _r->length = _clip->length();
  119. log_create();
  120. }
  121. /* used when DND importing */
  122. Audio_Region::Audio_Region ( Audio_File *c, Sequence *t, nframes_t o )
  123. {
  124. init();
  125. _clip = c;
  126. _sequence = t;
  127. _r->offset = 0;
  128. _r->start = o;
  129. _r->length = _clip->length();
  130. sequence()->add( this );
  131. int sum = 0;
  132. const char *s = rindex( _clip->name(), '/' );
  133. if ( ! s )
  134. s = _clip->name();
  135. for ( int i = strlen( s ); i--; )
  136. sum += s[ i ];
  137. while ( sum >> 8 )
  138. sum = (sum & 0xFF) + (sum >> 8);
  139. _color = (Fl_Color)sum;
  140. /* _color = fl_color_average( FL_YELLOW, (Fl_Color)sum, 0.80 ); */
  141. // _color = FL_YELLOW;
  142. _box_color = FL_WHITE;
  143. log_create();
  144. }
  145. Audio_Region::~Audio_Region ( )
  146. {
  147. log_destroy();
  148. _clip->release();
  149. }
  150. void
  151. Audio_Region::menu_cb ( Fl_Widget *w, void *v )
  152. {
  153. ((Audio_Region*)v)->menu_cb( (Fl_Menu_*) w );
  154. }
  155. void
  156. Audio_Region::menu_cb ( const Fl_Menu_ *m )
  157. {
  158. char picked[256];
  159. m->item_pathname( picked, sizeof( picked ) );
  160. Logger log( this );
  161. if ( ! strcmp( picked, "Fade/In/Linear" ) )
  162. _fade_in.type = Fade::Linear;
  163. else if ( ! strcmp( picked, "Fade/In/Sigmoid" ) )
  164. _fade_in.type = Fade::Sigmoid;
  165. else if ( ! strcmp( picked, "Fade/In/Logarithmic" ) )
  166. _fade_in.type = Fade::Logarithmic;
  167. else if ( ! strcmp( picked, "Fade/In/Parabolic" ) )
  168. _fade_in.type = Fade::Parabolic;
  169. else if ( ! strcmp( picked, "Fade/Out/Linear" ) )
  170. _fade_out.type = Fade::Linear;
  171. else if ( ! strcmp( picked, "Fade/Out/Sigmoid" ) )
  172. _fade_out.type = Fade::Sigmoid;
  173. else if ( ! strcmp( picked, "Fade/Out/Logarithmic" ) )
  174. _fade_out.type = Fade::Logarithmic;
  175. else if ( ! strcmp( picked, "Fade/Out/Parabolic" ) )
  176. _fade_out.type = Fade::Parabolic;
  177. else if ( ! strcmp( picked, "/Color" ) )
  178. box_color( fl_show_colormap( box_color() ) );
  179. else if ( ! strcmp( picked, "/Fade in to mouse" ) )
  180. {
  181. nframes_t offset = x_to_offset( Fl::event_x() );
  182. if ( offset < length() )
  183. _fade_in.length = offset;
  184. DMESSAGE( "set fade in duration" );
  185. }
  186. else if ( ! strcmp( picked, "/Fade out to mouse" ) )
  187. {
  188. long offset = length() - x_to_offset( Fl::event_x() );
  189. if ( offset > 0 )
  190. _fade_out.length = offset;
  191. }
  192. else if ( ! strcmp( picked, "/Loop point to mouse" ) )
  193. {
  194. nframes_t offset = x_to_offset( Fl::event_x() );
  195. if ( offset > 0 )
  196. {
  197. nframes_t f = offset + _r->start;
  198. if ( timeline->nearest_line( &f, false ) )
  199. _loop = f - _r->start;
  200. else
  201. _loop = offset;
  202. }
  203. }
  204. else if ( ! strcmp( picked, "/Clear loop point" ) )
  205. _loop = 0;
  206. else if ( ! strcmp( picked, "/Normalize" ) )
  207. normalize();
  208. else if ( ! strcmp( picked, "/Remove" ) )
  209. remove();
  210. else
  211. FATAL( "Unknown menu choice \"%s\"", picked );
  212. redraw();
  213. }
  214. #include "FL/test_press.H"
  215. #include "FL/menu_popup.H"
  216. /** build the context menu for this region */
  217. Fl_Menu_Button &
  218. Audio_Region::menu ( void )
  219. {
  220. static Fl_Menu_Button m( 0, 0, 0, 0, "Region" );
  221. Fade::fade_type_e it = _fade_in.type;
  222. Fade::fade_type_e ot = _fade_out.type;
  223. Fl_Menu_Item items[] =
  224. {
  225. { "Fade", 0, 0, 0, FL_SUBMENU },
  226. { "In", 0, 0, 0, FL_SUBMENU },
  227. { "Linear", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Linear ? FL_MENU_VALUE : 0 ) },
  228. { "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
  229. { "Logarithmic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
  230. { "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
  231. { 0 },
  232. { "Out", 0, 0, 0, FL_SUBMENU },
  233. { "Linear", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Linear ? FL_MENU_VALUE : 0 ) },
  234. { "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
  235. { "Logarithmic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
  236. { "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
  237. { 0 },
  238. { 0 },
  239. { "Color", 0, 0, 0, inherit_track_color ? FL_MENU_INACTIVE : 0 },
  240. { "Fade in to mouse", FL_F + 3, 0, 0 },
  241. { "Fade out to mouse", FL_F + 4, 0, 0 },
  242. { "Loop point to mouse", 'l', 0, 0 },
  243. { "Clear loop point", FL_SHIFT + 'l', 0, 0 },
  244. { "Normalize", 'n', 0, 0 },
  245. { "Remove", 0, 0, 0 },
  246. { 0 },
  247. };
  248. menu_set_callback( items, &Audio_Region::menu_cb, (void*)this );
  249. m.copy( items, (void*)this );
  250. return m;
  251. }
  252. /** Draws the curve for a single fade. /X/ and /W/ repersent the
  253. portion of the region covered by this draw, which may or may not
  254. cover the fade in question. */
  255. void
  256. Audio_Region::draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool line, int X, int W )
  257. {
  258. const int dy = y() + Fl::box_dy( box() );
  259. const int dh = h() - Fl::box_dh( box() );
  260. const int height = dh;
  261. const int width = timeline->ts_to_x( fade.length );
  262. fl_color( fl_lighter( FL_BLACK ) );
  263. fl_push_matrix();
  264. if ( dir == Fade::In )
  265. fl_translate( line_x(), dy );
  266. else
  267. {
  268. fl_translate( line_x() + abs_w(), dy );
  269. /* flip */
  270. fl_scale( -1.0, 1.0 );
  271. }
  272. fl_scale( width, height );
  273. if ( line )
  274. fl_begin_line();
  275. else
  276. fl_begin_polygon();
  277. fl_vertex( 0.0, 0.0 );
  278. fl_vertex( 0.0, 1.0 );
  279. // if ( draw_real_fade_curve )
  280. {
  281. nframes_t tsx = timeline->x_to_ts( 1 );
  282. nframes_t ts = 0;
  283. for ( int i = 0; i < width; ++i, ts += tsx )
  284. fl_vertex( i / (float)width, 1.0f - fade.gain( ts / (float)fade.length ) );
  285. }
  286. fl_vertex( 1.0, 0.0 );
  287. if ( line )
  288. fl_end_line();
  289. else
  290. fl_end_polygon();
  291. fl_pop_matrix();
  292. }
  293. struct Peaks_Redraw_Request {
  294. Audio_Region *region;
  295. nframes_t start;
  296. nframes_t end;
  297. Peaks_Redraw_Request ( Audio_Region *region, nframes_t start, nframes_t end ) : region( region ), start( start), end( end )
  298. {
  299. }
  300. };
  301. /* static wrapper */
  302. void
  303. Audio_Region::peaks_pending_cb ( void *v )
  304. {
  305. Peaks_Redraw_Request *r = (Peaks_Redraw_Request*)v;
  306. r->region->peaks_pending_cb( r );
  307. }
  308. void
  309. Audio_Region::peaks_pending_cb ( Peaks_Redraw_Request *r )
  310. {
  311. int npeaks = timeline->ts_to_x( r->end - r->start );
  312. if ( _clip->peaks()->ready( r->start, npeaks, timeline->fpp() ) )
  313. {
  314. printf( "damaging from timeout\n" );
  315. /* FIXME: only need to damage the affected area! */
  316. timeline->damage( FL_DAMAGE_ALL, x(), y(), w(), h() );
  317. delete r;
  318. }
  319. else
  320. Fl::repeat_timeout( 0.1f, &Audio_Region::peaks_pending_cb, (void*)r );
  321. }
  322. void
  323. Audio_Region::draw_box( void )
  324. {
  325. /* dirty hack to keep the box from flipping to vertical at small sizes */
  326. fl_push_clip( x(), y(), w(), h() );
  327. Fl_Color selection_color = _selection_color;
  328. Fl_Color color = Audio_Region::inherit_track_color ? sequence()->track()->color() : _box_color;
  329. color = fl_color_average( color, sequence()->color(), 0.75f );
  330. if ( this == ((Audio_Sequence*)sequence())->capture_region() )
  331. {
  332. color = FL_RED;
  333. }
  334. else if ( ! active_r() )
  335. {
  336. color = fl_inactive( color );
  337. selection_color = fl_inactive( selection_color );
  338. }
  339. if ( selected() )
  340. fl_draw_box( fl_down( box() ), x() - ( h() >> 1 ), y(), w() + ( h() >> 1 ) + 50, h(), selection_color );
  341. else
  342. fl_draw_box( box(), x() - ( h() >> 1 ), y(), w() + ( h() >> 1 ) + 50, h(), color );
  343. /* draw fades */
  344. draw_fade( _fade_in, Fade::In, false, x(), w() );
  345. draw_fade( _fade_out, Fade::Out, false, x(), w() );
  346. fl_pop_clip();
  347. }
  348. /** Draw (part of) region. X, Y, W and H are the rectangle we're clipped to. */
  349. void
  350. Audio_Region::draw ( void )
  351. {
  352. /* intersect clip with region */
  353. int X, Y, W, H;
  354. fl_clip_box( x(), y(), w(), h(), X, Y, W, H );
  355. if ( ! ( W > 0 && H > 0 ) )
  356. /* no coverage */
  357. return;
  358. if ( start() > timeline->xoffset + timeline->x_to_ts( sequence()->w() ) ||
  359. start() + length() < timeline->xoffset )
  360. /* not in viewport */
  361. return;
  362. fl_push_clip( X, Y, W, H );
  363. /* account for waveform outlines... */
  364. X -= 2;
  365. W += 4;
  366. /* start with region length... */
  367. // int rw = timeline->ts_to_x( min( length(), timeline->x_to_ts( sequence()->w() ) ) );
  368. int rw = W;
  369. /* calculate waveform offset due to scrolling */
  370. nframes_t offset = 0;
  371. if ( start() < timeline->xoffset )
  372. {
  373. offset = timeline->xoffset - start();
  374. // rw -= timeline->ts_to_x( offset );
  375. }
  376. /* DMESSAGE( "rw = %d", rw ); */
  377. const int rx = x();
  378. /* fl_color( FL_RED ); */
  379. /* fl_line( rx + rw, y(), rx + rw, y() + h() ); */
  380. /* draw fade curve outlines--this is only here because of crossfades */
  381. draw_fade( _fade_in, Fade::In, true, X, W );
  382. draw_fade( _fade_out, Fade::Out, true, X, W );
  383. int xo = 0;
  384. nframes_t ostart = 0, oend = 0;
  385. const int total_peaks_needed = rw;
  386. /* compensate for scrolling */
  387. if ( X - rx > 0 )
  388. offset += timeline->x_to_ts( X - rx );
  389. do {
  390. int channels;
  391. int peaks;
  392. Peak *pbuf;
  393. nframes_t start = _r->offset;
  394. int loop_peaks_needed = _loop ? timeline->ts_to_x( _loop ) : timeline->ts_to_x( _clip->length() );
  395. if ( ! loop_peaks_needed )
  396. break;
  397. if ( ! xo ) /* first loop... */
  398. {
  399. if ( _loop )
  400. start += offset % _loop;
  401. else
  402. start += offset;
  403. /* DMESSAGE( "offset = %lu", (unsigned long) offset ); */
  404. /* DMESSAGE( "loop peaks needed = %d", loop_peaks_needed ); */
  405. loop_peaks_needed -= timeline->ts_to_x( offset % timeline->x_to_ts( loop_peaks_needed ) );
  406. loop_peaks_needed = min( loop_peaks_needed, total_peaks_needed );
  407. /* DMESSAGE( "loop peaks needed = %d", loop_peaks_needed ); */
  408. assert( loop_peaks_needed >= 0 );
  409. if ( _loop && offset < _loop )
  410. {
  411. const int x = timeline->ts_to_x( _loop - offset );
  412. /* FIXME: is there no way to draw these symbols direclty? */
  413. fl_font( FL_SYMBOL, 14 );
  414. fl_color( FL_WHITE );
  415. fl_draw( "@2>", X + x - 7, y(), 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 );
  416. fl_color( FL_WHITE );
  417. fl_draw( "@2<", X + x - 7, y() + h() - 14, 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 );
  418. }
  419. }
  420. if ( xo + loop_peaks_needed > total_peaks_needed )
  421. {
  422. loop_peaks_needed -= ( xo + loop_peaks_needed ) - total_peaks_needed;
  423. }
  424. if ( 0 == loop_peaks_needed )
  425. break;
  426. const nframes_t end = start + timeline->x_to_ts( loop_peaks_needed );
  427. if ( start != ostart || end != oend )
  428. {
  429. if ( _clip->read_peaks( timeline->fpp(),
  430. start,
  431. end,
  432. &peaks, &pbuf, &channels ) )
  433. {
  434. Waveform::scale( pbuf, peaks * channels, _scale );
  435. ostart = start;
  436. oend = end;
  437. }
  438. }
  439. else
  440. {
  441. // DMESSAGE( "using cached peaks" );
  442. }
  443. if ( peaks )
  444. {
  445. assert( pbuf );
  446. int ch = (h() - Fl::box_dh( box() )) / channels;
  447. for ( int i = 0; i < channels; ++i )
  448. {
  449. Waveform::draw( X + xo,
  450. (y() + Fl::box_dy( box() )) + (i * ch),
  451. loop_peaks_needed,
  452. ch,
  453. pbuf + i, peaks, channels,
  454. selected() ? fl_invert_color( _color ) : _color );
  455. }
  456. }
  457. if ( peaks < loop_peaks_needed )
  458. {
  459. /* couldn't read peaks--perhaps they're being generated. Try again later. */
  460. Fl::add_timeout( 0.1f, &Audio_Region::peaks_pending_cb,
  461. new Peaks_Redraw_Request( this, start + timeline->x_to_ts( peaks ), end ) );
  462. }
  463. xo += loop_peaks_needed;
  464. }
  465. while ( _loop && xo < W );
  466. timeline->draw_measure_lines( X, Y, W, H, _box_color );
  467. /* fl_color( FL_BLACK ); */
  468. /* fl_line( rx, Y, rx, Y + H ); */
  469. /* fl_line( rx + rw - 1, Y, rx + rw - 1, Y + H ); */
  470. if ( _clip->dummy() )
  471. {
  472. char pat[256];
  473. snprintf( pat, sizeof( pat ), "Missing Source!: %s", _clip->name() );
  474. draw_label( pat, align() );
  475. }
  476. else
  477. draw_label( _clip->name(), align() );
  478. /* if ( current() ) */
  479. /* { */
  480. /* /\* draw length bubble *\/ */
  481. /* char pat[40]; */
  482. /* snprintf( pat, sizeof( pat ), "%dm:%.1fs", (int)(length() / timeline->sample_rate()) / 60, (double)length() / timeline->sample_rate() ); */
  483. /* draw_label( pat, (Fl_Align)(FL_ALIGN_INSIDE | FL_ALIGN_CENTER), FL_GREEN ); */
  484. /* } */
  485. fl_pop_clip();
  486. }
  487. int
  488. Audio_Region::handle ( int m )
  489. {
  490. static int ox, oy;
  491. static bool copied = false;
  492. static nframes_t os;
  493. int X = Fl::event_x();
  494. int Y = Fl::event_y();
  495. Logger _log( this );
  496. switch ( m )
  497. {
  498. case FL_FOCUS:
  499. case FL_UNFOCUS:
  500. return 1;
  501. case FL_KEYBOARD:
  502. return menu().test_shortcut() != 0;
  503. case FL_ENTER:
  504. return Sequence_Region::handle( m );
  505. case FL_LEAVE:
  506. return Sequence_Region::handle( m );
  507. case FL_PUSH:
  508. {
  509. /* splitting */
  510. if ( test_press( FL_BUTTON2 | FL_SHIFT ) )
  511. {
  512. /* split */
  513. if ( ! copied )
  514. {
  515. Loggable::block_start();
  516. Audio_Region *copy = new Audio_Region( *this );
  517. trim( RIGHT, X );
  518. copy->trim( LEFT, X );
  519. sequence()->add( copy );
  520. log_end();
  521. Loggable::block_end();
  522. }
  523. return 0;
  524. }
  525. else
  526. {
  527. ox = x() - X;
  528. oy = y() - Y;
  529. /* for panning */
  530. os = _r->offset;
  531. if ( test_press( FL_BUTTON2 | FL_CTRL ) )
  532. {
  533. normalize();
  534. return 1;
  535. }
  536. else if ( test_press( FL_BUTTON3 ) )
  537. {
  538. /* context menu */
  539. menu_popup( &menu() );
  540. return 1;
  541. }
  542. else
  543. return Sequence_Region::handle( m );
  544. }
  545. break;
  546. }
  547. case FL_RELEASE:
  548. {
  549. Sequence_Region::handle( m );
  550. copied = false;
  551. return 1;
  552. }
  553. case FL_DRAG:
  554. if ( ! _drag )
  555. {
  556. begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  557. _log.hold();
  558. }
  559. if ( test_press( FL_BUTTON1 | FL_SHIFT | FL_CTRL ) )
  560. {
  561. /* panning */
  562. int d = (ox + X) - x();
  563. long td = timeline->x_to_ts( d );
  564. if ( td > 0 && os < (nframes_t)td )
  565. _r->offset = 0;
  566. else
  567. _r->offset = os - td;
  568. redraw();
  569. return 1;
  570. }
  571. return Sequence_Region::handle( m );
  572. default:
  573. return Sequence_Region::handle( m );
  574. break;
  575. }
  576. return 0;
  577. }
  578. /**********/
  579. /* Public */
  580. /**********/
  581. /** return the name of the audio source this region represents */
  582. const char *
  583. Audio_Region::source_name ( void ) const
  584. {
  585. return _clip->name();
  586. }
  587. /** set the amplitude scaling for this region from the normalization
  588. * factor for the range of samples represented by this region */
  589. void
  590. Audio_Region::normalize ( void )
  591. {
  592. int peaks, channels;
  593. Peak *pbuf;
  594. if ( _clip->read_peaks( length(), offset(), offset() + length(), &peaks, &pbuf, &channels ) &&
  595. peaks )
  596. _scale = pbuf->normalization_factor();
  597. /* FIXME: wrong place for this? */
  598. sequence()->handle_widget_change( start(), length() );
  599. redraw();
  600. }