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.

159 lines
4.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. Meter_Indicator_Module::Meter_Indicator_Module ( int W, int H, const char *L )
  35. : Module ( W, 100, L )
  36. {
  37. box( FL_NO_BOX );
  38. _pad = true;
  39. control = 0;
  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->type( FL_HORIZONTAL );
  44. control_value = new float[1];
  45. end();
  46. Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  47. }
  48. Meter_Indicator_Module::~Meter_Indicator_Module ( )
  49. {
  50. if ( control_value )
  51. delete[] control_value;
  52. }
  53. void
  54. Meter_Indicator_Module::update_cb ( void *v )
  55. {
  56. ((Meter_Indicator_Module*)v)->update_cb();
  57. }
  58. void
  59. Meter_Indicator_Module::update_cb ( void )
  60. {
  61. Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  62. if ( control_input[0].connected() )
  63. {
  64. // A little hack to detect that the connected module's number
  65. // of control outs has changed.
  66. Port *p = control_input[0].connected_port();
  67. if ( dpm_pack->children() != p->hints.dimensions )
  68. {
  69. engine->lock();
  70. dpm_pack->clear();
  71. control_value = new float[p->hints.dimensions];
  72. for ( int i = p->hints.dimensions; i--; )
  73. {
  74. DPM *dpm = new DPM( x(), y(), w(), h() );
  75. dpm->type( FL_VERTICAL );
  76. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  77. dpm_pack->add( dpm );
  78. control_value[i] = -70.0f;
  79. dpm->value( -70.0f );
  80. }
  81. engine->unlock();
  82. }
  83. else
  84. {
  85. for ( int i = 0; i < dpm_pack->children(); ++i )
  86. {
  87. ((DPM*)dpm_pack->child( i ))->value( control_value[i] );
  88. }
  89. }
  90. }
  91. // redraw();
  92. }
  93. void
  94. Meter_Indicator_Module::connect_to ( Port *p )
  95. {
  96. control_input[0].connect_to( p );
  97. /* else if ( p->hints.type == Module::Port::Hints::LOGARITHMIC ) */
  98. /* { */
  99. {
  100. DPM *o = new DPM( x(), y(), this->w(), h() );
  101. o->type( FL_VERTICAL );
  102. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  103. dpm_pack->add( o );
  104. }
  105. }
  106. int
  107. Meter_Indicator_Module::handle ( int m )
  108. {
  109. return Fl_Group::handle( m );
  110. }
  111. void
  112. Meter_Indicator_Module::process ( void )
  113. {
  114. if ( control_input[0].connected() )
  115. {
  116. Port *p = control_input[0].connected_port();
  117. for ( int i = 0; i < p->hints.dimensions; ++i )
  118. control_value[i] = ((float*)control_input[0].buffer())[i];
  119. }
  120. }