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.

121 lines
3.5KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 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. /* routines to draw a waveform from peak data */
  19. #include <FL/fl_draw.H>
  20. #include "Waveform.H"
  21. #include <math.h>
  22. #include <algorithm>
  23. using std::min;
  24. using std::max;
  25. bool Waveform::fill = true;
  26. bool Waveform::outline = true;
  27. bool Waveform::vary_color = true;
  28. bool Waveform::logarithmic = true;
  29. /* TODO: split the variations into separate functions. eg, plain,
  30. * outlined, filled, polygonal, rectified. */
  31. void
  32. Waveform::scale ( Peak *pbuf, int npeaks, float gain )
  33. {
  34. /* scale it */
  35. for ( int j = npeaks; j--; )
  36. {
  37. pbuf[ j ].min *= gain;
  38. pbuf[ j ].max *= gain;
  39. }
  40. }
  41. /** draw a portion of /clip/'s waveform. coordinates are the portion to draw */
  42. void
  43. Waveform::draw ( int X, int Y, int W, int H,
  44. const Peak *pbuf, int peaks, int skip,
  45. Fl_Color color )
  46. {
  47. int j;
  48. int start = 0;
  49. const int halfheight = H / 2;
  50. const int mid = Y + halfheight;
  51. W = min( peaks, W );
  52. if ( Waveform::fill )
  53. {
  54. j = start;
  55. for ( int x = X; x < X + W; ++x, j += skip )
  56. {
  57. const Peak p = pbuf[ j ];
  58. const float diff = fabs( p.max - p.min );
  59. if ( diff > 2.0f )
  60. fl_color( FL_RED );
  61. else
  62. if ( Waveform::vary_color )
  63. fl_color( fl_color_average( FL_WHITE, color, diff * 0.5f ) );
  64. else
  65. fl_color( color );
  66. const int ty = mid - ( halfheight * p.min );
  67. const int by = mid - ( halfheight * p.max );
  68. fl_line( x, ty, x, by );
  69. }
  70. }
  71. const int ty = Y + halfheight;
  72. if ( Waveform::outline )
  73. {
  74. fl_color( fl_darker( fl_darker( color ) ) );
  75. fl_line_style( FL_SOLID | FL_CAP_FLAT, 2 );
  76. fl_begin_line();
  77. j = start;
  78. for ( int x = X; x < X + W; ++x, j += skip )
  79. fl_vertex( x, ty - ( halfheight * pbuf[ j ].min ) );
  80. fl_end_line();
  81. fl_begin_line();
  82. j = start;
  83. for ( int x = X; x < X + W; ++x, j += skip )
  84. fl_vertex( x, ty - ( halfheight * pbuf[ j ].max ) );
  85. fl_end_line();
  86. fl_line_style( FL_SOLID, 0 );
  87. }
  88. }