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.

189 lines
4.7KB

  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 <math.h>
  23. extern Fl_Color velocity_colors[];
  24. Waveform::Waveform ( int X, int Y, int W, int H, const char *L ) : Fl_Widget( X, Y, W, H, L )
  25. {
  26. }
  27. void
  28. Waveform::bubble_draw ( void )
  29. {
  30. int inc = 10;
  31. for ( tick_t x = 0; x < w() && x < _end; ++x )
  32. {
  33. float v1 = _peaks[ _start + (x * inc) ] / (float)127;
  34. int lh1 = (float)(h() / 2) * fabs( v1 );
  35. int ly1 = (h() / 2) - (lh1 / 2);
  36. fl_color( selection_color() );
  37. fl_color( velocity_colors[ 127 - (int)(127 * fabs( v1 )) ] );
  38. fl_pie( x, y() + ly1, inc, lh1, 0, 360 );
  39. fl_color( fl_darker( selection_color() ) );
  40. fl_arc( x, y() + ly1, inc, lh1, 0, 360 );
  41. }
  42. }
  43. int
  44. Waveform::handle ( int m )
  45. {
  46. if ( m == FL_PUSH )
  47. {
  48. switch ( Fl::event_button() )
  49. {
  50. case 1:
  51. _start += 100;
  52. _end += 100;
  53. redraw();
  54. break;
  55. case 3:
  56. _start -= 100;
  57. _end -= 100;
  58. redraw();
  59. break;
  60. case 2:
  61. selection_color( selection_color() + 10 );
  62. redraw();
  63. break;
  64. default:
  65. return 0;
  66. }
  67. return 1;
  68. }
  69. return 0;
  70. }
  71. int measure = 50;
  72. void
  73. Waveform::draw ( void )
  74. {
  75. // draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() );
  76. /* fl_color( fl_lighter( color() ) ); */
  77. /* for ( int nx = x(); nx < x() + w(); ++nx ) */
  78. /* if ( ! (nx % measure) ) */
  79. /* fl_line( nx, y(), nx, y() + h() ); */
  80. int X, Y, W, H;
  81. fl_clip_box( x(), y(), w(), h(), X, Y, W, H );
  82. draw( X, y(), W, h() );
  83. }
  84. void
  85. Waveform::draw ( int X, int Y, int W, int H )
  86. {
  87. fl_push_clip( X, Y, W, H );
  88. fl_push_matrix();
  89. int j;
  90. float _scale = 2;
  91. int start = (_start + (X - x())) * 2;
  92. j = 0;
  93. for ( int x = X; x < X + W; ++x )
  94. {
  95. float lo = _peaks[ start + j++ ] * _scale;
  96. float hi = _peaks[ start + j++ ] * _scale;
  97. int mid = Y + (H / 2);
  98. if ( lo < -1.0 || hi > 1.0 )
  99. fl_color( FL_RED );
  100. else
  101. fl_color( selection_color() );
  102. // fl_color( velocity_colors[ 127 - (int)( 127 * fabs( hi - lo ) ) ] );
  103. // FIXME: cache this stuff.
  104. // fl_color( fl_color_average( selection_color(), fl_contrast( fl_darker( FL_BLUE ), selection_color() ), fabs( hi - lo ) ) );
  105. fl_color( fl_color_average( FL_RED, selection_color(), fabs( hi - lo ) ) );
  106. if ( lo < -0.5 || hi > 0.5 )
  107. fl_color( FL_RED );
  108. fl_line( x, mid + (H * lo), x, mid + (H * hi) );
  109. }
  110. fl_color( fl_darker( fl_darker( selection_color() ) ) );
  111. fl_line_style( FL_SOLID, 2 );
  112. fl_begin_line();
  113. j = 0;
  114. for ( int x = X; x < X + W; ++x )
  115. {
  116. float v = _peaks[ start + j ] * _scale;
  117. j += 2;
  118. fl_vertex( x, Y + (H / 2) + ((float)H * v ));
  119. }
  120. fl_end_line();
  121. fl_begin_line();
  122. j = 1;
  123. for ( int x = X; x < X + W; ++x )
  124. {
  125. float v = _peaks[ start + j ] * _scale;
  126. j += 2;
  127. fl_vertex( x, Y + (H / 2) + ((float)H * v ));
  128. }
  129. fl_end_line();
  130. fl_line_style( FL_SOLID, 0 );
  131. fl_pop_matrix();
  132. fl_pop_clip();
  133. }