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.

134 lines
4.0KB

  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. 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. /* TODO: this should be made completely independent of /timeline/ so that it can be used for other purposes (file previews) */
  32. /** draw a portion of /clip/'s waveform. coordinates are the portion to draw */
  33. void
  34. Waveform::draw ( int X, int Y, int W, int H,
  35. Peak *pbuf, int peaks,
  36. Fl_Color color )
  37. {
  38. fl_push_clip( X, Y, W, H );
  39. int j;
  40. // int start = timeline->ts_to_x( _r->start ) + (X - ox);
  41. int start = 0;
  42. const int halfheight = H / 2;
  43. const int mid = Y + halfheight;
  44. if ( Waveform::fill )
  45. {
  46. j = start;
  47. for ( int x = X; x < X + W; ++x, ++j )
  48. {
  49. const Peak p = pbuf[ j ];
  50. const float diff = fabs( p.max - p.min );
  51. /* if ( Waveform::logarithmic ) */
  52. /* { */
  53. /* p.max = 10.0f * log10f( p.max ); */
  54. /* p.min = 10.0f * log10f( p.min ); */
  55. /* } */
  56. if ( diff > 2.0f )
  57. fl_color( FL_RED );
  58. else
  59. if ( Waveform::vary_color )
  60. fl_color( fl_color_average( FL_WHITE, color, diff / 2.0f ) );
  61. else
  62. fl_color( color );
  63. const int ty = mid + (halfheight * p.min);
  64. const int by = mid + (halfheight * p.max );
  65. fl_line( x, ty, x, by );
  66. /* if ( outline ) */
  67. /* { */
  68. /* fl_color( fl_darker( fl_darker( color ) ) ); */
  69. /* fl_line( x, ty - 2, x, ty ); */
  70. /* fl_line( x, by + 2, x, by ); */
  71. /* } */
  72. }
  73. }
  74. if ( Waveform::outline )
  75. {
  76. fl_color( fl_darker( fl_darker( color ) ) );
  77. fl_line_style( FL_SOLID, 2 );
  78. fl_begin_line();
  79. j = start;
  80. for ( int x = X; x < X + W; ++x, ++j )
  81. {
  82. const Peak p = pbuf[ j ];
  83. fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.min ));
  84. }
  85. fl_end_line();
  86. fl_begin_line();
  87. j = start;
  88. for ( int x = X; x < X + W; ++x, ++j )
  89. {
  90. const Peak p = pbuf[ j ];
  91. fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.max ));
  92. }
  93. fl_end_line();
  94. fl_line_style( FL_SOLID, 0 );
  95. }
  96. fl_pop_clip();
  97. }