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.

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