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.

301 lines
9.1KB

  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 <FL/fl_draw.H>
  19. #include <FL/Fl_Pack.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/Boxtypes.H"
  25. #include "FL/Fl_Flowpack.H"
  26. #include "FL/Fl_Labelpad_Group.H"
  27. #include "FL/Fl_Choice.H"
  28. #include "Module.H"
  29. #include "Module_Parameter_Editor.H"
  30. #include "Controller_Module.H"
  31. #include "Chain.H"
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <util/debug.h>
  36. #include <math.h>
  37. Module_Parameter_Editor::Module_Parameter_Editor ( Module *module ) : Fl_Double_Window( 0, 0, 800, 600 )
  38. {
  39. _module = module;
  40. _resized = false;
  41. char lab[256];
  42. if ( strcmp( module->name(), module->label() ) )
  43. {
  44. snprintf( lab, sizeof( lab ), "%s : %s", module->name(), module->label() );
  45. }
  46. else
  47. strcpy( lab, module->label() );
  48. char title[512];
  49. snprintf( title, sizeof( title ), "%s - %s - %s", "Mixer", module->chain()->name(), lab );
  50. label( title );
  51. { Fl_Pack *o = main_pack = new Fl_Pack( 0, y(), w(), h() - 10 );
  52. o->type( FL_VERTICAL );
  53. o->label( strdup( lab ) );
  54. o->labeltype( FL_SHADOW_LABEL );
  55. o->labelsize( 18 );
  56. o->align( (Fl_Align)(FL_ALIGN_TOP | FL_ALIGN_RIGHT | FL_ALIGN_INSIDE ) );
  57. { Fl_Pack *o = new Fl_Pack( 0, 0, 50, 25 );
  58. o->type( FL_HORIZONTAL );
  59. o->spacing( 20 );
  60. { Fl_Choice *o = mode_choice = new Fl_Choice( 0, 0, 200, 25 );
  61. o->add( "Knobs" );
  62. o->add( "Horizontal Sliders" );
  63. o->add( "Vertical Sliders" );
  64. o->value( 0 );
  65. o->when( FL_WHEN_CHANGED );
  66. o->callback( cb_mode_handle, this );
  67. }
  68. /* { Fl_Box *o = new Fl_Box( 0, 0, 300, 25 ); */
  69. /* o->box( FL_ROUNDED_BOX ); */
  70. /* o->color( FL_YELLOW ); */
  71. /* o->label( strdup( lab ) ); */
  72. /* o->labeltype( FL_SHADOW_LABEL ); */
  73. /* o->labelsize( 18 ); */
  74. /* o->align( (Fl_Align)(FL_ALIGN_TOP | FL_ALIGN_RIGHT | FL_ALIGN_INSIDE ) ); */
  75. /* // Fl_Group::current()->resizable( o ); */
  76. /* } */
  77. o->end();
  78. }
  79. { Fl_Group *o = new Fl_Group( 0, 0, w(), h() );
  80. { Fl_Flowpack *o = control_pack = new Fl_Flowpack( 50, 0, w() - 100, h() );
  81. /* o->box( FL_ROUNDED_BOX ); */
  82. /* o->color( FL_GRAY ); */
  83. o->vspacing( 10 );
  84. o->hspacing( 10 );
  85. o->end();
  86. }
  87. o->resizable( 0 );
  88. o->end();
  89. }
  90. o->end();
  91. }
  92. end();
  93. // draw();
  94. make_controls();
  95. }
  96. Module_Parameter_Editor::~Module_Parameter_Editor ( )
  97. {
  98. }
  99. void
  100. Module_Parameter_Editor::make_controls ( void )
  101. {
  102. Module *module = _module;
  103. control_pack->clear();
  104. for ( unsigned int i = 0; i < module->control_input.size(); ++i )
  105. {
  106. Fl_Widget *w;
  107. Module::Port *p = &module->control_input[i];
  108. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  109. {
  110. Fl_Button *o = new Fl_Button( 0, 0, 30, 30, p->name() );
  111. w = o;
  112. o->selection_color( FL_GREEN );
  113. o->type( FL_TOGGLE_BUTTON );
  114. o->value( p->control_value() );
  115. }
  116. else if ( p->hints.type == Module::Port::Hints::INTEGER )
  117. {
  118. Fl_Counter *o = new Fl_Counter(0, 0, 58, 24, p->name() );
  119. w = o;
  120. o->type(1);
  121. o->step(1);
  122. if ( p->hints.ranged )
  123. {
  124. o->minimum( p->hints.minimum );
  125. o->maximum( p->hints.maximum );
  126. }
  127. o->value( p->control_value() );
  128. }
  129. else
  130. {
  131. if ( mode_choice->value() == 0 )
  132. {
  133. Fl_Arc_Dial *o = new Fl_Arc_Dial( 0, 0, 50, 50, p->name() );
  134. w = o;
  135. if ( p->hints.ranged )
  136. {
  137. o->minimum( p->hints.minimum );
  138. o->maximum( p->hints.maximum );
  139. }
  140. o->box( FL_BURNISHED_OVAL_BOX );
  141. o->color( fl_darker( fl_darker( FL_GRAY ) ) );
  142. o->selection_color( FL_WHITE );
  143. o->value( p->control_value() );
  144. // o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f );
  145. }
  146. else
  147. {
  148. Fl_Value_SliderX *o = new Fl_Value_SliderX( 0, 0, 120, 24, p->name() );
  149. w = o;
  150. if ( mode_choice->value() == 1 )
  151. {
  152. o->type( FL_HORIZONTAL );
  153. o->size( 120, 24 );
  154. if ( p->hints.ranged )
  155. {
  156. o->minimum( p->hints.minimum );
  157. o->maximum( p->hints.maximum );
  158. }
  159. }
  160. else
  161. {
  162. o->type( FL_VERTICAL );
  163. o->size( 24, 120 );
  164. /* have to reverse the meaning of these to get the
  165. * orientation of the slider right */
  166. o->maximum( p->hints.minimum );
  167. o->minimum( p->hints.maximum );
  168. }
  169. // o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f );
  170. o->slider( FL_THIN_UP_BOX );
  171. o->color( fl_darker( fl_darker( FL_GRAY ) ) );
  172. o->selection_color( FL_WHITE );
  173. o->value( p->control_value() );
  174. }
  175. }
  176. Fl_Button *bound;
  177. w->align(FL_ALIGN_TOP);
  178. w->labelsize( 10 );
  179. w->callback( cb_value_handle, new callback_data( this, i ) );
  180. { Fl_Group *o = new Fl_Group( 0, 0, 50, 75 );
  181. {
  182. Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( w );
  183. { Fl_Button *o = bound = new Fl_Button( 0, 50, 14, 14 );
  184. o->selection_color( FL_YELLOW );
  185. o->type( 0 );
  186. o->labelsize( 8 );
  187. o->value( p->connected() );
  188. o->callback( cb_bound_handle, new callback_data( this, i ) );
  189. }
  190. o->resizable( 0 );
  191. o->end();
  192. flg->position( o->x(), o->y() );
  193. bound->position( o->x(), flg->y() + flg->h() );
  194. o->size( flg->w(), flg->h() + bound->h() );
  195. o->init_sizes();
  196. }
  197. control_pack->add( o );
  198. }
  199. }
  200. main_pack->size( control_pack->max_width() + 100, control_pack->h() + 50 );
  201. size( control_pack->max_width() + 100, control_pack->h() + 50 );
  202. }
  203. void
  204. Module_Parameter_Editor::cb_value_handle ( Fl_Widget *w, void *v )
  205. {
  206. callback_data *cd = (callback_data*)v;
  207. cd->base_widget->set_value( cd->port_number, ((Fl_Valuator*)w)->value() );
  208. }
  209. void
  210. Module_Parameter_Editor::cb_mode_handle ( Fl_Widget *w, void *v )
  211. {
  212. ((Module_Parameter_Editor*)v)->make_controls();
  213. }
  214. void
  215. Module_Parameter_Editor::cb_bound_handle ( Fl_Widget *w, void *v )
  216. {
  217. callback_data *cd = (callback_data*)v;
  218. Fl_Button *fv = (Fl_Button*)w;
  219. fv->value( 1 );
  220. cd->base_widget->bind_control( cd->port_number );
  221. }
  222. void
  223. Module_Parameter_Editor::bind_control ( int i )
  224. {
  225. Module::Port *p = &_module->control_input[i];
  226. if ( p->connected() )
  227. /* can only bind once */
  228. return;
  229. Controller_Module *o = new Controller_Module();
  230. o->label( p->name() );
  231. o->chain( _module->chain() );
  232. o->connect_to( p );
  233. _module->chain()->add_control( o );
  234. _module->redraw();
  235. }
  236. void
  237. Module_Parameter_Editor::set_value (int i, float value )
  238. {
  239. _module->control_input[i].control_value( value );
  240. _module->handle_control_changed( &_module->control_input[i] );
  241. }