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.

150 lines
4.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 "Audio_File.H"
  24. #include "Waveform.H"
  25. #include <math.h>
  26. bool Waveform::fill = true;
  27. bool Waveform::outline = true;
  28. bool Waveform::vary_color = true;
  29. bool Waveform::logarithmic = true;
  30. /* TODO: split the variations into separate functions. eg, plain,
  31. * outlined, filled, polygonal, rectified. */
  32. /* TODO: this should be made completely independent of /timeline/ so that it can be used for other purposes (file previews) */
  33. /** draw a portion of /clip/'s waveform. coordinates are the portion to draw */
  34. void
  35. Waveform::draw ( int ox, int X, int Y, int W, int H, Audio_File *_clip, int channel, float fpp, nframes_t _start, nframes_t _end, float _scale, Fl_Color color )
  36. {
  37. fl_push_clip( X, Y, W, H );
  38. int j;
  39. // int start = timeline->ts_to_x( _start );
  40. int start = timeline->ts_to_x( _start ) + (X - ox);
  41. const Peaks *pk = _clip->peaks( channel );
  42. _start = timeline->x_to_ts( start );
  43. pk->fill_buffer( fpp, _start, _start + timeline->x_to_ts( W ) );
  44. const int halfheight = H / 2;
  45. const int mid = Y + halfheight;
  46. if ( Waveform::fill )
  47. {
  48. j = start;
  49. for ( int x = X; x <= X + W; ++x, ++j )
  50. {
  51. // Peak p = (*pk)[ j ];
  52. Peak p = pk->peak( timeline->x_to_ts( j ), timeline->x_to_ts( j + 1 ) );
  53. p.max *= _scale;
  54. p.min *= _scale;
  55. const float diff = fabs( p.max - p.min );
  56. /* if ( Waveform::logarithmic ) */
  57. /* { */
  58. /* p.max = 10.0f * log10f( p.max ); */
  59. /* p.min = 10.0f * log10f( p.min ); */
  60. /* } */
  61. if ( diff > 2.0f )
  62. fl_color( FL_RED );
  63. else
  64. if ( Waveform::vary_color )
  65. fl_color( fl_color_average( FL_WHITE, color, diff / 2.0f ) );
  66. else
  67. fl_color( color );
  68. const int ty = mid + (halfheight * p.min);
  69. const int by = mid + (halfheight * p.max );
  70. fl_line( x, ty, x, by );
  71. /* if ( outline ) */
  72. /* { */
  73. /* fl_color( fl_darker( fl_darker( color ) ) ); */
  74. /* fl_line( x, ty - 2, x, ty ); */
  75. /* fl_line( x, by + 2, x, by ); */
  76. /* } */
  77. }
  78. }
  79. if ( Waveform::outline )
  80. {
  81. fl_color( fl_darker( fl_darker( color ) ) );
  82. fl_line_style( FL_SOLID, 2 );
  83. fl_begin_line();
  84. j = start;
  85. for ( int x = X; x <= X + W; ++x, ++j )
  86. {
  87. // Peak p = (*pk)[ j ];
  88. Peak p = pk->peak( timeline->x_to_ts( j ), timeline->x_to_ts( j + 1 ) );
  89. p.min *= _scale;
  90. fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.min ));
  91. }
  92. fl_end_line();
  93. fl_begin_line();
  94. j = start;
  95. for ( int x = X; x <= X + W; ++x, ++j )
  96. {
  97. // Peak p = (*pk)[ j ];
  98. Peak p = pk->peak( timeline->x_to_ts( j ), timeline->x_to_ts( j + 1 ) );
  99. p.max *= _scale;
  100. fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.max ));
  101. }
  102. fl_end_line();
  103. fl_line_style( FL_SOLID, 0 );
  104. }
  105. fl_pop_clip();
  106. }