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.

180 lines
4.3KB

  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=0 ) : 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. default:
  63. return 0;
  64. }
  65. return 1;
  66. }
  67. return 0;
  68. }
  69. void
  70. Waveform::draw ( void )
  71. {
  72. fl_push_clip( x(), y(), w(), h() );
  73. draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() );
  74. fl_push_matrix();
  75. fl_color( selection_color() );
  76. int j;
  77. float scale = 1;
  78. j = 0;
  79. for ( tick_t x = 0; x < w() && x < _end; ++x )
  80. {
  81. float lo = _peaks[ _start + j++ ] * scale;
  82. float hi = _peaks[ _start + j++ ] * scale;
  83. int mid = y() + (h() / 2);
  84. int rx = this->x() + x;
  85. fl_line( rx, mid + (h() * lo), rx, mid + (h() * hi) );
  86. }
  87. fl_color( fl_darker( fl_darker( selection_color() ) ) );
  88. fl_begin_line();
  89. j = 0;
  90. for ( tick_t x = 0; x < w() && x < _end; ++x )
  91. {
  92. float v = _peaks[ _start + j ] * scale;
  93. j += 2;
  94. fl_vertex( this->x() + x, y() + (h() / 2) + ((float)h() * v ));
  95. }
  96. fl_end_line();
  97. fl_begin_line();
  98. j = 1;
  99. for ( tick_t x = 0; x < w() && x < _end; ++x )
  100. {
  101. float v = _peaks[ _start + j ] * scale;
  102. j += 2;
  103. fl_vertex( this->x() + x, y() + (h() / 2) + ((float)h() * v ));
  104. }
  105. fl_end_line();
  106. fl_pop_matrix();
  107. fl_pop_clip();
  108. }
  109. #if 0
  110. void
  111. Waveform::draw ( void )
  112. {
  113. fl_push_clip( x(), y(), w(), h() );
  114. draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() );
  115. fl_push_matrix();
  116. int inc = 1;
  117. int j = 0;
  118. for ( tick_t x = 0; x < w() && x < _end; ++x )
  119. {
  120. float lo = _peaks[ _start + j++ ];
  121. float hi = _peaks[ _start + j++ ];
  122. int mid = y() + (h() / 2);
  123. int rx = this->x() + x;
  124. fl_color( selection_color() );
  125. fl_line( rx, mid + (h() * lo), rx, mid + (h() * hi) );
  126. }
  127. fl_pop_matrix();
  128. }
  129. #endif