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.

258 lines
6.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 "Controller_Module.H"
  19. #include <FL/Fl.H>
  20. #include "FL/Fl_Value_SliderX.H"
  21. #include <FL/Fl_Box.H>
  22. #include <FL/Fl_Counter.H>
  23. #include "FL/Fl_Arc_Dial.H"
  24. #include "FL/Fl_Light_Button.H"
  25. #include "FL/Boxtypes.H"
  26. #include <FL/fl_draw.H>
  27. #include "FL/Fl_Labelpad_Group.H"
  28. #include <stdio.h>
  29. #include "Engine/Engine.H"
  30. #include "Chain.H"
  31. const float CONTROL_UPDATE_FREQ = 0.1f;
  32. Controller_Module::Controller_Module ( int W, int H, const char *L )
  33. : Module ( W, 100, L )
  34. {
  35. // label( "" );
  36. box( FL_NO_BOX );
  37. _pad = true;
  38. control = 0;
  39. control_value =0.0f;
  40. add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
  41. mode( GUI );
  42. // mode( CV );
  43. // configure_inputs( 1 );
  44. end();
  45. Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  46. }
  47. Controller_Module::~Controller_Module ( )
  48. {
  49. Fl::remove_timeout( update_cb, this );
  50. }
  51. void
  52. Controller_Module::update_cb ( void *v )
  53. {
  54. ((Controller_Module*)v)->update_cb();
  55. }
  56. void
  57. Controller_Module::update_cb ( void )
  58. {
  59. Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  60. if ( control && control_output[0].connected() )
  61. control->value(control_value);
  62. }
  63. void
  64. Controller_Module::cb_handle ( Fl_Widget *w, void *v )
  65. {
  66. ((Controller_Module*)v)->cb_handle( w );
  67. }
  68. void
  69. Controller_Module::cb_handle ( Fl_Widget *w )
  70. {
  71. control_value = ((Fl_Valuator*)w)->value();
  72. if ( control_output[0].connected() )
  73. {
  74. control_output[0].control_value( control_value );
  75. Port *p = control_output[0].connected_port();
  76. Module *m = p->module();
  77. m->handle_control_changed( p );
  78. }
  79. }
  80. void
  81. Controller_Module::connect_to ( Port *p )
  82. {
  83. control_output[0].connect_to( p );
  84. if( mode() == CV )
  85. {
  86. engine->lock();
  87. {
  88. char name[256];
  89. snprintf( name, sizeof( name ), "%s-CV", p->name() );
  90. JACK::Port po( engine->client(), JACK::Port::Input, chain()->name(), 0, name );
  91. if ( po.valid() )
  92. {
  93. jack_input.push_back( po );
  94. }
  95. }
  96. engine->unlock();
  97. }
  98. Fl_Widget *w;
  99. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  100. {
  101. Fl_Light_Button *o = new Fl_Light_Button( 0, 0, 40, 40, p->name() );
  102. w = o;
  103. o->value( p->control_value() );
  104. }
  105. else if ( p->hints.type == Module::Port::Hints::INTEGER )
  106. {
  107. Fl_Counter *o = new Fl_Counter(0, 0, 58, 24, p->name() );
  108. control = o;
  109. w = o;
  110. o->type(1);
  111. o->step(1);
  112. if ( p->hints.ranged )
  113. {
  114. o->minimum( p->hints.minimum );
  115. o->maximum( p->hints.maximum );
  116. }
  117. o->value( p->control_value() );
  118. }
  119. else if ( p->hints.type == Module::Port::Hints::LOGARITHMIC )
  120. {
  121. Fl_Value_SliderX *o = new Fl_Value_SliderX(0, 0, 30, 250, p->name() );
  122. control = o;
  123. w = o;
  124. o->type(4);
  125. o->color(FL_GRAY0);
  126. o->selection_color((Fl_Color)1);
  127. o->minimum(1.5);
  128. o->maximum(0);
  129. o->value(1);
  130. o->textsize(14);
  131. // o->type( FL_VERTICAL );
  132. // o->type(1);
  133. if ( p->hints.ranged )
  134. {
  135. o->minimum( p->hints.maximum );
  136. o->maximum( p->hints.minimum );
  137. }
  138. o->value( p->control_value() );
  139. }
  140. else
  141. {
  142. { Fl_Arc_Dial *o = new Fl_Arc_Dial( 0, 0, 40, 40, p->name() );
  143. w = o;
  144. control = o;
  145. if ( p->hints.ranged )
  146. {
  147. o->minimum( p->hints.minimum );
  148. o->maximum( p->hints.maximum );
  149. }
  150. o->box( FL_BURNISHED_OVAL_BOX );
  151. // o->box( FL_OVAL_BOX );
  152. // o->type( FL_FILL_DIAL );
  153. o->color( fl_darker( fl_darker( FL_GRAY ) ) );
  154. o->selection_color( FL_WHITE );
  155. o->value( p->control_value() );
  156. }
  157. }
  158. control_value = p->control_value();
  159. w->align(FL_ALIGN_TOP);
  160. w->labelsize( 10 );
  161. w->callback( cb_handle, this );
  162. if ( _pad )
  163. {
  164. Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( w );
  165. size( flg->w(), flg->h() );
  166. add( flg );
  167. }
  168. else
  169. {
  170. w->resize( x(), y(), this->w(), h() );
  171. add( w );
  172. resizable( w );
  173. }
  174. }
  175. int
  176. Controller_Module::handle ( int m )
  177. {
  178. return Fl_Group::handle( m );
  179. }
  180. void
  181. Controller_Module::process ( void )
  182. {
  183. if ( control_output[0].connected() )
  184. {
  185. float f = control_value;
  186. if ( mode() == CV )
  187. {
  188. f = *((float*)jack_input[0].buffer( engine->nframes() ));
  189. const Port *p = control_output[0].connected_port();
  190. if (p->hints.ranged )
  191. {
  192. // scale value to range.
  193. // we assume that CV values are between 0 and 1
  194. float scale = p->hints.maximum - p->hints.minimum;
  195. float offset = p->hints.minimum;
  196. f = ( f * scale ) + offset;
  197. }
  198. }
  199. // else
  200. // f = *((float*)control_output[0].buffer());
  201. *((float*)control_output[0].buffer()) = f;
  202. control_value = f;
  203. }
  204. }