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.

277 lines
6.5KB

  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/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_FLAT_BOX );
  39. color( FL_GREEN );
  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->type( FL_HORIZONTAL );
  45. end();
  46. control_value = new float[1];
  47. *control_value = -70.0f;
  48. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  49. clear_visible_focus();
  50. Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  51. }
  52. Meter_Indicator_Module::~Meter_Indicator_Module ( )
  53. {
  54. if ( control_value )
  55. {
  56. delete[] control_value;
  57. control_value = NULL;
  58. }
  59. Fl::remove_timeout( update_cb, this );
  60. log_destroy();
  61. }
  62. void
  63. Meter_Indicator_Module::get ( Log_Entry &e ) const
  64. {
  65. Port *p = control_input[0].connected_port();
  66. Module *m = p->module();
  67. e.add( ":module", m );
  68. e.add( ":port", m->control_output_port_index( p ) );
  69. Module::get( e );
  70. }
  71. void
  72. Meter_Indicator_Module::set ( Log_Entry &e )
  73. {
  74. Module::set( e );
  75. int port = -1;
  76. Module *module = NULL;
  77. for ( int i = 0; i < e.size(); ++i )
  78. {
  79. const char *s, *v;
  80. e.get( i, &s, &v );
  81. if ( ! strcmp( s, ":port" ) )
  82. {
  83. port = atoi( v );
  84. }
  85. else if ( ! strcmp( s, ":module" ) )
  86. {
  87. int i;
  88. sscanf( v, "%X", &i );
  89. Module *t = (Module*)Loggable::find( i );
  90. assert( t );
  91. module = t;
  92. }
  93. }
  94. if ( port >= 0 && module )
  95. control_input[0].connect_to( &module->control_output[port] );
  96. }
  97. void
  98. Meter_Indicator_Module::update_cb ( void *v )
  99. {
  100. ((Meter_Indicator_Module*)v)->update_cb();
  101. }
  102. void
  103. Meter_Indicator_Module::update_cb ( void )
  104. {
  105. Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  106. if ( control_input[0].connected() )
  107. {
  108. // A little hack to detect that the connected module's number
  109. // of control outs has changed.
  110. Port *p = control_input[0].connected_port();
  111. if ( dpm_pack->children() != p->hints.dimensions )
  112. {
  113. /* engine->lock(); */
  114. dpm_pack->clear();
  115. control_value = new float[p->hints.dimensions];
  116. for ( int i = p->hints.dimensions; i--; )
  117. {
  118. DPM *dpm = new DPM( x(), y(), w(), h() );
  119. dpm->type( FL_VERTICAL );
  120. dpm_pack->add( dpm );
  121. control_value[i] = -70.0f;
  122. dpm->value( -70.0f );
  123. }
  124. // redraw();
  125. /* engine->unlock(); */
  126. }
  127. else
  128. {
  129. for ( int i = 0; i < dpm_pack->children(); ++i )
  130. {
  131. ((DPM*)dpm_pack->child( i ))->value( control_value[i] );
  132. }
  133. }
  134. }
  135. }
  136. void
  137. Meter_Indicator_Module::connect_to ( Port *p )
  138. {
  139. control_input[0].connect_to( p );
  140. /* DPM *o = new DPM( 10, 10, 10, 10 ); */
  141. /* o->type( FL_VERTICAL ); */
  142. /* dpm_pack->add( o ); */
  143. redraw();
  144. }
  145. int
  146. Meter_Indicator_Module::handle ( int m )
  147. {
  148. switch ( m )
  149. {
  150. case FL_PUSH:
  151. {
  152. if ( Fl::event_button1() )
  153. {
  154. /* don't let Module::handle eat our click */
  155. return Fl_Group::handle( m );
  156. }
  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. dpm_pack->redraw();
  182. control_value[i] = -70.0f;
  183. dpm->value( -70.0f );
  184. }
  185. redraw();
  186. }
  187. }
  188. }
  189. /**********/
  190. /* Engine */
  191. /**********/
  192. void
  193. Meter_Indicator_Module::process ( nframes_t )
  194. {
  195. if ( control_input[0].connected() )
  196. {
  197. Port *p = control_input[0].connected_port();
  198. for ( int i = 0; i < p->hints.dimensions; ++i )
  199. {
  200. control_value[i] = ((float*)control_input[0].buffer())[i];
  201. }
  202. }
  203. }