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.

262 lines
6.6KB

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