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.

245 lines
6.2KB

  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 "Control_Sequence.H"
  19. #include "Track.H"
  20. bool Control_Sequence::draw_with_gradient = true;
  21. bool Control_Sequence::draw_with_polygon = true;
  22. bool Control_Sequence::draw_with_grid = true;
  23. Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 )
  24. {
  25. init();
  26. _track = track;
  27. if ( track )
  28. track->add( this );
  29. log_create();
  30. }
  31. Control_Sequence::~Control_Sequence ( )
  32. {
  33. log_destroy();
  34. }
  35. void
  36. Control_Sequence::init ( void )
  37. {
  38. _track = NULL;
  39. color( fl_darker( FL_YELLOW ) );
  40. }
  41. void
  42. Control_Sequence::get ( Log_Entry &e )
  43. {
  44. Sequence::get( e );
  45. e.add( ":t", _track );
  46. }
  47. void
  48. Control_Sequence::set ( Log_Entry &e )
  49. {
  50. Sequence::set( e );
  51. for ( int i = 0; i < e.size(); ++i )
  52. {
  53. const char *s, *v;
  54. e.get( i, &s, &v );
  55. if ( ! strcmp( ":t", s ) )
  56. {
  57. int i;
  58. sscanf( v, "%X", &i );
  59. Track *t = (Track*)Loggable::find( i );
  60. assert( t );
  61. t->add( this );
  62. }
  63. }
  64. }
  65. void
  66. Control_Sequence::draw_curve ( bool flip, bool filled )
  67. {
  68. const int bx = x();
  69. const int by = y() + Fl::box_dy( box() );
  70. const int bw = w();
  71. const int bh = h() - Fl::box_dh( box() );
  72. list <Sequence_Widget *>::const_iterator e = _widgets.end();
  73. e--;
  74. if ( _widgets.size() )
  75. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); ; r++ )
  76. {
  77. const int ry = (*r)->y();
  78. if ( r == _widgets.begin() )
  79. {
  80. if ( flip )
  81. {
  82. if ( filled )
  83. fl_vertex( bx, by );
  84. fl_vertex( bx, ry );
  85. }
  86. else
  87. {
  88. if ( filled )
  89. fl_vertex( bx, bh + by );
  90. fl_vertex( bx, ry );
  91. }
  92. }
  93. fl_vertex( (*r)->x(), ry );
  94. if ( r == e )
  95. {
  96. if ( flip )
  97. {
  98. fl_vertex( bx + bw, ry );
  99. if ( filled )
  100. fl_vertex( bx + bw, by );
  101. }
  102. else
  103. {
  104. fl_vertex( bx + bw, ry );
  105. if ( filled )
  106. fl_vertex( bx + bw, bh + by );
  107. }
  108. break;
  109. }
  110. }
  111. }
  112. void
  113. Control_Sequence::draw ( void )
  114. {
  115. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  116. return;
  117. fl_push_clip( x(), y(), w(), h() );
  118. /* draw the box with the ends cut off. */
  119. draw_box( box(), x() - Fl::box_dx( box() ), y(), w() + Fl::box_dw( box() ), h(), color() );
  120. const int bx = x();
  121. const int by = y() + Fl::box_dy( box() );
  122. const int bw = w();
  123. const int bh = h() - Fl::box_dh( box() );
  124. int X, Y, W, H;
  125. fl_clip_box( bx, by, bw, bh, X, Y, W, H );
  126. if ( draw_with_gradient )
  127. {
  128. // Fl_Color target = fl_color_average( color(), FL_WHITE, 0.50f );
  129. const Fl_Color c2 = fl_color_average( selection_color(), FL_WHITE, 0.75f );
  130. const Fl_Color c1 = fl_color_average( color(), c2, 0.60f );
  131. for ( int gy = 0; gy < bh; gy++ )
  132. {
  133. fl_color( fl_color_average( c1, c2, gy / (float)bh) );
  134. fl_line( X, by + gy, X + W, by + gy );
  135. }
  136. }
  137. if ( draw_with_grid )
  138. {
  139. fl_color( fl_darker( color() ) );
  140. const int inc = bh / 10;
  141. if ( inc )
  142. for ( int gy = 0; gy < bh; gy += inc )
  143. fl_line( X, by + gy, X + W, by + gy );
  144. }
  145. if ( draw_with_polygon )
  146. {
  147. fl_begin_complex_polygon();
  148. draw_curve( draw_with_gradient, true );
  149. fl_end_complex_polygon();
  150. fl_color( selection_color() );
  151. fl_line_style( FL_SOLID, 2 );
  152. fl_begin_line();
  153. draw_curve( draw_with_gradient, false );
  154. fl_end_line();
  155. }
  156. else
  157. {
  158. // fl_color( fl_color_average( selection_color(), color(), 0.70f ) );
  159. fl_color( selection_color() );
  160. fl_line_style( FL_SOLID, 2 );
  161. fl_begin_line();
  162. draw_curve( draw_with_gradient, false );
  163. fl_end_line();
  164. }
  165. fl_line_style( FL_SOLID, 0 );
  166. timeline->draw_measure_lines( x(), y(), w(), h(), color() );
  167. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  168. (*r)->draw_box();
  169. fl_pop_clip();
  170. }
  171. int
  172. Control_Sequence::handle ( int m )
  173. {
  174. int r = Sequence::handle( m );
  175. if ( r )
  176. return r;
  177. switch ( m )
  178. {
  179. case FL_PUSH:
  180. {
  181. if ( Fl::event_button1() )
  182. {
  183. Control_Point *r = new Control_Point( this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ), (float)(Fl::event_y() - y()) / h() );
  184. add( r );
  185. }
  186. return 1;
  187. }
  188. default:
  189. return 0;
  190. }
  191. }