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.

266 lines
6.1KB

  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 "../Track.H"
  19. #include "../Transport.H" // for rolling
  20. #include "../Control_Sequence.H"
  21. #include "Playback_DS.H"
  22. #include "Record_DS.H"
  23. #include "Engine.H"
  24. /**********/
  25. /* Engine */
  26. /**********/
  27. void
  28. Track::update_port_names ( void )
  29. {
  30. for ( unsigned int i = 0; i < output.size(); ++i )
  31. output[ i ].name( name(), i );
  32. for ( unsigned int i = 0; i < input.size(); ++i )
  33. input[ i ].name( name(), i );
  34. for ( unsigned int i = 0; i < control_out.size(); ++i )
  35. control_out[ i ]->name( name(), i, "cv" );
  36. /* /\* tell any attached control sequences to do the same *\/ */
  37. /* for ( int i = control->children(); i-- ) */
  38. /* ((Control_Sequence*)control->child( i ))->update_port_names(); */
  39. }
  40. bool
  41. Track::configure_outputs ( int n )
  42. {
  43. int on = output.size();
  44. if ( n == on )
  45. return true;
  46. // engine->lock();
  47. if ( playback_ds )
  48. {
  49. Playback_DS *ds = playback_ds;
  50. playback_ds = NULL;
  51. ds->shutdown();
  52. delete ds;
  53. }
  54. if ( n > on )
  55. {
  56. for ( int i = on; i < n; ++i )
  57. {
  58. Port p( Port::Output, name(), i );
  59. if ( p.valid() )
  60. output.push_back( p );
  61. else
  62. WARNING( "could not create output port!" );
  63. }
  64. }
  65. else
  66. {
  67. for ( int i = on; i > n; --i )
  68. {
  69. output.back().shutdown();
  70. output.pop_back();
  71. }
  72. }
  73. if ( output.size() )
  74. playback_ds = new Playback_DS( this, engine->frame_rate(), engine->nframes(), output.size() );
  75. // engine->unlock();
  76. /* FIXME: bogus */
  77. return true;
  78. }
  79. bool
  80. Track::configure_inputs ( int n )
  81. {
  82. int on = input.size();
  83. if ( n == on )
  84. return true;
  85. // engine->lock();
  86. if ( record_ds )
  87. {
  88. Record_DS *ds = record_ds;
  89. record_ds = NULL;
  90. ds->shutdown();
  91. delete ds;
  92. }
  93. if ( n > on )
  94. {
  95. for ( int i = on; i < n; ++i )
  96. {
  97. Port p( Port::Input, name(), i );
  98. if ( p.valid() )
  99. input.push_back( p );
  100. else
  101. WARNING( "could not create input port!" );
  102. }
  103. }
  104. else
  105. {
  106. for ( int i = on; i > n; --i )
  107. {
  108. input.back().shutdown();
  109. input.pop_back();
  110. }
  111. }
  112. if ( input.size() )
  113. record_ds = new Record_DS( this, engine->frame_rate(), engine->nframes(), input.size() );
  114. // engine->unlock();
  115. /* FIXME: bogus */
  116. return true;
  117. }
  118. /* THREAD: RT */
  119. nframes_t
  120. Track::process ( nframes_t nframes )
  121. {
  122. if ( ! transport->rolling )
  123. {
  124. for ( int i = output.size(); i--; )
  125. output[ i ].silence( nframes );
  126. for ( int i = input.size(); i--; )
  127. input[ i ].silence( nframes );
  128. /* FIXME: is this really the right thing to do for control ports? */
  129. for ( int i = control_out.size(); i--; )
  130. control_out[ i ]->silence( nframes );
  131. return 0;
  132. }
  133. for ( int i = control->children(); i--; )
  134. ((Control_Sequence*)control->child( i ))->process( nframes );
  135. if ( playback_ds )
  136. {
  137. record_ds->process( nframes );
  138. return playback_ds->process( nframes );
  139. }
  140. else
  141. return 0;
  142. }
  143. /* THREAD: RT */
  144. void
  145. Track::seek ( nframes_t frame )
  146. {
  147. if ( playback_ds )
  148. return playback_ds->seek( frame );
  149. }
  150. /* THREAD: RT (non-RT) */
  151. void
  152. Track::resize_buffers ( nframes_t nframes )
  153. {
  154. if ( record_ds )
  155. record_ds->resize_buffers( nframes );
  156. if ( playback_ds )
  157. playback_ds->resize_buffers( nframes );
  158. }
  159. /* #include "Audio_Region.H" */
  160. #include <time.h>
  161. /** very cheap UUID generator... */
  162. unsigned long long
  163. uuid ( void )
  164. {
  165. time_t t = time( NULL );
  166. return (unsigned long long) t;
  167. }
  168. /* THREAD: IO */
  169. /** create capture region and prepare to record */
  170. void
  171. Track::record ( nframes_t frame )
  172. {
  173. assert( ! _capture );
  174. assert( ! _capture_af );
  175. char pat[256];
  176. snprintf( pat, sizeof( pat ), "%s-%llu", name(), uuid() );
  177. _capture_af = Audio_File_SF::create( pat, engine->sample_rate(), input.size(), Track::capture_format );
  178. if ( ! _capture_af )
  179. {
  180. /* ERROR */
  181. }
  182. /* open it again for reading in the GUI thread */
  183. Audio_File *af = Audio_File::from_file( _capture_af->name() );
  184. _capture = new Audio_Region( af, sequence(), frame );
  185. _capture->prepare();
  186. }
  187. /* THREAD: IO */
  188. /** write a block to the (already opened) capture file */
  189. void
  190. Track::write ( sample_t *buf, nframes_t nframes )
  191. {
  192. nframes_t l = _capture_af->write( buf, nframes );
  193. _capture->write( l );
  194. }
  195. #include <stdio.h>
  196. /* THREAD: IO */
  197. void
  198. Track::stop ( nframes_t frame )
  199. {
  200. _capture->finalize( frame );
  201. _capture = NULL;
  202. _capture_af->finalize();
  203. delete _capture_af;
  204. _capture_af = NULL;
  205. }