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.

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