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.

210 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 "JACK_Module.H"
  19. #include <FL/Fl_Single_Window.H>
  20. #include "Engine/Engine.H"
  21. #include "dsp.h"
  22. #include <string.h>
  23. #include "Chain.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()->client(), JACK::Port::Output, chain()->name(), 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()->client(), JACK::Port::Input, chain()->name(), 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. // configure_inputs( 1 );
  124. return true;
  125. }
  126. void
  127. JACK_Module::handle_control_changed ( Port *p )
  128. {
  129. THREAD_ASSERT( UI );
  130. if ( 0 == strcmp( p->name(), "Inputs" ) )
  131. {
  132. DMESSAGE( "Adjusting number of inputs (JACK outputs)" );
  133. configure_inputs( p->control_value() );
  134. if ( chain() )
  135. chain()->configure_ports();
  136. }
  137. else if ( 0 == strcmp( p->name(), "Outputs" ) )
  138. {
  139. DMESSAGE( "Adjusting number of outputs (JACK inputs)" );
  140. if ( ! chain() )
  141. {
  142. configure_outputs( p->control_value() );
  143. }
  144. else if ( chain()->can_configure_outputs( this, p->control_value() ) )
  145. {
  146. configure_outputs( p->control_value() );
  147. chain()->configure_ports();
  148. }
  149. else
  150. {
  151. p->connected_port()->control_value( noutputs() );
  152. }
  153. }
  154. }
  155. void
  156. JACK_Module::handle_chain_name_changed ( void )
  157. {
  158. for ( unsigned int i = 0; i < jack_output.size(); ++i )
  159. jack_output[ i ].name( chain()->name(), i );
  160. for ( unsigned int i = 0; i < jack_input.size(); ++i )
  161. jack_input[ i ].name( chain()->name(), i );
  162. }
  163. void
  164. JACK_Module::process ( void )
  165. {
  166. for ( int i = 0; i < audio_input.size(); ++i )
  167. if ( audio_input[i].connected() )
  168. buffer_copy( (sample_t*)jack_output[i].buffer( nframes() ), (sample_t*)audio_input[i].buffer(), nframes() );
  169. for ( int i = 0; i < audio_output.size(); ++i )
  170. if ( audio_output[i].connected() )
  171. buffer_copy( (sample_t*)audio_output[i].buffer(), (sample_t*)jack_input[i].buffer( nframes() ), nframes() );
  172. }