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.

217 lines
5.3KB

  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. void
  35. Meter_Indicator_Module::get ( Log_Entry &e ) const
  36. {
  37. Port *p = control_input[0].connected_port();
  38. Module *m = p->module();
  39. e.add( ":module", m );
  40. e.add( ":port", m->control_output_port_index( p ) );
  41. Module::get( e );
  42. }
  43. void
  44. Meter_Indicator_Module::set ( Log_Entry &e )
  45. {
  46. Module::set( e );
  47. int port;
  48. Module *module = NULL;
  49. for ( int i = 0; i < e.size(); ++i )
  50. {
  51. const char *s, *v;
  52. e.get( i, &s, &v );
  53. if ( ! strcmp( s, ":port" ) )
  54. {
  55. port = atoi( v );
  56. }
  57. else if ( ! strcmp( s, ":module" ) )
  58. {
  59. int i;
  60. sscanf( v, "%X", &i );
  61. Module *t = (Module*)Loggable::find( i );
  62. assert( t );
  63. module = t;
  64. }
  65. }
  66. if ( port >= 0 && module )
  67. control_input[0].connect_to( &module->control_output[port] );
  68. }
  69. Meter_Indicator_Module::Meter_Indicator_Module ( bool is_default )
  70. : Module ( is_default, 50, 100, name() )
  71. {
  72. box( FL_NO_BOX );
  73. _pad = true;
  74. control = 0;
  75. control_value = 0;
  76. add_port( Port( this, Port::INPUT, Port::CONTROL ) );
  77. dpm_pack = new Fl_Scalepack( x(), y(), w(), h() );
  78. dpm_pack->type( FL_HORIZONTAL );
  79. control_value = new float[1];
  80. *control_value = -70.0f;
  81. end();
  82. Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  83. }
  84. Meter_Indicator_Module::~Meter_Indicator_Module ( )
  85. {
  86. if ( control_value )
  87. {
  88. delete[] control_value;
  89. control_value = NULL;
  90. }
  91. Fl::remove_timeout( update_cb, this );
  92. log_destroy();
  93. }
  94. void
  95. Meter_Indicator_Module::update_cb ( void *v )
  96. {
  97. ((Meter_Indicator_Module*)v)->update_cb();
  98. }
  99. void
  100. Meter_Indicator_Module::update_cb ( void )
  101. {
  102. Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  103. if ( control_input[0].connected() )
  104. {
  105. // A little hack to detect that the connected module's number
  106. // of control outs has changed.
  107. Port *p = control_input[0].connected_port();
  108. if ( dpm_pack->children() != p->hints.dimensions )
  109. {
  110. engine->lock();
  111. dpm_pack->clear();
  112. control_value = new float[p->hints.dimensions];
  113. for ( int i = p->hints.dimensions; i--; )
  114. {
  115. DPM *dpm = new DPM( x(), y(), w(), h() );
  116. dpm->type( FL_VERTICAL );
  117. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  118. dpm_pack->add( dpm );
  119. control_value[i] = -70.0f;
  120. dpm->value( -70.0f );
  121. }
  122. engine->unlock();
  123. }
  124. else
  125. {
  126. for ( int i = 0; i < dpm_pack->children(); ++i )
  127. {
  128. ((DPM*)dpm_pack->child( i ))->value( control_value[i] );
  129. }
  130. }
  131. }
  132. // redraw();
  133. }
  134. void
  135. Meter_Indicator_Module::connect_to ( Port *p )
  136. {
  137. control_input[0].connect_to( p );
  138. /* else if ( p->hints.type == Module::Port::Hints::LOGARITHMIC ) */
  139. /* { */
  140. {
  141. DPM *o = new DPM( x(), y(), this->w(), h() );
  142. o->type( FL_VERTICAL );
  143. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  144. dpm_pack->add( o );
  145. }
  146. }
  147. int
  148. Meter_Indicator_Module::handle ( int m )
  149. {
  150. return Fl_Group::handle( m );
  151. }
  152. void
  153. Meter_Indicator_Module::process ( void )
  154. {
  155. if ( control_input[0].connected() )
  156. {
  157. Port *p = control_input[0].connected_port();
  158. for ( int i = 0; i < p->hints.dimensions; ++i )
  159. control_value[i] = ((float*)control_input[0].buffer())[i];
  160. }
  161. }