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.

123 lines
3.6KB

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