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.

265 lines
6.3KB

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