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.

268 lines
6.4KB

  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 "Chain.H"
  30. #include "DPM.H"
  31. #include "FL/test_press.H"
  32. Meter_Indicator_Module::Meter_Indicator_Module ( bool is_default )
  33. : Module ( is_default, 50, 100, name() )
  34. {
  35. box( FL_FLAT_BOX );
  36. color( FL_BLACK );
  37. _disable_context_menu = false;
  38. _pad = true;
  39. control_value = 0;
  40. add_port( Port( this, Port::INPUT, Port::CONTROL ) );
  41. control_input[0].hints.visible = false;
  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. }
  52. Meter_Indicator_Module::~Meter_Indicator_Module ( )
  53. {
  54. if ( control_value )
  55. {
  56. delete[] control_value;
  57. control_value = NULL;
  58. }
  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 ( void )
  98. {
  99. if ( control_input[0].connected() )
  100. {
  101. // A little hack to detect that the connected module's number
  102. // of control outs has changed.
  103. Port *p = control_input[0].connected_port();
  104. if ( dpm_pack->children() != p->hints.dimensions )
  105. {
  106. /* engine->lock(); */
  107. dpm_pack->clear();
  108. control_value = new float[p->hints.dimensions];
  109. for ( int i = p->hints.dimensions; i--; )
  110. {
  111. DPM *dpm = new DPM( x(), y(), w(), h() );
  112. dpm->type( FL_VERTICAL );
  113. dpm_pack->add( dpm );
  114. control_value[i] = -70.0f;
  115. dpm->value( -70.0f );
  116. }
  117. /* engine->unlock(); */
  118. }
  119. else
  120. {
  121. for ( int i = 0; i < dpm_pack->children(); ++i )
  122. {
  123. ((DPM*)dpm_pack->child( i ))->value( control_value[i] );
  124. control_value[i] = -70.0f;
  125. }
  126. }
  127. }
  128. }
  129. void
  130. Meter_Indicator_Module::connect_to ( Port *p )
  131. {
  132. control_input[0].connect_to( p );
  133. /* DPM *o = new DPM( 10, 10, 10, 10 ); */
  134. /* o->type( FL_VERTICAL ); */
  135. /* dpm_pack->add( o ); */
  136. redraw();
  137. }
  138. int
  139. Meter_Indicator_Module::handle ( int m )
  140. {
  141. switch ( m )
  142. {
  143. case FL_PUSH:
  144. {
  145. if ( Fl::event_button3() && _disable_context_menu )
  146. return 0;
  147. if ( Fl::event_button1() )
  148. {
  149. /* don't let Module::handle eat our click */
  150. return Fl_Group::handle( m );
  151. }
  152. }
  153. }
  154. return Module::handle( m );
  155. }
  156. void
  157. Meter_Indicator_Module::handle_control_changed ( Port *p )
  158. {
  159. THREAD_ASSERT( UI );
  160. /* The engine is already locked by the UI thread at this point in
  161. the call-graph, so we can be sure that process() won't be
  162. executed concurrently. */
  163. if ( p->connected() )
  164. {
  165. p = p->connected_port();
  166. if ( dpm_pack->children() != p->hints.dimensions )
  167. {
  168. dpm_pack->clear();
  169. control_value = new float[p->hints.dimensions];
  170. for ( int i = p->hints.dimensions; i--; )
  171. {
  172. DPM *dpm = new DPM( x(), y(), w(), h() );
  173. dpm->type( FL_VERTICAL );
  174. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  175. dpm_pack->add( dpm );
  176. dpm_pack->redraw();
  177. control_value[i] = -70.0f;
  178. dpm->value( -70.0f );
  179. }
  180. redraw();
  181. }
  182. }
  183. }
  184. /**********/
  185. /* Engine */
  186. /**********/
  187. void
  188. Meter_Indicator_Module::process ( nframes_t )
  189. {
  190. if ( control_input[0].connected() )
  191. {
  192. Port *p = control_input[0].connected_port();
  193. for ( int i = 0; i < p->hints.dimensions; ++i )
  194. {
  195. float dB = ((float*)control_input[0].buffer())[i];
  196. if ( dB > control_value[i])
  197. control_value[i] = dB;
  198. }
  199. }
  200. }