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.

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