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.

266 lines
6.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 "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. const Fl_Color color = active_r() ? this->color() : fl_inactive( this->color() );
  128. const Fl_Color selection_color = active_r() ? this->selection_color() : fl_inactive( this->selection_color() );
  129. if ( draw_with_gradient )
  130. {
  131. // Fl_Color target = fl_color_average( color, FL_WHITE, 0.50f );
  132. const Fl_Color c2 = fl_color_average( selection_color, FL_WHITE, 0.75f );
  133. const Fl_Color c1 = fl_color_average( color, c2, 0.60f );
  134. for ( int gy = 0; gy < bh; gy++ )
  135. {
  136. fl_color( fl_color_average( c1, c2, gy / (float)bh) );
  137. fl_line( X, by + gy, X + W, by + gy );
  138. }
  139. }
  140. if ( draw_with_grid )
  141. {
  142. fl_color( fl_darker( color ) );
  143. const int inc = bh / 10;
  144. if ( inc )
  145. for ( int gy = 0; gy < bh; gy += inc )
  146. fl_line( X, by + gy, X + W, by + gy );
  147. }
  148. if ( draw_with_polygon )
  149. {
  150. fl_begin_complex_polygon();
  151. draw_curve( draw_with_gradient, true );
  152. fl_end_complex_polygon();
  153. fl_color( selection_color );
  154. fl_line_style( FL_SOLID, 2 );
  155. fl_begin_line();
  156. draw_curve( draw_with_gradient, false );
  157. fl_end_line();
  158. }
  159. else
  160. {
  161. // fl_color( fl_color_average( selection_color, color, 0.70f ) );
  162. fl_color( selection_color );
  163. fl_line_style( FL_SOLID, 2 );
  164. fl_begin_line();
  165. draw_curve( draw_with_gradient, false );
  166. fl_end_line();
  167. }
  168. fl_line_style( FL_SOLID, 0 );
  169. timeline->draw_measure_lines( x(), y(), w(), h(), color );
  170. if ( _highlighted )
  171. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  172. (*r)->draw_box();
  173. fl_pop_clip();
  174. }
  175. int
  176. Control_Sequence::handle ( int m )
  177. {
  178. switch ( m )
  179. {
  180. case FL_ENTER:
  181. _highlighted = true;
  182. redraw();
  183. return 1;
  184. case FL_LEAVE:
  185. _highlighted = false;
  186. redraw();
  187. return 1;
  188. default:
  189. break;
  190. }
  191. int r = Sequence::handle( m );
  192. if ( r )
  193. return r;
  194. switch ( m )
  195. {
  196. case FL_PUSH:
  197. {
  198. if ( Fl::event_button1() )
  199. {
  200. Control_Point *r = new Control_Point( this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ), (float)(Fl::event_y() - y()) / h() );
  201. add( r );
  202. }
  203. return 1;
  204. }
  205. default:
  206. return 0;
  207. }
  208. }