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.

188 lines
4.8KB

  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 "const.h"
  19. #include <math.h>
  20. #include <FL/Fl.H>
  21. #include <FL/Fl_Single_Window.H>
  22. #include "FL/Fl_Scalepack.H"
  23. #include "FL/test_press.H"
  24. #include "Meter_Module.H"
  25. #include "DPM.H"
  26. #include "JACK/Port.H"
  27. #include "dsp.h"
  28. Meter_Module::Meter_Module ( )
  29. : Module ( 50, 100, name() )
  30. {
  31. box( FL_NO_BOX );
  32. dpm_pack = new Fl_Scalepack( x(), y(), w(), h() );
  33. dpm_pack->type( FL_HORIZONTAL );
  34. control_value = 0;
  35. color( FL_BLACK );
  36. end();
  37. Port p( this, Port::OUTPUT, Port::CONTROL, "dB level" );
  38. p.hints.type = Port::Hints::LOGARITHMIC;
  39. p.hints.ranged = true;
  40. p.hints.maximum = 6.0f;
  41. p.hints.minimum = -70.0f;
  42. p.hints.dimensions = 1;
  43. p.connect_to( new float[1] );
  44. p.control_value_no_callback( -70.0f );
  45. add_port( p );
  46. log_create();
  47. }
  48. Meter_Module::~Meter_Module ( )
  49. {
  50. if ( control_value )
  51. delete[] control_value;
  52. log_destroy();
  53. }
  54. void
  55. Meter_Module::update ( void )
  56. {
  57. for ( int i = dpm_pack->children(); i--; )
  58. {
  59. ((DPM*)dpm_pack->child( i ))->value( control_value[i] );
  60. control_value[i] = -70.0f;
  61. }
  62. }
  63. bool
  64. Meter_Module::configure_inputs ( int n )
  65. {
  66. THREAD_ASSERT( UI );
  67. int on = audio_input.size();
  68. if ( n > on )
  69. {
  70. for ( int i = on; i < n; ++i )
  71. {
  72. DPM *dpm = new DPM( 0, 0, w(), h() );
  73. dpm->type( FL_VERTICAL );
  74. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  75. dpm_pack->add( dpm );
  76. add_port( Port( this, Port::INPUT, Port::AUDIO ) );
  77. add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
  78. }
  79. }
  80. else
  81. {
  82. for ( int i = on; i > n; --i )
  83. {
  84. DPM *dpm = (DPM*)dpm_pack->child( dpm_pack->children() - 1 );
  85. dpm_pack->remove( dpm );
  86. delete dpm;
  87. audio_input.back().disconnect();
  88. audio_input.pop_back();
  89. audio_output.back().disconnect();
  90. audio_output.pop_back();
  91. }
  92. }
  93. control_output[0].hints.dimensions = n;
  94. delete[] (float*)control_output[0].buffer();
  95. {
  96. float *f = new float[n];
  97. for ( int i = n; i--; )
  98. f[i] = -70.0f;
  99. control_output[0].connect_to( f );
  100. }
  101. if ( control_value )
  102. delete [] control_value;
  103. control_value = new float[n];
  104. for ( int i = n; i--; )
  105. control_value[i] = -70.0f;
  106. if ( control_output[0].connected() )
  107. control_output[0].connected_port()->module()->handle_control_changed( control_output[0].connected_port() );
  108. return true;
  109. }
  110. int
  111. Meter_Module::handle ( int m )
  112. {
  113. switch ( m )
  114. {
  115. case FL_PUSH:
  116. {
  117. if ( test_press( FL_BUTTON1 ) )
  118. {
  119. /* don't let Module::handle eat our click */
  120. return Fl_Group::handle( m );
  121. }
  122. return Module::handle( m );
  123. }
  124. }
  125. return Module::handle( m );
  126. }
  127. /**********/
  128. /* Engine */
  129. /**********/
  130. void
  131. Meter_Module::process ( nframes_t nframes )
  132. {
  133. for ( unsigned int i = 0; i < audio_input.size(); ++i )
  134. {
  135. if ( audio_input[i].connected() )
  136. {
  137. // float dB = 20 * log10( get_peak_sample( (float*)audio_input[i].buffer(), nframes ) / 2.0f );
  138. float dB = 20 * log10( buffer_get_peak( (sample_t*) audio_input[i].buffer(), nframes ) );
  139. ((float*)control_output[0].buffer())[i] = dB;
  140. if (dB > control_value[i])
  141. control_value[i] = dB;
  142. }
  143. }
  144. }