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.

236 lines
6.0KB

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