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.

271 lines
6.5KB

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