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.

200 lines
5.4KB

  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.connect_to( new float );
  34. p.control_value_no_callback( 0 );
  35. add_port( p );
  36. }
  37. {
  38. Port p( this, Port::INPUT, Port::CONTROL, "Outputs" );
  39. p.hints.type = Port::Hints::INTEGER;
  40. p.hints.minimum = 0;
  41. p.hints.maximum = 6;
  42. p.connect_to( new float );
  43. p.control_value_no_callback( 0 );
  44. add_port( p );
  45. }
  46. end();
  47. log_create();
  48. }
  49. JACK_Module::~JACK_Module ( )
  50. {
  51. log_destroy();
  52. configure_inputs( 0 );
  53. configure_outputs( 0 );
  54. }
  55. int
  56. JACK_Module::can_support_inputs ( int n )
  57. {
  58. return audio_output.size();
  59. }
  60. bool
  61. JACK_Module::configure_inputs ( int n )
  62. {
  63. int on = audio_input.size();
  64. if ( n > on )
  65. {
  66. for ( int i = on; i < n; ++i )
  67. {
  68. JACK::Port po( engine->client(), JACK::Port::Output, chain()->name(), i );
  69. if ( po.valid() )
  70. {
  71. add_port( Port( this, Port::INPUT, Port::AUDIO ) );
  72. jack_output.push_back( po );
  73. }
  74. }
  75. }
  76. else
  77. {
  78. for ( int i = on; i > n; --i )
  79. {
  80. audio_input.back().disconnect();
  81. audio_input.pop_back();
  82. jack_output.back().shutdown();
  83. jack_output.pop_back();
  84. }
  85. }
  86. control_input[0].control_value_no_callback( n );
  87. return true;
  88. }
  89. bool
  90. JACK_Module::configure_outputs ( int n )
  91. {
  92. int on = audio_output.size();
  93. if ( n > on )
  94. {
  95. for ( int i = on; i < n; ++i )
  96. {
  97. JACK::Port po( engine->client(), JACK::Port::Input, chain()->name(), i );
  98. if ( po.valid() )
  99. {
  100. add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
  101. jack_input.push_back( po );
  102. }
  103. }
  104. }
  105. else
  106. {
  107. for ( int i = on; i > n; --i )
  108. {
  109. audio_output.back().disconnect();
  110. audio_output.pop_back();
  111. jack_input.back().shutdown();
  112. jack_input.pop_back();
  113. }
  114. }
  115. control_input[1].control_value_no_callback( n );
  116. return true;
  117. }
  118. bool
  119. JACK_Module::initialize ( void )
  120. {
  121. // configure_inputs( 1 );
  122. return true;
  123. }
  124. void
  125. JACK_Module::handle_control_changed ( Port *p )
  126. {
  127. if ( 0 == strcmp( p->name(), "Inputs" ) )
  128. {
  129. DMESSAGE( "Adjusting number of inputs (JACK outputs)" );
  130. configure_inputs( p->control_value() );
  131. if ( chain() )
  132. chain()->configure_ports();
  133. }
  134. else if ( 0 == strcmp( p->name(), "Outputs" ) )
  135. {
  136. DMESSAGE( "Adjusting number of outputs (JACK inputs)" );
  137. if ( chain() && chain()->can_configure_outputs( this, p->control_value() ) )
  138. {
  139. configure_outputs( p->control_value() );
  140. chain()->configure_ports();
  141. }
  142. else
  143. configure_outputs( p->control_value() );
  144. }
  145. }
  146. void
  147. JACK_Module::handle_chain_name_changed ( void )
  148. {
  149. for ( unsigned int i = 0; i < jack_output.size(); ++i )
  150. jack_output[ i ].name( chain()->name(), i );
  151. for ( unsigned int i = 0; i < jack_input.size(); ++i )
  152. jack_input[ i ].name( chain()->name(), i );
  153. }
  154. void
  155. JACK_Module::process ( void )
  156. {
  157. for ( int i = 0; i < audio_input.size(); ++i )
  158. if ( audio_input[i].connected() )
  159. buffer_copy( (sample_t*)jack_output[i].buffer( nframes() ), (sample_t*)audio_input[i].buffer(), nframes() );
  160. for ( int i = 0; i < audio_output.size(); ++i )
  161. if ( audio_output[i].connected() )
  162. buffer_copy( (sample_t*)audio_output[i].buffer(), (sample_t*)jack_input[i].buffer( nframes() ), nframes() );
  163. }