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.

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