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.

216 lines
5.6KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2009 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 "const.h"
  19. #include <string.h>
  20. #include "dsp.h"
  21. #include "Engine/Engine.H"
  22. #include "Chain.H"
  23. #include "JACK_Module.H"
  24. JACK_Module::JACK_Module ( )
  25. : Module ( 50, 24, name() )
  26. {
  27. /* FIXME: how do Controls find out that a connected value has changed? How does this work in ladspa? */
  28. {
  29. Port p( this, Port::INPUT, Port::CONTROL, "Inputs" );
  30. p.hints.type = Port::Hints::INTEGER;
  31. p.hints.minimum = 0;
  32. p.hints.maximum = 6;
  33. p.hints.ranged = true;
  34. p.connect_to( new float );
  35. p.control_value_no_callback( 0 );
  36. add_port( p );
  37. }
  38. {
  39. Port p( this, Port::INPUT, Port::CONTROL, "Outputs" );
  40. p.hints.type = Port::Hints::INTEGER;
  41. p.hints.minimum = 0;
  42. p.hints.maximum = 6;
  43. p.hints.ranged = true;
  44. p.connect_to( new float );
  45. p.control_value_no_callback( 0 );
  46. add_port( p );
  47. }
  48. end();
  49. log_create();
  50. }
  51. JACK_Module::~JACK_Module ( )
  52. {
  53. log_destroy();
  54. configure_inputs( 0 );
  55. configure_outputs( 0 );
  56. }
  57. int
  58. JACK_Module::can_support_inputs ( int n )
  59. {
  60. return audio_output.size();
  61. }
  62. bool
  63. JACK_Module::configure_inputs ( int n )
  64. {
  65. int on = audio_input.size();
  66. if ( n > on )
  67. {
  68. for ( int i = on; i < n; ++i )
  69. {
  70. JACK::Port po( chain()->engine(), JACK::Port::Output, i );
  71. if ( po.valid() )
  72. {
  73. add_port( Port( this, Port::INPUT, Port::AUDIO ) );
  74. jack_output.push_back( po );
  75. }
  76. }
  77. }
  78. else
  79. {
  80. for ( int i = on; i > n; --i )
  81. {
  82. audio_input.back().disconnect();
  83. audio_input.pop_back();
  84. jack_output.back().shutdown();
  85. jack_output.pop_back();
  86. }
  87. }
  88. control_input[0].control_value_no_callback( n );
  89. return true;
  90. }
  91. bool
  92. JACK_Module::configure_outputs ( int n )
  93. {
  94. int on = audio_output.size();
  95. if ( n > on )
  96. {
  97. for ( int i = on; i < n; ++i )
  98. {
  99. JACK::Port po( chain()->engine(), JACK::Port::Input, i );
  100. if ( po.valid() )
  101. {
  102. add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
  103. jack_input.push_back( po );
  104. }
  105. }
  106. }
  107. else
  108. {
  109. for ( int i = on; i > n; --i )
  110. {
  111. audio_output.back().disconnect();
  112. audio_output.pop_back();
  113. jack_input.back().shutdown();
  114. jack_input.pop_back();
  115. }
  116. }
  117. control_input[1].control_value_no_callback( n );
  118. return true;
  119. }
  120. bool
  121. JACK_Module::initialize ( void )
  122. {
  123. return true;
  124. }
  125. void
  126. JACK_Module::handle_control_changed ( Port *p )
  127. {
  128. THREAD_ASSERT( UI );
  129. if ( 0 == strcmp( p->name(), "Inputs" ) )
  130. {
  131. DMESSAGE( "Adjusting number of inputs (JACK outputs)" );
  132. configure_inputs( p->control_value() );
  133. if ( chain() )
  134. chain()->configure_ports();
  135. }
  136. else if ( 0 == strcmp( p->name(), "Outputs" ) )
  137. {
  138. DMESSAGE( "Adjusting number of outputs (JACK inputs)" );
  139. if ( ! chain() )
  140. {
  141. configure_outputs( p->control_value() );
  142. }
  143. else if ( chain()->can_configure_outputs( this, p->control_value() ) )
  144. {
  145. configure_outputs( p->control_value() );
  146. chain()->configure_ports();
  147. }
  148. else
  149. {
  150. p->connected_port()->control_value( noutputs() );
  151. }
  152. }
  153. }
  154. void
  155. JACK_Module::handle_chain_name_changed ( void )
  156. {
  157. for ( unsigned int i = 0; i < jack_output.size(); ++i )
  158. jack_output[ i ].name( NULL, i );
  159. for ( unsigned int i = 0; i < jack_input.size(); ++i )
  160. jack_input[ i ].name( NULL, i );
  161. }
  162. /**********/
  163. /* Engine */
  164. /**********/
  165. void
  166. JACK_Module::process ( nframes_t nframes )
  167. {
  168. for ( unsigned int i = 0; i < audio_input.size(); ++i )
  169. if ( audio_input[i].connected() )
  170. buffer_copy( (sample_t*)jack_output[i].buffer( nframes ), (sample_t*)audio_input[i].buffer(), nframes );
  171. for ( unsigned int i = 0; i < audio_output.size(); ++i )
  172. if ( audio_output[i].connected() )
  173. buffer_copy( (sample_t*)audio_output[i].buffer(), (sample_t*)jack_input[i].buffer( nframes ), nframes );
  174. }