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.

269 lines
6.4KB

  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. Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  49. }
  50. Meter_Indicator_Module::~Meter_Indicator_Module ( )
  51. {
  52. if ( control_value )
  53. {
  54. delete[] control_value;
  55. control_value = NULL;
  56. }
  57. Fl::remove_timeout( update_cb, this );
  58. log_destroy();
  59. }
  60. void
  61. Meter_Indicator_Module::get ( Log_Entry &e ) const
  62. {
  63. Port *p = control_input[0].connected_port();
  64. Module *m = p->module();
  65. e.add( ":module", m );
  66. e.add( ":port", m->control_output_port_index( p ) );
  67. Module::get( e );
  68. }
  69. void
  70. Meter_Indicator_Module::set ( Log_Entry &e )
  71. {
  72. Module::set( e );
  73. int port = -1;
  74. Module *module = NULL;
  75. for ( int i = 0; i < e.size(); ++i )
  76. {
  77. const char *s, *v;
  78. e.get( i, &s, &v );
  79. if ( ! strcmp( s, ":port" ) )
  80. {
  81. port = atoi( v );
  82. }
  83. else if ( ! strcmp( s, ":module" ) )
  84. {
  85. int i;
  86. sscanf( v, "%X", &i );
  87. Module *t = (Module*)Loggable::find( i );
  88. assert( t );
  89. module = t;
  90. }
  91. }
  92. if ( port >= 0 && module )
  93. control_input[0].connect_to( &module->control_output[port] );
  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. DPM *o = new DPM( x(), y(), this->w(), h() );
  140. o->type( FL_VERTICAL );
  141. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  142. dpm_pack->add( o );
  143. }
  144. int
  145. Meter_Indicator_Module::handle ( int m )
  146. {
  147. switch ( m )
  148. {
  149. case FL_PUSH:
  150. {
  151. if ( test_press( FL_BUTTON1 ) )
  152. {
  153. /* don't let Module::handle eat our click */
  154. return Fl_Group::handle( m );
  155. }
  156. return Module::handle( m );
  157. }
  158. }
  159. return Module::handle( m );
  160. }
  161. void
  162. Meter_Indicator_Module::handle_control_changed ( Port *p )
  163. {
  164. THREAD_ASSERT( UI );
  165. /* The engine is already locked by the UI thread at this point in
  166. the call-graph, so we can be sure that process() won't be
  167. executed concurrently. */
  168. if ( p->connected() )
  169. {
  170. p = p->connected_port();
  171. if ( dpm_pack->children() != p->hints.dimensions )
  172. {
  173. dpm_pack->clear();
  174. control_value = new float[p->hints.dimensions];
  175. for ( int i = p->hints.dimensions; i--; )
  176. {
  177. DPM *dpm = new DPM( x(), y(), w(), h() );
  178. dpm->type( FL_VERTICAL );
  179. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  180. dpm_pack->add( dpm );
  181. control_value[i] = -70.0f;
  182. dpm->value( -70.0f );
  183. }
  184. }
  185. }
  186. }
  187. /**********/
  188. /* Engine */
  189. /**********/
  190. void
  191. Meter_Indicator_Module::process ( void )
  192. {
  193. if ( control_input[0].connected() )
  194. {
  195. Port *p = control_input[0].connected_port();
  196. for ( int i = 0; i < p->hints.dimensions; ++i )
  197. control_value[i] = ((float*)control_input[0].buffer())[i];
  198. }
  199. }