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.

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