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.

257 lines
6.0KB

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