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.

161 lines
4.1KB

  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::draw ( int X, int Y, int W, int H )
  48. {
  49. fl_push_clip( X, Y, W, H );
  50. // fl_push_matrix();
  51. int j;
  52. // int start = (_start + (X - x())) * 2;
  53. int start = timeline.ts_to_x( _start ) + (X - x() );
  54. {
  55. nframes_t start = timeline.x_to_ts( X - x() ) + _start;
  56. _clip->peaks()->fill_buffer( start,
  57. start + timeline.x_to_ts( W ) );
  58. }
  59. j = start;
  60. for ( int x = X; x < X + W; ++x, ++j )
  61. {
  62. // read_peaks( x, &hi, &lo );
  63. Peak p = (*_clip->peaks())[ j ];
  64. int mid = Y + (H / 2);
  65. // FIXME: cache this stuff.
  66. // fl_color( fl_color_average( selection_color(), fl_contrast( fl_darker( FL_BLUE ), selection_color() ), fabs( hi - lo ) ) );
  67. fl_color( fl_color_average( FL_RED, selection_color(), fabs( p.max - p.min ) ) );
  68. p.max *= _scale;
  69. p.min *= _scale;
  70. if ( p.min < -1.0 || p.max > 1.0 )
  71. fl_color( FL_RED );
  72. fl_line( x, mid + (H / 2 * p.min), x, mid + (H / 2 * p.max) );
  73. }
  74. fl_color( fl_darker( fl_darker( selection_color() ) ) );
  75. fl_line_style( FL_SOLID, 2 );
  76. fl_begin_line();
  77. j = start;
  78. for ( int x = X; x < X + W; ++x, ++j )
  79. {
  80. Peak p = (*_clip->peaks())[ j ];
  81. p.min *= _scale;
  82. fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.min ));
  83. }
  84. fl_end_line();
  85. fl_begin_line();
  86. j = start;
  87. for ( int x = X; x < X + W; ++x, ++j )
  88. {
  89. Peak p = (*_clip->peaks())[ j ];
  90. p.max *= _scale;
  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. // fl_pop_matrix();
  96. fl_pop_clip();
  97. }
  98. void
  99. Waveform::normalize ( void )
  100. {
  101. float mhi, mlo;
  102. _clip->peaks()->downsample( _start, _end, &mhi, &mlo );
  103. _scale = 1.0f / (float)mhi;
  104. if ( _scale * mlo < -1.0 )
  105. _scale = 1 / fabs( mlo );
  106. _scale = fabs( _scale );
  107. redraw();
  108. }