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.

188 lines
5.2KB

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