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.

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