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.

158 lines
3.9KB

  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 "Waveform.H"
  22. #include "Clip.H"
  23. // extern Timeline timeline;
  24. // #include "Timeline.H"
  25. #include <math.h>
  26. extern Fl_Color velocity_colors[];
  27. Waveform::Waveform ( int X, int Y, int W, int H, const char *L ) : Fl_Widget( X, Y, W, H, L )
  28. {
  29. _scale = 1;
  30. _clip = NULL;
  31. _start = _end = 0;
  32. }
  33. int measure = 50;
  34. void
  35. Waveform::draw ( void )
  36. {
  37. // draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() );
  38. /* fl_color( fl_lighter( color() ) ); */
  39. /* for ( int nx = x(); nx < x() + w(); ++nx ) */
  40. /* if ( ! (nx % measure) ) */
  41. /* fl_line( nx, y(), nx, y() + h() ); */
  42. int X, Y, W, H;
  43. fl_clip_box( x(), y(), w(), h(), X, Y, W, H );
  44. draw( X, y(), W, h() );
  45. }
  46. void
  47. Waveform::read_peaks ( tick_t X, float *hi, float *lo )
  48. {
  49. _clip->peaks()->read( X, hi, lo );
  50. }
  51. void
  52. Waveform::draw ( int X, int Y, int W, int H )
  53. {
  54. fl_push_clip( X, Y, W, H );
  55. fl_push_matrix();
  56. int j;
  57. int start = (_start + (X - x())) * 2;
  58. j = 0;
  59. for ( int x = X; x < X + W; ++x )
  60. {
  61. // read_peaks( x, &hi, &lo );
  62. Peak p = (*_clip->peaks())[ x ];
  63. int mid = Y + (H / 2);
  64. // FIXME: cache this stuff.
  65. // fl_color( fl_color_average( selection_color(), fl_contrast( fl_darker( FL_BLUE ), selection_color() ), fabs( hi - lo ) ) );
  66. fl_color( fl_color_average( FL_RED, selection_color(), fabs( p.max - p.min ) ) );
  67. p.max *= _scale;
  68. p.min *= _scale;
  69. if ( p.min < -1.0 || p.max > 1.0 )
  70. fl_color( FL_RED );
  71. fl_line( x, mid + (H / 2 * p.min), x, mid + (H / 2 * p.max) );
  72. }
  73. fl_color( fl_darker( fl_darker( selection_color() ) ) );
  74. fl_line_style( FL_SOLID, 2 );
  75. fl_begin_line();
  76. for ( int x = X; x < X + W; ++x )
  77. {
  78. Peak p = (*_clip->peaks())[ x ];
  79. p.min *= _scale;
  80. fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.min ));
  81. }
  82. fl_end_line();
  83. fl_begin_line();
  84. for ( int x = X; x < X + W; ++x )
  85. {
  86. Peak p = (*_clip->peaks())[ x ];
  87. p.max *= _scale;
  88. fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.max ));
  89. }
  90. fl_end_line();
  91. fl_line_style( FL_SOLID, 0 );
  92. fl_pop_matrix();
  93. fl_pop_clip();
  94. }
  95. void
  96. Waveform::normalize ( void )
  97. {
  98. float mhi, mlo;
  99. _clip->peaks()->downsample( _start, _end, &mhi, &mlo );
  100. _scale = 1.0f / (float)mhi;
  101. if ( _scale * mlo < -1.0 )
  102. _scale = 1 / fabs( mlo );
  103. _scale = fabs( _scale );
  104. redraw();
  105. }