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.

223 lines
4.8KB

  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 "../Transport.H" // for .rolling
  20. #include "../Track.H"
  21. #include "Record_DS.H"
  22. #include "Playback_DS.H"
  23. /** Initiate recording for all armed tracks */
  24. bool
  25. Timeline::record ( void )
  26. {
  27. /* FIXME: right place for this? */
  28. transport->recording = true;
  29. Loggable::block_start();
  30. for ( int i = tracks->children(); i-- ; )
  31. {
  32. Track *t = (Track*)tracks->child( i );
  33. if ( t->armed() && t->record_ds )
  34. t->record_ds->start( transport->frame );
  35. }
  36. deactivate();
  37. return true;
  38. }
  39. /** stop recording for all armed tracks */
  40. void
  41. Timeline::stop ( void )
  42. {
  43. nframes_t frame = transport->frame;
  44. for ( int i = tracks->children(); i-- ; )
  45. {
  46. Track *t = (Track*)tracks->child( i );
  47. if ( t->armed() && t->record_ds )
  48. t->record_ds->stop( frame );
  49. }
  50. Loggable::block_end();
  51. activate();
  52. transport->recording = false;
  53. }
  54. /**********/
  55. /* Engine */
  56. /**********/
  57. /** call process() on each track header */
  58. nframes_t
  59. Timeline::process ( nframes_t nframes )
  60. {
  61. for ( int i = tracks->children(); i-- ; )
  62. {
  63. Track *t = (Track*)tracks->child( i );
  64. t->process( nframes );
  65. }
  66. /* FIXME: BOGUS */
  67. return nframes;
  68. }
  69. /* THREAD: RT */
  70. void
  71. Timeline::seek ( nframes_t frame )
  72. {
  73. for ( int i = tracks->children(); i-- ; )
  74. {
  75. Track *t = (Track*)tracks->child( i );
  76. t->seek( frame );
  77. }
  78. }
  79. /* THREAD: RT (non-RT) */
  80. void
  81. Timeline::resize_buffers ( nframes_t nframes )
  82. {
  83. for ( int i = tracks->children(); i-- ; )
  84. {
  85. Track *t = (Track*)tracks->child( i );
  86. t->resize_buffers( nframes );
  87. }
  88. }
  89. /* THREAD: RT */
  90. int
  91. Timeline::seek_pending ( void )
  92. {
  93. int r = 0;
  94. for ( int i = tracks->children(); i-- ; )
  95. {
  96. Track *t = (Track*)tracks->child( i );
  97. if ( t->playback_ds )
  98. r += t->playback_ds->buffer_percent() < 50;
  99. }
  100. return r;
  101. }
  102. /* FIXME: shouldn't these belong to the engine? */
  103. int
  104. Timeline::total_input_buffer_percent ( void )
  105. {
  106. int r = 0;
  107. int cnt = 0;
  108. for ( int i = tracks->children(); i-- ; )
  109. {
  110. Track *t = (Track*)tracks->child( i );
  111. if ( t->record_ds )
  112. {
  113. ++cnt;
  114. r += t->record_ds->buffer_percent();
  115. }
  116. }
  117. if ( ! cnt )
  118. return 0;
  119. return r / cnt;
  120. }
  121. int
  122. Timeline::total_output_buffer_percent ( void )
  123. {
  124. int r = 0;
  125. int cnt = 0;
  126. for ( int i = tracks->children(); i-- ; )
  127. {
  128. Track *t = (Track*)tracks->child( i );
  129. if ( t->playback_ds )
  130. {
  131. ++cnt;
  132. r += t->playback_ds->buffer_percent();
  133. }
  134. }
  135. if ( ! cnt )
  136. return 0;
  137. return r / cnt;
  138. }
  139. /** wait for I/O threads to fill their buffers */
  140. void
  141. Timeline::wait_for_buffers ( void )
  142. {
  143. while ( total_output_buffer_percent() + total_input_buffer_percent() < 200 )
  144. usleep( 5000 );
  145. }
  146. int
  147. Timeline::total_playback_xruns ( void )
  148. {
  149. int r = 0;
  150. for ( int i = tracks->children(); i-- ; )
  151. {
  152. Track *t = (Track*)tracks->child( i );
  153. if ( t->playback_ds )
  154. r += t->playback_ds->xruns();
  155. }
  156. return r;
  157. }
  158. int
  159. Timeline::total_capture_xruns ( void )
  160. {
  161. int r = 0;
  162. for ( int i = tracks->children(); i-- ; )
  163. {
  164. Track *t = (Track*)tracks->child( i );
  165. if ( t->record_ds )
  166. r += t->record_ds->xruns();
  167. }
  168. return r;
  169. }