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.

230 lines
4.9KB

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