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.

450 lines
13KB

  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.H>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <math.h>
  23. #include <FL/fl_draw.H>
  24. #include <FL/Fl_Pack.H>
  25. #include <FL/Fl_Box.H>
  26. #include <FL/Fl_Menu_Button.H>
  27. #include <FL/Fl_Counter.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_Dial.H"
  32. #include "Module.H"
  33. #include "Module_Parameter_Editor.H"
  34. #include "Controller_Module.H"
  35. #include "Chain.H"
  36. #include "Panner.H"
  37. #include "debug.h"
  38. Module_Parameter_Editor::Module_Parameter_Editor ( Module *module ) : Fl_Double_Window( 800, 600 )
  39. {
  40. _module = module;
  41. _resized = false;
  42. _min_width = 100;
  43. char lab[256];
  44. if ( strcmp( module->name(), module->label() ) )
  45. {
  46. snprintf( lab, sizeof( lab ), "%s : %s", module->name(), module->label() );
  47. }
  48. else
  49. strcpy( lab, module->label() );
  50. char title[512];
  51. snprintf( title, sizeof( title ), "%s - %s - %s", "Mixer", module->chain()->name(), lab );
  52. copy_label( title );
  53. fl_font( FL_HELVETICA, 14 );
  54. _min_width = 30 + fl_width( module->label() );
  55. { Fl_Pack *o = main_pack = new Fl_Pack( 0, 0, w(), h() - 10 );
  56. o->type( FL_VERTICAL );
  57. o->label( module->label() );
  58. o->labelfont( 2 );
  59. o->labeltype( FL_SHADOW_LABEL );
  60. o->labelsize( 14 );
  61. o->align( FL_ALIGN_TOP | FL_ALIGN_RIGHT | FL_ALIGN_INSIDE );
  62. { Fl_Pack *o = new Fl_Pack( 0, 0, 50, 25 );
  63. o->type( FL_HORIZONTAL );
  64. o->spacing( 20 );
  65. { Fl_Menu_Button *o = mode_choice = new Fl_Menu_Button( 0, 0, 25, 25 );
  66. o->add( "Knobs" );
  67. o->add( "Horizontal Sliders" );
  68. o->add( "Vertical Sliders" );
  69. o->label( NULL );
  70. o->value( 0 );
  71. o->when( FL_WHEN_CHANGED );
  72. o->callback( cb_mode_handle, this );
  73. }
  74. /* { Fl_Box *o = new Fl_Box( 0, 0, 300, 25 ); */
  75. /* o->box( FL_ROUNDED_BOX ); */
  76. /* o->color( FL_YELLOW ); */
  77. /* o->label( strdup( lab ) ); */
  78. /* o->labeltype( FL_SHADOW_LABEL ); */
  79. /* o->labelsize( 18 ); */
  80. /* o->align( (Fl_Align)(FL_ALIGN_TOP | FL_ALIGN_RIGHT | FL_ALIGN_INSIDE ) ); */
  81. /* // Fl_Group::current()->resizable( o ); */
  82. /* } */
  83. o->end();
  84. }
  85. { Fl_Group *o = new Fl_Group( 0, 0, w(), h() );
  86. { Fl_Flowpack *o = control_pack = new Fl_Flowpack( 50, 0, w() - 100, h() );
  87. /* o->box( FL_ROUNDED_BOX ); */
  88. /* o->color( FL_GRAY ); */
  89. o->vspacing( 10 );
  90. o->hspacing( 10 );
  91. o->end();
  92. }
  93. o->resizable( 0 );
  94. o->end();
  95. }
  96. o->end();
  97. }
  98. end();
  99. // draw();
  100. make_controls();
  101. }
  102. Module_Parameter_Editor::~Module_Parameter_Editor ( )
  103. {
  104. controls_by_port.clear();
  105. }
  106. void
  107. Module_Parameter_Editor::make_controls ( void )
  108. {
  109. Module *module = _module;
  110. control_pack->clear();
  111. controls_by_port.clear();
  112. /* these are for detecting related parameter groups which can be
  113. better represented by a single control */
  114. azimuth_port_number = -1;
  115. float azimuth_value = 0.0f;
  116. elevation_port_number = -1;
  117. float elevation_value = 0.0f;
  118. controls_by_port.resize( module->control_input.size() );
  119. for ( unsigned int i = 0; i < module->control_input.size(); ++i )
  120. {
  121. Fl_Widget *w;
  122. Module::Port *p = &module->control_input[i];
  123. if ( !strcasecmp( "Azimuth", p->name() ) &&
  124. 180.0f == p->hints.maximum &&
  125. -180.0f == p->hints.minimum )
  126. {
  127. azimuth_port_number = i;
  128. azimuth_value = p->control_value();
  129. continue;
  130. }
  131. else if ( !strcasecmp( "Elevation", p->name() ) &&
  132. 90.0f == p->hints.maximum &&
  133. -90.0f == p->hints.minimum )
  134. {
  135. elevation_port_number = i;
  136. elevation_value = p->control_value();
  137. continue;
  138. }
  139. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  140. {
  141. Fl_Button *o = new Fl_Button( 0, 0, 30, 30, p->name() );
  142. w = o;
  143. o->selection_color( FL_GREEN );
  144. o->type( FL_TOGGLE_BUTTON );
  145. o->value( p->control_value() );
  146. }
  147. else if ( p->hints.type == Module::Port::Hints::INTEGER )
  148. {
  149. Fl_Counter *o = new Fl_Counter(0, 0, 58, 24, p->name() );
  150. w = o;
  151. o->type(1);
  152. o->step(1);
  153. if ( p->hints.ranged )
  154. {
  155. o->minimum( p->hints.minimum );
  156. o->maximum( p->hints.maximum );
  157. }
  158. o->value( p->control_value() );
  159. }
  160. else
  161. {
  162. if ( mode_choice->value() == 0 )
  163. {
  164. Fl_Dial *o = new Fl_Dial( 0, 0, 60, 60, p->name() );
  165. w = o;
  166. if ( p->hints.ranged )
  167. {
  168. DMESSAGE( "Min: %f, max: %f", p->hints.minimum, p->hints.maximum );
  169. o->minimum( p->hints.minimum );
  170. o->maximum( p->hints.maximum );
  171. }
  172. o->color( FL_GRAY );
  173. o->selection_color( FL_WHITE );
  174. o->value( p->control_value() );
  175. // o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f );
  176. }
  177. else
  178. {
  179. Fl_Value_SliderX *o = new Fl_Value_SliderX( 0, 0, 120, 24, p->name() );
  180. w = o;
  181. if ( mode_choice->value() == 1 )
  182. {
  183. o->type( FL_HORIZONTAL );
  184. o->size( 120, 36 );
  185. if ( p->hints.ranged )
  186. {
  187. o->minimum( p->hints.minimum );
  188. o->maximum( p->hints.maximum );
  189. }
  190. }
  191. else
  192. {
  193. o->type( FL_VERTICAL );
  194. o->size( 36, 120 );
  195. /* have to reverse the meaning of these to get the
  196. * orientation of the slider right */
  197. o->maximum( p->hints.minimum );
  198. o->minimum( p->hints.maximum );
  199. }
  200. o->slider( FL_UP_BOX );
  201. // o->color( FL_BACKGROUND2_COLOR );
  202. o->color( FL_BACKGROUND2_COLOR );
  203. o->selection_color( FL_WHITE );
  204. o->value( p->control_value() );
  205. }
  206. }
  207. controls_by_port[i] = w;
  208. w->tooltip( p->osc_path() );
  209. Fl_Button *bound;
  210. w->align(FL_ALIGN_TOP);
  211. w->labelsize( 10 );
  212. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  213. w->callback( cb_button_handle, new callback_data( this, i ) );
  214. else
  215. w->callback( cb_value_handle, new callback_data( this, i ) );
  216. { Fl_Group *o = new Fl_Group( 0, 0, 50, 75 );
  217. {
  218. Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( w );
  219. { Fl_Button *o = bound = new Fl_Button( 0, 50, 14, 14 );
  220. o->selection_color( FL_YELLOW );
  221. o->type( 0 );
  222. o->labelsize( 8 );
  223. o->value( p->connected() );
  224. o->callback( cb_bound_handle, new callback_data( this, i ) );
  225. }
  226. o->resizable( 0 );
  227. o->end();
  228. o->set_visible_focus();
  229. flg->set_visible_focus();
  230. flg->position( o->x(), o->y() );
  231. bound->position( o->x(), flg->y() + flg->h() );
  232. o->size( flg->w(), flg->h() + bound->h() );
  233. o->init_sizes();
  234. }
  235. control_pack->add( o );
  236. }
  237. }
  238. if ( azimuth_port_number >= 0 && elevation_port_number >= 0 )
  239. {
  240. Panner *o = new Panner( 0,0, 300, 300 );
  241. o->box(FL_THIN_UP_BOX);
  242. o->color(FL_GRAY0);
  243. o->selection_color(FL_BACKGROUND_COLOR);
  244. o->labeltype(FL_NORMAL_LABEL);
  245. o->labelfont(0);
  246. o->labelcolor(FL_FOREGROUND_COLOR);
  247. o->align(FL_ALIGN_TOP);
  248. o->when(FL_WHEN_CHANGED);
  249. o->label( "Spatialization" );
  250. o->align(FL_ALIGN_TOP);
  251. o->labelsize( 10 );
  252. o->callback( cb_panner_value_handle, new callback_data( this, azimuth_port_number, elevation_port_number ) );
  253. o->point( 0 )->azimuth( azimuth_value );
  254. o->point( 0 )->elevation( elevation_value );
  255. Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( o );
  256. control_pack->add( flg );
  257. controls_by_port[azimuth_port_number] = o;
  258. controls_by_port[elevation_port_number] = o;
  259. }
  260. int width = control_pack->max_width() + 100;
  261. int height = control_pack->h() + 50;
  262. if ( width < _min_width )
  263. width = _min_width;
  264. main_pack->size( width, height );
  265. size( width, height );
  266. size_range( width, height, width, height );
  267. }
  268. void
  269. Module_Parameter_Editor::cb_value_handle ( Fl_Widget *w, void *v )
  270. {
  271. callback_data *cd = (callback_data*)v;
  272. cd->base_widget->set_value( cd->port_number[0], ((Fl_Valuator*)w)->value() );
  273. }
  274. void
  275. Module_Parameter_Editor::cb_button_handle ( Fl_Widget *w, void *v )
  276. {
  277. callback_data *cd = (callback_data*)v;
  278. cd->base_widget->set_value( cd->port_number[0], ((Fl_Button*)w)->value() );
  279. }
  280. void
  281. Module_Parameter_Editor::cb_panner_value_handle ( Fl_Widget *w, void *v )
  282. {
  283. callback_data *cd = (callback_data*)v;
  284. cd->base_widget->set_value( cd->port_number[0], ((Panner*)w)->point( 0 )->azimuth() );
  285. cd->base_widget->set_value( cd->port_number[1], ((Panner*)w)->point( 0 )->elevation() );
  286. }
  287. void
  288. Module_Parameter_Editor::cb_mode_handle ( Fl_Widget *, void *v )
  289. {
  290. ((Module_Parameter_Editor*)v)->make_controls();
  291. }
  292. void
  293. Module_Parameter_Editor::cb_bound_handle ( Fl_Widget *w, void *v )
  294. {
  295. callback_data *cd = (callback_data*)v;
  296. Fl_Button *fv = (Fl_Button*)w;
  297. fv->value( 1 );
  298. cd->base_widget->bind_control( cd->port_number[0] );
  299. }
  300. void
  301. Module_Parameter_Editor::bind_control ( int i )
  302. {
  303. Module::Port *p = &_module->control_input[i];
  304. if ( p->connected() )
  305. /* can only bind once */
  306. return;
  307. Controller_Module *o = new Controller_Module();
  308. o->label( p->name() );
  309. o->chain( _module->chain() );
  310. o->connect_to( p );
  311. _module->chain()->add_control( o );
  312. _module->redraw();
  313. }
  314. /* Display changes initiated via automation or from other parts of the GUI */
  315. void
  316. Module_Parameter_Editor::handle_control_changed ( Module::Port *p )
  317. {
  318. int i = _module->control_input_port_index( p );
  319. Fl_Widget *w = controls_by_port[i];
  320. if ( i == azimuth_port_number ||
  321. i == elevation_port_number )
  322. {
  323. Panner *_panner = (Panner*)w;
  324. if ( i == azimuth_port_number )
  325. _panner->point(0)->azimuth( p->control_value() );
  326. else if ( i == elevation_port_number )
  327. _panner->point(0)->elevation( p->control_value() );
  328. _panner->redraw();
  329. return;
  330. }
  331. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  332. {
  333. Fl_Button *v = (Fl_Button*)w;
  334. v->value( p->control_value() );
  335. }
  336. else
  337. {
  338. Fl_Valuator *v = (Fl_Valuator*)w;
  339. v->value( p->control_value() );
  340. }
  341. }
  342. void
  343. Module_Parameter_Editor::set_value (int i, float value )
  344. {
  345. _module->control_input[i].control_value( value );
  346. if ( _module->control_input[i].connected() )
  347. _module->control_input[i].connected_port()->module()->handle_control_changed( _module->control_input[i].connected_port() );
  348. // _module->handle_control_changed( &_module->control_input[i] );
  349. }