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.2KB

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