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.

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