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.

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