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.

260 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_Slider.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. }
  50. void
  51. Controller_Module::update_cb ( void *v )
  52. {
  53. ((Controller_Module*)v)->update_cb();
  54. }
  55. void
  56. Controller_Module::update_cb ( void )
  57. {
  58. Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  59. if ( control && control_output[0].connected() )
  60. control->value(control_value);
  61. }
  62. void
  63. Controller_Module::cb_handle ( Fl_Widget *w, void *v )
  64. {
  65. ((Controller_Module*)v)->cb_handle( w );
  66. }
  67. void
  68. Controller_Module::cb_handle ( Fl_Widget *w )
  69. {
  70. control_value = ((Fl_Valuator*)w)->value();
  71. if ( control_output[0].connected() )
  72. {
  73. control_output[0].control_value( control_value );
  74. Port *p = control_output[0].connected_port();
  75. Module *m = p->module();
  76. m->handle_control_changed( p );
  77. }
  78. }
  79. void
  80. Controller_Module::connect_to ( Port *p )
  81. {
  82. control_output[0].connect_to( p );
  83. if( mode() == CV )
  84. {
  85. engine->lock();
  86. {
  87. char name[256];
  88. snprintf( name, sizeof( name ), "%s-CV", p->name() );
  89. JACK::Port po( engine->client(), JACK::Port::Input, chain()->name(), 0, name );
  90. if ( po.valid() )
  91. {
  92. jack_input.push_back( po );
  93. }
  94. }
  95. engine->unlock();
  96. }
  97. Fl_Widget *w;
  98. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  99. {
  100. Fl_Light_Button *o = new Fl_Light_Button( 0, 0, 40, 40, p->name() );
  101. w = o;
  102. o->value( p->control_value() );
  103. }
  104. else if ( p->hints.type == Module::Port::Hints::INTEGER )
  105. {
  106. Fl_Counter *o = new Fl_Counter(0, 0, 58, 24, p->name() );
  107. control = o;
  108. w = o;
  109. o->type(1);
  110. o->step(1);
  111. if ( p->hints.ranged )
  112. {
  113. o->minimum( p->hints.minimum );
  114. o->maximum( p->hints.maximum );
  115. }
  116. o->value( p->control_value() );
  117. }
  118. else if ( p->hints.type == Module::Port::Hints::LOGARITHMIC )
  119. {
  120. Fl_Value_Slider *o = new Fl_Value_Slider(0, 0, 30, 250, p->name() );
  121. control = o;
  122. w = o;
  123. o->type(4);
  124. o->color(FL_GRAY0);
  125. o->selection_color((Fl_Color)1);
  126. o->minimum(1.5);
  127. o->maximum(0);
  128. o->step(0.01);
  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. }