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.

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