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.

898 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 "Timeline.H"
  19. #include "Tempo_Sequence.H"
  20. #include "Time_Sequence.H"
  21. #include "Audio_Sequence.H"
  22. #include "Control_Sequence.H"
  23. #include <FL/Fl_Scrollbar.H>
  24. #include "Ruler_Sequence.H"
  25. // #include <FL/Fl_Image.H>
  26. // #include <FL/Fl_RGB_Image.H> // needed for alpha blending
  27. #include "Track.H"
  28. const float UPDATE_FREQ = 0.02f;
  29. #include "Playback_DS.H"
  30. #include "Transport.H"
  31. void
  32. Timeline::cb_scroll ( Fl_Widget *w, void *v )
  33. {
  34. ((Timeline*)v)->cb_scroll( w );
  35. }
  36. void
  37. Timeline::cb_scroll ( Fl_Widget *w )
  38. {
  39. if ( w == vscroll )
  40. {
  41. tracks->position( tracks->x(), (rulers->y() + rulers->h()) - vscroll->value() );
  42. yposition( vscroll->value() );
  43. int rh = h() - rulers->h();
  44. vscroll->value( vscroll->value(), 30, 0, max( tracks->h() - rh, rh) );
  45. }
  46. else
  47. {
  48. if ( hscroll->zoom_changed() )
  49. {
  50. _fpp = hscroll->zoom() * 1;
  51. int maxx = ts_to_x( _length );
  52. hscroll->range( 0, maxx );
  53. redraw();
  54. }
  55. else
  56. {
  57. xposition( hscroll->value() );
  58. }
  59. }
  60. }
  61. Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Window( X, Y, W, H, L )
  62. {
  63. box( FL_FLAT_BOX );
  64. xoffset = 0;
  65. _enable_measure_lines = true;
  66. X = Y = 0;
  67. {
  68. Scalebar *o = new Scalebar( X, Y + H - 18, W - 18, 18 );
  69. o->range( 0, 48000 * 300 );
  70. o->zoom_range( 2, 8192 );
  71. o->zoom( 256 );
  72. o->type( FL_HORIZONTAL );
  73. o->callback( cb_scroll, this );
  74. hscroll = o;
  75. }
  76. {
  77. Fl_Scrollbar *o = new Fl_Scrollbar( X + W - 18, Y, 18, H - 18 );
  78. o->type( FL_VERTICAL );
  79. o->callback( cb_scroll, this );
  80. vscroll = o;
  81. }
  82. {
  83. Fl_Pack *o = new Fl_Pack( X + Track::width(), Y, (W - Track::width()) - vscroll->w(), H - hscroll->h(), "rulers" );
  84. o->type( Fl_Pack::VERTICAL );
  85. {
  86. Tempo_Sequence *o = new Tempo_Sequence( 0, 0, 800, 24 );
  87. o->color( FL_RED );
  88. o->label( "Tempo" );
  89. o->align( FL_ALIGN_LEFT );
  90. tempo_track = o;
  91. }
  92. {
  93. Time_Sequence *o = new Time_Sequence( 0, 24, 800, 24 );
  94. o->color( fl_color_average( FL_RED, FL_WHITE, 0.50f ) );
  95. o->label( "Time" );
  96. o->align( FL_ALIGN_LEFT );
  97. time_track = o;
  98. }
  99. {
  100. Ruler_Sequence *o = new Ruler_Sequence( 0, 24, 800, 24 );
  101. o->color( FL_GREEN );
  102. o->label( "Ruler" );
  103. o->align( FL_ALIGN_LEFT );
  104. ruler_track = o;
  105. }
  106. o->size( o->w(), o->child( 0 )->h() * o->children() );
  107. rulers = o;
  108. o->end();
  109. }
  110. {
  111. _sample_rate = 44100;
  112. _fpp = 256;
  113. _length = _sample_rate * 60 * 2;
  114. {
  115. Fl_Pack *o = new Fl_Pack( X, rulers->y() + rulers->h(), W - vscroll->w(), 5000 );
  116. o->type( Fl_Pack::VERTICAL );
  117. o->spacing( 0 );
  118. tracks = o;
  119. o->end();
  120. resizable( o );
  121. }
  122. }
  123. /* make sure scrollbars are on top */
  124. add( vscroll );
  125. add( hscroll );
  126. vscroll->range( 0, tracks->h() );
  127. redraw();
  128. end();
  129. Fl::add_timeout( UPDATE_FREQ, update_cb, this );
  130. }
  131. float
  132. Timeline::beats_per_minute ( nframes_t when ) const
  133. {
  134. return tempo_track->beats_per_minute( when );
  135. }
  136. int
  137. Timeline::beats_per_bar ( nframes_t when ) const
  138. {
  139. time_sig t = time_track->time( when );
  140. return t.beats_per_bar;
  141. }
  142. void
  143. Timeline::beats_per_minute ( nframes_t when, float bpm )
  144. {
  145. tempo_track->add( new Tempo_Point( when, bpm ) );
  146. }
  147. #if 0
  148. struct BBT
  149. {
  150. int bar, beat, tick;
  151. BBT ( int bar, int beat, int tick ) : bar( bar ), beat( beat ), tick( tick )
  152. {
  153. }
  154. };
  155. /** returns the BBT value for timestamp /when/ by examining the tempo/time maps */
  156. BBT
  157. Timeline::bbt ( nframes_t when )
  158. {
  159. Tempo_Sequence *tempo = (Tempo_Sequence*)rulers->child( 0 );
  160. BBT bbt;
  161. for ( list <Sequence_Widget *>::const_iterator i = tempo.widgets.begin();
  162. i != tempo.widgets.end(); ++i )
  163. {
  164. Tempo_Point *p = *i;
  165. }
  166. };
  167. #endif
  168. /** return the absolute pixel of the nearest measure line to /x/ */
  169. int
  170. Timeline::nearest_line ( int ix )
  171. {
  172. for ( int x = ix - 10; x < ix + 10; ++x )
  173. {
  174. const int measure = ts_to_x( (double)(_sample_rate * 60) / beats_per_minute( x_to_ts( x - Track::width() ) + xoffset ));
  175. // const int abs_x = ts_to_x( xoffset ) + x;
  176. if ( 0 == x % measure )
  177. return x;
  178. }
  179. return -1;
  180. }
  181. /** draw appropriate measure lines inside the given bounding box */
  182. /* FIXME: this function *really* needs to be optimized. Currently it
  183. searched both the time and tempo lists once for every horiontal
  184. pixel and performs a number of calculations--this is slow. */
  185. void
  186. Timeline::draw_measure ( int X, int Y, int W, int H, Fl_Color color, bool BBT )
  187. {
  188. if ( ! _enable_measure_lines )
  189. return;
  190. // fl_line_style( FL_DASH, 2 );
  191. fl_line_style( FL_DASH, 0 );
  192. Fl_Color beat = fl_color_average( FL_BLACK, color, 0.65f );
  193. Fl_Color bar = fl_color_average( FL_RED, color, 0.65f );
  194. int measure;
  195. for ( int x = X; x < X + W; ++x )
  196. {
  197. measure = ts_to_x( (double)(_sample_rate * 60) / beats_per_minute( x_to_ts( x - Track::width() ) + xoffset ) );
  198. const int abs_x = ts_to_x( xoffset ) + x - Track::width();
  199. if ( 0 == abs_x % measure )
  200. {
  201. int bpb = beats_per_bar( x_to_ts( x -Track::width() ) + xoffset );
  202. if ( 0 == (abs_x / measure) % bpb )
  203. {
  204. if ( measure * bpb < 8 )
  205. break;
  206. if ( BBT )
  207. {
  208. fl_font( FL_HELVETICA, 14 );
  209. fl_color( fl_lighter( color ) );
  210. char pat[40];
  211. const nframes_t ts = x_to_ts( abs_x );
  212. // if ( draw_hms )
  213. {
  214. const double seconds = (double)ts / _sample_rate;
  215. int S = (int)seconds;
  216. int M = S / 60; S -= M * 60;
  217. int H = M / 60; M -= H * 60;
  218. snprintf( pat, sizeof( pat ), "%d:%d:%d", H, M, S );
  219. }
  220. // else if ( draw_bbt )
  221. {
  222. /* const int bar = */
  223. /* const int beat; */
  224. /* const int tick = 0; */
  225. /* snprintf( pat, sizeof( pat ), "%d:%d:%d", bar, beat, tick ); */
  226. }
  227. fl_draw( pat, x, Y + 14 );
  228. }
  229. fl_color( bar );
  230. }
  231. else
  232. {
  233. if ( measure < 8 )
  234. continue;
  235. fl_color( beat );
  236. }
  237. fl_line( x, Y, x, Y + H );
  238. }
  239. }
  240. fl_line_style( FL_SOLID, 0 );
  241. }
  242. void
  243. Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
  244. {
  245. draw_measure( X, Y, W, H, color, false );
  246. }
  247. /** just like draw mesure lines except that it also draws the BBT values. */
  248. void
  249. Timeline::draw_measure_BBT ( int X, int Y, int W, int H, Fl_Color color )
  250. {
  251. draw_measure( X, Y, W, H, color, true );
  252. }
  253. void
  254. Timeline::xposition ( int X )
  255. {
  256. // _old_xposition = xoffset;
  257. xoffset = x_to_ts( X );
  258. damage( FL_DAMAGE_SCROLL );
  259. }
  260. void
  261. Timeline::yposition ( int Y )
  262. {
  263. // _old_yposition = _yposition;
  264. _yposition = Y;
  265. damage( FL_DAMAGE_SCROLL );
  266. }
  267. void
  268. Timeline::draw_clip ( void * v, int X, int Y, int W, int H )
  269. {
  270. Timeline *tl = (Timeline *)v;
  271. // printf( "draw_clip: %d,%d %dx%d\n", X, Y, W, H );
  272. fl_push_clip( X, Y, W, H );
  273. fl_color( rand() );
  274. fl_rectf( X, Y, X + W, Y + H );
  275. tl->draw_child( *tl->rulers );
  276. /* headers */
  277. fl_push_clip( tl->tracks->x(), tl->rulers->y() + tl->rulers->h(), Track::width(), tl->h() - tl->rulers->h() - tl->hscroll->h() );
  278. tl->draw_child( *tl->tracks );
  279. fl_pop_clip();
  280. /* track bodies */
  281. fl_push_clip( tl->tracks->x() + Track::width(), tl->rulers->y() + tl->rulers->h(), tl->tracks->w() - Track::width(), tl->h() - tl->rulers->h() - tl->hscroll->h() );
  282. tl->draw_child( *tl->tracks );
  283. fl_pop_clip();
  284. // tl->draw_child( *tl->tracks );
  285. fl_pop_clip();
  286. }
  287. // static unsigned char *rect_image;
  288. void
  289. Timeline::resize ( int X, int Y, int W, int H )
  290. {
  291. Fl_Overlay_Window::resize( X, Y, W, H );
  292. /* why is this necessary? */
  293. rulers->resize( Track::width(), 0, W, rulers->h() );
  294. }
  295. void
  296. Timeline::draw ( void )
  297. {
  298. int X, Y, W, H;
  299. int bdx = 0;
  300. int bdw = 0;
  301. X = tracks->x() + bdx + 1;
  302. Y = tracks->y();
  303. W = tracks->w() - bdw - 1;
  304. H = tracks->h();
  305. /* if ( damage() & FL_DAMAGE_USER1 ) */
  306. /* { */
  307. /* /\* save the rectangle so we can draw it (darkened) in the overlay *\/ */
  308. /* Rectangle &r = _selection; */
  309. /* make_current(); */
  310. /* rect_image = fl_read_image( NULL, r.x, r.y, r.w, r.h, 0 ); */
  311. /* return; */
  312. /* } */
  313. if ( (damage() & FL_DAMAGE_ALL)
  314. ||
  315. damage() & FL_DAMAGE_EXPOSE )
  316. {
  317. draw_box( box(), 0, 0, w(), h(), color() );
  318. fl_push_clip( 0, rulers->y(), w(), rulers->h() );
  319. draw_child( *rulers );
  320. fl_pop_clip();
  321. fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), hscroll->y() - (rulers->y() + rulers->h()) );
  322. draw_child( *tracks );
  323. fl_pop_clip();
  324. draw_child( *hscroll );
  325. draw_child( *vscroll );
  326. redraw_overlay();
  327. /* Rectangle &r = _selection; */
  328. /* unsigned char *data = fl_read_image( NULL, r.x, r.y, r.w, r.h, 0 ); */
  329. /* Fl_RGB_Image bi( data, r.w, r.h, 3 ); */
  330. /* bi.color_average( FL_BLACK, 0.50f ); */
  331. /* bi.draw( r.x, r.y ); */
  332. /* delete[] data; */
  333. /* if ( r.w && r.h ) */
  334. /* { */
  335. /* const unsigned char data[] = { 0, 127, 0, 96, */
  336. /* 0, 96, 0, 127 }; */
  337. /* Fl_RGB_Image bi( data, 2, 2, 2 ); */
  338. /* Fl_Image *bi2 = bi.copy( r.w, r.h ); */
  339. /* bi2->draw( r.x, r.y ); */
  340. /* delete bi2; */
  341. /* } */
  342. return;
  343. }
  344. if ( damage() & FL_DAMAGE_CHILD )
  345. {
  346. // draw_box( box(), 0, 0, w(), h(), color() );
  347. fl_push_clip( rulers->x(), rulers->y(), rulers->w() - vscroll->w(), rulers->h() );
  348. update_child( *rulers );
  349. fl_pop_clip();
  350. fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), hscroll->y() - (rulers->y() + rulers->h()) );
  351. update_child( *tracks );
  352. fl_pop_clip();
  353. update_child( *hscroll );
  354. update_child( *vscroll );
  355. }
  356. if ( damage() & FL_DAMAGE_SCROLL )
  357. {
  358. int dx = ts_to_x( _old_xposition ) - ts_to_x( xoffset );
  359. int dy = _old_yposition - _yposition;
  360. if ( ! dy )
  361. fl_scroll( X + Track::width(), rulers->y(), rulers->w(), rulers->h(), dx, 0, draw_clip, this );
  362. Y = rulers->y() + rulers->h();
  363. H = h() - rulers->h() - hscroll->h();
  364. if ( dy == 0 )
  365. fl_scroll( X + Track::width(), Y, W - Track::width(), H, dx, dy, draw_clip, this );
  366. else
  367. fl_scroll( X, Y, W, H, dx, dy, draw_clip, this );
  368. _old_xposition = xoffset;
  369. _old_yposition = _yposition;
  370. }
  371. }
  372. void
  373. Timeline::draw_playhead ( void )
  374. {
  375. int x = ( ts_to_x( transport->frame ) - ts_to_x( xoffset ) ) + tracks->x() + Track::width();
  376. if ( x < tracks->x() + Track::width() || x > tracks->x() + tracks->w() )
  377. return;
  378. fl_color( FL_RED );
  379. int y = rulers->y() + rulers->h();
  380. int h = this->h() - hscroll->h();
  381. fl_rectf( x - 2, y, 5, 2 );
  382. fl_line( x, y, x, h );
  383. fl_color( fl_darker( FL_RED ) );
  384. fl_line( x - 1, y, x - 1, h );
  385. fl_color( FL_BLACK );
  386. fl_line( x + 1, y, x + 1, h );
  387. }
  388. void
  389. Timeline::redraw_playhead ( void )
  390. {
  391. static nframes_t last_playhead = -1;
  392. if ( last_playhead != transport->frame )
  393. {
  394. redraw_overlay();
  395. last_playhead = transport->frame;
  396. }
  397. }
  398. /** called so many times a second to redraw the playhead etc. */
  399. void
  400. Timeline::update_cb ( void *arg )
  401. {
  402. Fl::repeat_timeout( UPDATE_FREQ, update_cb, arg );
  403. Timeline *tl = (Timeline *)arg;
  404. tl->redraw_playhead();
  405. }
  406. void
  407. Timeline::draw_overlay ( void )
  408. {
  409. draw_playhead();
  410. if ( ! ( _selection.w && _selection.h ) )
  411. return;
  412. fl_push_clip( tracks->x() + Track::width(), rulers->y() + rulers->h(), tracks->w() - Track::width(), h() - rulers->h() - hscroll->h() );
  413. const Rectangle &r = _selection;
  414. fl_color( FL_BLACK );
  415. fl_line_style( FL_SOLID, 2 );
  416. fl_rect( r.x + 2, r.y + 2, r.w, r.h );
  417. fl_color( FL_MAGENTA );
  418. fl_line_style( FL_DASH, 2 );
  419. fl_rect( r.x, r.y, r.w, r.h );
  420. fl_line( r.x, r.y, r.x + r.w, r.y + r.h );
  421. fl_line( r.x + r.w, r.y, r.x, r.y + r.h );
  422. /* fl_overlay_rect( r.x, r.y, r.w, r.h ); */
  423. fl_line_style( FL_SOLID, 0 );
  424. /* const unsigned char data[] = { 127, 127, 127, 96, */
  425. /* 127, 96, 127, 40 }; */
  426. /* Fl_RGB_Image bi( data, 2, 2, 2 ); */
  427. /* Fl_Image *bi2 = bi.copy( r.w, r.h ); */
  428. /* bi2->draw( r.x, r.y ); */
  429. /* delete bi2; */
  430. /* unsigned char *data = fl_read_image( NULL, r.x, r.y, r.w, r.h, 0 ); */
  431. /* Fl_RGB_Image bi( rect_image, r.w, r.h, 3 ); */
  432. /* bi.color_average( FL_BLACK, 0.50f ); */
  433. /* bi.draw( r.x, r.y ); */
  434. /* delete[] rect_image; */
  435. /* rect_image = NULL; */
  436. fl_pop_clip();
  437. }
  438. // #include "Sequence_Widget.H"
  439. /** select all widgets in inside rectangle /r/ */
  440. void
  441. Timeline::select( const Rectangle &r )
  442. {
  443. const int Y = r.y;
  444. for ( int i = tracks->children(); i-- ; )
  445. {
  446. Track *t = (Track*)tracks->child( i );
  447. if ( ! ( t->y() > Y + r.h || t->y() + t->h() < Y ) )
  448. t->track()->select_range( r.x, r.w );
  449. }
  450. }
  451. int
  452. Timeline::handle ( int m )
  453. {
  454. static Drag *drag = NULL;
  455. switch ( m )
  456. {
  457. case FL_KEYBOARD:
  458. {
  459. switch ( Fl::event_key() )
  460. {
  461. case FL_Delete:
  462. {
  463. Sequence_Widget::delete_selected();
  464. return 1;
  465. }
  466. /* case FL_Home: */
  467. /* transport->locate( 0 ); */
  468. /* return 1; */
  469. /* case ' ': */
  470. /* transport->toggle(); */
  471. /* return 1; */
  472. case 'p':
  473. {
  474. int X = Fl::event_x() - Track::width();
  475. if ( X > 0 )
  476. {
  477. transport->locate( xoffset + x_to_ts( X ) );
  478. }
  479. return 1;
  480. }
  481. default:
  482. return Fl_Overlay_Window::handle( m );
  483. }
  484. return 0;
  485. }
  486. default:
  487. {
  488. int r = Fl_Overlay_Window::handle( m );
  489. if ( m != FL_RELEASE && r )
  490. return r;
  491. const int X = Fl::event_x();
  492. const int Y = Fl::event_y();
  493. switch ( m )
  494. {
  495. case FL_PUSH:
  496. {
  497. take_focus();
  498. if ( Fl::event_button1() )
  499. {
  500. assert( ! drag );
  501. drag = new Drag( X - x(), Y - y() );
  502. _selection.x = drag->x;
  503. _selection.y = drag->y;
  504. }
  505. else if ( Fl::event_button3() )
  506. {
  507. Fl_Menu_Item menu[] =
  508. {
  509. { "Add Track", 0, 0, 0, FL_SUBMENU },
  510. { "Audio", 0, 0, 0 },
  511. { 0 },
  512. { 0 },
  513. };
  514. const Fl_Menu_Item *r = menu->popup( X, Y, "Timeline" );
  515. if ( r == &menu[1] )
  516. {
  517. /* FIXME: prompt for I/O config? */
  518. Loggable::block_start();
  519. /* add audio track */
  520. char *name = get_unique_track_name( "Audio" );
  521. Track *t = new Track( name );
  522. add_track( t );
  523. Sequence *o = new Audio_Sequence( t );
  524. new Control_Sequence( t );
  525. t->track( o );
  526. /* t->add( new Control_Sequence( t ); */
  527. t->color( (Fl_Color)rand() );
  528. Loggable::block_end();
  529. }
  530. }
  531. else
  532. return 0;
  533. break;
  534. }
  535. case FL_DRAG:
  536. {
  537. int ox = X - drag->x;
  538. int oy = Y - drag->y;
  539. if ( ox < 0 )
  540. _selection.x = X;
  541. if ( oy < 0 )
  542. _selection.y = Y;
  543. _selection.w = abs( ox );
  544. _selection.h = abs( oy );
  545. break;
  546. }
  547. case FL_RELEASE:
  548. {
  549. delete drag;
  550. drag = NULL;
  551. select( _selection );
  552. _selection.w = _selection.h = 0;
  553. break;
  554. }
  555. default:
  556. return 0;
  557. break;
  558. }
  559. redraw_overlay();
  560. return 1;
  561. }
  562. }
  563. }
  564. Track *
  565. Timeline::track_by_name ( const char *name )
  566. {
  567. for ( int i = tracks->children(); i-- ; )
  568. {
  569. Track *t = (Track*)tracks->child( i );
  570. if ( ! strcmp( name, t->name() ) )
  571. return t;
  572. }
  573. return NULL;
  574. }
  575. char *
  576. Timeline::get_unique_track_name ( const char *name )
  577. {
  578. char pat[256];
  579. strcpy( pat, name );
  580. for ( int i = 1; track_by_name( pat ); ++i )
  581. snprintf( pat, sizeof( pat ), "%s.%d", name, i );
  582. return strdup( pat );
  583. }
  584. void
  585. Timeline::add_track ( Track *track )
  586. {
  587. printf( "added new track to the timeline\n" );
  588. /* FIXME: do locking */
  589. tracks->add( track );
  590. /* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */
  591. redraw();
  592. }
  593. void
  594. Timeline::remove_track ( Track *track )
  595. {
  596. printf( "removed track from the timeline\n" );
  597. /* FIXME: do locking */
  598. /* FIXME: what to do about track contents? */
  599. tracks->remove( track );
  600. /* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */
  601. redraw();
  602. }
  603. /**********/
  604. /* Engine */
  605. /**********/
  606. /** call process() on each track header */
  607. nframes_t
  608. Timeline::process ( nframes_t nframes )
  609. {
  610. for ( int i = tracks->children(); i-- ; )
  611. {
  612. Track *t = (Track*)tracks->child( i );
  613. t->process( nframes );
  614. }
  615. /* FIXME: BOGUS */
  616. return nframes;
  617. }
  618. /* THREAD: RT */
  619. void
  620. Timeline::seek ( nframes_t frame )
  621. {
  622. for ( int i = tracks->children(); i-- ; )
  623. {
  624. Track *t = (Track*)tracks->child( i );
  625. t->seek( frame );
  626. }
  627. }
  628. /* THREAD: RT */
  629. int
  630. Timeline::seek_pending ( void )
  631. {
  632. int r = 0;
  633. for ( int i = tracks->children(); i-- ; )
  634. {
  635. Track *t = (Track*)tracks->child( i );
  636. if ( t->playback_ds )
  637. r += t->playback_ds->buffer_percent() < 50;
  638. }
  639. }