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.

280 lines
6.6KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2010 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 "Meter_Indicator_Module.H"
  19. #include <stdio.h>
  20. #include <FL/Fl.H>
  21. #include <FL/Fl_Value_Slider.H>
  22. #include <FL/Fl_Box.H>
  23. #include <FL/fl_draw.H>
  24. #include <FL/Fl_Counter.H>
  25. #include <FL/Fl_Light_Button.H>
  26. #include "FL/Fl_Dial.H"
  27. #include "FL/Fl_Labelpad_Group.H"
  28. #include "FL/Fl_Scalepack.H"
  29. #include "Engine/Engine.H"
  30. #include "Chain.H"
  31. #include "DPM.H"
  32. #include "FL/test_press.H"
  33. const float CONTROL_UPDATE_FREQ = 0.1f;
  34. Meter_Indicator_Module::Meter_Indicator_Module ( bool is_default )
  35. : Module ( is_default, 50, 100, name() )
  36. {
  37. box( FL_FLAT_BOX );
  38. color( FL_BLACK );
  39. _disable_context_menu = false;
  40. _pad = true;
  41. control_value = 0;
  42. add_port( Port( this, Port::INPUT, Port::CONTROL ) );
  43. dpm_pack = new Fl_Scalepack( x(), y(), w(), h() );
  44. dpm_pack->color( FL_BACKGROUND_COLOR );
  45. dpm_pack->box( FL_FLAT_BOX );
  46. dpm_pack->type( FL_HORIZONTAL );
  47. end();
  48. control_value = new float[1];
  49. *control_value = -70.0f;
  50. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  51. clear_visible_focus();
  52. Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  53. }
  54. Meter_Indicator_Module::~Meter_Indicator_Module ( )
  55. {
  56. if ( control_value )
  57. {
  58. delete[] control_value;
  59. control_value = NULL;
  60. }
  61. Fl::remove_timeout( update_cb, this );
  62. log_destroy();
  63. }
  64. void
  65. Meter_Indicator_Module::get ( Log_Entry &e ) const
  66. {
  67. Port *p = control_input[0].connected_port();
  68. Module *m = p->module();
  69. e.add( ":module", m );
  70. e.add( ":port", m->control_output_port_index( p ) );
  71. Module::get( e );
  72. }
  73. void
  74. Meter_Indicator_Module::set ( Log_Entry &e )
  75. {
  76. Module::set( e );
  77. int port = -1;
  78. Module *module = NULL;
  79. for ( int i = 0; i < e.size(); ++i )
  80. {
  81. const char *s, *v;
  82. e.get( i, &s, &v );
  83. if ( ! strcmp( s, ":port" ) )
  84. {
  85. port = atoi( v );
  86. }
  87. else if ( ! strcmp( s, ":module" ) )
  88. {
  89. int i;
  90. sscanf( v, "%X", &i );
  91. Module *t = (Module*)Loggable::find( i );
  92. assert( t );
  93. module = t;
  94. }
  95. }
  96. if ( port >= 0 && module )
  97. control_input[0].connect_to( &module->control_output[port] );
  98. }
  99. void
  100. Meter_Indicator_Module::update_cb ( void *v )
  101. {
  102. ((Meter_Indicator_Module*)v)->update_cb();
  103. }
  104. void
  105. Meter_Indicator_Module::update_cb ( void )
  106. {
  107. Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  108. if ( control_input[0].connected() )
  109. {
  110. // A little hack to detect that the connected module's number
  111. // of control outs has changed.
  112. Port *p = control_input[0].connected_port();
  113. if ( dpm_pack->children() != p->hints.dimensions )
  114. {
  115. /* engine->lock(); */
  116. dpm_pack->clear();
  117. control_value = new float[p->hints.dimensions];
  118. for ( int i = p->hints.dimensions; i--; )
  119. {
  120. DPM *dpm = new DPM( x(), y(), w(), h() );
  121. dpm->type( FL_VERTICAL );
  122. dpm_pack->add( dpm );
  123. control_value[i] = -70.0f;
  124. dpm->value( -70.0f );
  125. }
  126. /* engine->unlock(); */
  127. }
  128. else
  129. {
  130. for ( int i = 0; i < dpm_pack->children(); ++i )
  131. {
  132. ((DPM*)dpm_pack->child( i ))->value( control_value[i] );
  133. }
  134. }
  135. }
  136. }
  137. void
  138. Meter_Indicator_Module::connect_to ( Port *p )
  139. {
  140. control_input[0].connect_to( p );
  141. /* DPM *o = new DPM( 10, 10, 10, 10 ); */
  142. /* o->type( FL_VERTICAL ); */
  143. /* dpm_pack->add( o ); */
  144. redraw();
  145. }
  146. int
  147. Meter_Indicator_Module::handle ( int m )
  148. {
  149. switch ( m )
  150. {
  151. case FL_PUSH:
  152. {
  153. if ( Fl::event_button3() && _disable_context_menu )
  154. return 0;
  155. if ( Fl::event_button1() )
  156. {
  157. /* don't let Module::handle eat our click */
  158. return Fl_Group::handle( m );
  159. }
  160. }
  161. }
  162. return Module::handle( m );
  163. }
  164. void
  165. Meter_Indicator_Module::handle_control_changed ( Port *p )
  166. {
  167. THREAD_ASSERT( UI );
  168. /* The engine is already locked by the UI thread at this point in
  169. the call-graph, so we can be sure that process() won't be
  170. executed concurrently. */
  171. if ( p->connected() )
  172. {
  173. p = p->connected_port();
  174. if ( dpm_pack->children() != p->hints.dimensions )
  175. {
  176. dpm_pack->clear();
  177. control_value = new float[p->hints.dimensions];
  178. for ( int i = p->hints.dimensions; i--; )
  179. {
  180. DPM *dpm = new DPM( x(), y(), w(), h() );
  181. dpm->type( FL_VERTICAL );
  182. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  183. dpm_pack->add( dpm );
  184. dpm_pack->redraw();
  185. control_value[i] = -70.0f;
  186. dpm->value( -70.0f );
  187. }
  188. redraw();
  189. }
  190. }
  191. }
  192. /**********/
  193. /* Engine */
  194. /**********/
  195. void
  196. Meter_Indicator_Module::process ( nframes_t )
  197. {
  198. if ( control_input[0].connected() )
  199. {
  200. Port *p = control_input[0].connected_port();
  201. for ( int i = 0; i < p->hints.dimensions; ++i )
  202. {
  203. control_value[i] = ((float*)control_input[0].buffer())[i];
  204. }
  205. }
  206. }