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.

458 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_DialX.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. Fl_Color fc = fl_color_add_alpha( FL_CYAN, 200 );
  119. Fl_Color bc = FL_BACKGROUND2_COLOR;
  120. controls_by_port.resize( module->control_input.size() );
  121. for ( unsigned int i = 0; i < module->control_input.size(); ++i )
  122. {
  123. Fl_Widget *w;
  124. Module::Port *p = &module->control_input[i];
  125. if ( !p->hints.visible )
  126. continue;
  127. if ( !strcasecmp( "Azimuth", p->name() ) &&
  128. 180.0f == p->hints.maximum &&
  129. -180.0f == p->hints.minimum )
  130. {
  131. azimuth_port_number = i;
  132. azimuth_value = p->control_value();
  133. continue;
  134. }
  135. else if ( !strcasecmp( "Elevation", p->name() ) &&
  136. 90.0f == p->hints.maximum &&
  137. -90.0f == p->hints.minimum )
  138. {
  139. elevation_port_number = i;
  140. elevation_value = p->control_value();
  141. continue;
  142. }
  143. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  144. {
  145. Fl_Button *o = new Fl_Button( 0, 0, 30, 30, p->name() );
  146. w = o;
  147. o->selection_color( fc );
  148. o->type( FL_TOGGLE_BUTTON );
  149. o->value( p->control_value() );
  150. }
  151. else if ( p->hints.type == Module::Port::Hints::INTEGER )
  152. {
  153. Fl_Counter *o = new Fl_Counter(0, 0, 58, 24, p->name() );
  154. w = o;
  155. o->type(1);
  156. o->step(1);
  157. if ( p->hints.ranged )
  158. {
  159. o->minimum( p->hints.minimum );
  160. o->maximum( p->hints.maximum );
  161. }
  162. o->value( p->control_value() );
  163. }
  164. else
  165. {
  166. if ( mode_choice->value() == 0 )
  167. {
  168. Fl_DialX *o = new Fl_DialX( 0, 0, 60, 60, p->name() );
  169. w = o;
  170. if ( p->hints.ranged )
  171. {
  172. DMESSAGE( "Min: %f, max: %f", p->hints.minimum, p->hints.maximum );
  173. o->minimum( p->hints.minimum );
  174. o->maximum( p->hints.maximum );
  175. }
  176. o->color( bc );
  177. o->selection_color( fc );
  178. o->value( p->control_value() );
  179. // o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f );
  180. }
  181. else
  182. {
  183. Fl_Value_SliderX *o = new Fl_Value_SliderX( 0, 0, 120, 24, p->name() );
  184. w = o;
  185. if ( mode_choice->value() == 1 )
  186. {
  187. o->type( FL_HORIZONTAL );
  188. o->size( 120, 24 );
  189. if ( p->hints.ranged )
  190. {
  191. o->minimum( p->hints.minimum );
  192. o->maximum( p->hints.maximum );
  193. }
  194. }
  195. else
  196. {
  197. o->type( FL_VERTICAL );
  198. o->size( 24, 120 );
  199. /* have to reverse the meaning of these to get the
  200. * orientation of the slider right */
  201. o->maximum( p->hints.minimum );
  202. o->minimum( p->hints.maximum );
  203. }
  204. o->textsize( 8 );
  205. o->box( FL_NO_BOX );
  206. o->slider( FL_UP_BOX );
  207. o->color( bc );
  208. o->selection_color( fc );
  209. o->value( p->control_value() );
  210. }
  211. }
  212. controls_by_port[i] = w;
  213. w->tooltip( p->osc_path() );
  214. Fl_Button *bound;
  215. w->align(FL_ALIGN_TOP);
  216. w->labelsize( 10 );
  217. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  218. w->callback( cb_button_handle, new callback_data( this, i ) );
  219. else
  220. w->callback( cb_value_handle, new callback_data( this, i ) );
  221. { Fl_Group *o = new Fl_Group( 0, 0, 50, 75 );
  222. {
  223. Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( w );
  224. { Fl_Button *o = bound = new Fl_Button( 0, 50, 14, 14 );
  225. o->selection_color( FL_YELLOW );
  226. o->type( 0 );
  227. o->labelsize( 8 );
  228. o->value( p->connected() );
  229. o->callback( cb_bound_handle, new callback_data( this, i ) );
  230. }
  231. o->resizable( 0 );
  232. o->end();
  233. o->set_visible_focus();
  234. flg->set_visible_focus();
  235. flg->position( o->x(), o->y() );
  236. bound->position( o->x(), flg->y() + flg->h() );
  237. o->size( flg->w(), flg->h() + bound->h() );
  238. o->init_sizes();
  239. }
  240. control_pack->add( o );
  241. }
  242. }
  243. if ( azimuth_port_number >= 0 && elevation_port_number >= 0 )
  244. {
  245. Panner *o = new Panner( 0,0, 300, 300 );
  246. o->box(FL_THIN_UP_BOX);
  247. o->color(FL_GRAY0);
  248. o->selection_color(FL_BACKGROUND_COLOR);
  249. o->labeltype(FL_NORMAL_LABEL);
  250. o->labelfont(0);
  251. o->labelcolor(FL_FOREGROUND_COLOR);
  252. o->align(FL_ALIGN_TOP);
  253. o->when(FL_WHEN_CHANGED);
  254. o->label( "Spatialization" );
  255. o->align(FL_ALIGN_TOP);
  256. o->labelsize( 10 );
  257. o->callback( cb_panner_value_handle, new callback_data( this, azimuth_port_number, elevation_port_number ) );
  258. o->point( 0 )->azimuth( azimuth_value );
  259. o->point( 0 )->elevation( elevation_value );
  260. Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( o );
  261. control_pack->add( flg );
  262. controls_by_port[azimuth_port_number] = o;
  263. controls_by_port[elevation_port_number] = o;
  264. }
  265. int width = control_pack->max_width() + 100;
  266. int height = control_pack->h() + 50;
  267. if ( width < _min_width )
  268. width = _min_width;
  269. main_pack->size( width, height );
  270. size( width, height );
  271. size_range( width, height, width, height );
  272. }
  273. void
  274. Module_Parameter_Editor::cb_value_handle ( Fl_Widget *w, void *v )
  275. {
  276. callback_data *cd = (callback_data*)v;
  277. cd->base_widget->set_value( cd->port_number[0], ((Fl_Valuator*)w)->value() );
  278. }
  279. void
  280. Module_Parameter_Editor::cb_button_handle ( Fl_Widget *w, void *v )
  281. {
  282. callback_data *cd = (callback_data*)v;
  283. cd->base_widget->set_value( cd->port_number[0], ((Fl_Button*)w)->value() );
  284. }
  285. void
  286. Module_Parameter_Editor::cb_panner_value_handle ( Fl_Widget *w, void *v )
  287. {
  288. callback_data *cd = (callback_data*)v;
  289. cd->base_widget->set_value( cd->port_number[0], ((Panner*)w)->point( 0 )->azimuth() );
  290. cd->base_widget->set_value( cd->port_number[1], ((Panner*)w)->point( 0 )->elevation() );
  291. }
  292. void
  293. Module_Parameter_Editor::cb_mode_handle ( Fl_Widget *, void *v )
  294. {
  295. ((Module_Parameter_Editor*)v)->make_controls();
  296. }
  297. void
  298. Module_Parameter_Editor::cb_bound_handle ( Fl_Widget *w, void *v )
  299. {
  300. callback_data *cd = (callback_data*)v;
  301. Fl_Button *fv = (Fl_Button*)w;
  302. fv->value( 1 );
  303. cd->base_widget->bind_control( cd->port_number[0] );
  304. }
  305. void
  306. Module_Parameter_Editor::bind_control ( int i )
  307. {
  308. Module::Port *p = &_module->control_input[i];
  309. /* p->learn_osc(); */
  310. if ( p->connected() )
  311. /* can only bind once */
  312. return;
  313. Controller_Module *o = new Controller_Module();
  314. o->label( p->name() );
  315. o->chain( _module->chain() );
  316. o->connect_to( p );
  317. _module->chain()->add_control( o );
  318. _module->redraw();
  319. }
  320. /* Display changes initiated via automation or from other parts of the GUI */
  321. void
  322. Module_Parameter_Editor::handle_control_changed ( Module::Port *p )
  323. {
  324. int i = _module->control_input_port_index( p );
  325. Fl_Widget *w = controls_by_port[i];
  326. if ( i == azimuth_port_number ||
  327. i == elevation_port_number )
  328. {
  329. Panner *_panner = (Panner*)w;
  330. if ( i == azimuth_port_number )
  331. _panner->point(0)->azimuth( p->control_value() );
  332. else if ( i == elevation_port_number )
  333. _panner->point(0)->elevation( p->control_value() );
  334. _panner->redraw();
  335. return;
  336. }
  337. if ( p->hints.type == Module::Port::Hints::BOOLEAN )
  338. {
  339. Fl_Button *v = (Fl_Button*)w;
  340. v->value( p->control_value() );
  341. }
  342. else
  343. {
  344. Fl_Valuator *v = (Fl_Valuator*)w;
  345. v->value( p->control_value() );
  346. }
  347. }
  348. void
  349. Module_Parameter_Editor::set_value (int i, float value )
  350. {
  351. _module->control_input[i].control_value( value );
  352. if ( _module->control_input[i].connected() )
  353. _module->control_input[i].connected_port()->module()->handle_control_changed( _module->control_input[i].connected_port() );
  354. // _module->handle_control_changed( &_module->control_input[i] );
  355. }