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.

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