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.

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