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.

219 lines
5.5KB

  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_GREEN ) );
  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 ( void )
  67. {
  68. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  69. return;
  70. fl_push_clip( x(), y(), w(), h() );
  71. /* draw the box with the ends cut off. */
  72. draw_box( box(), x() - Fl::box_dx( box() ), y(), w() + Fl::box_dw( box() ), h(), color() );
  73. const int bx = x();
  74. const int by = y() + Fl::box_dy( box() );
  75. const int bw = w();
  76. const int bh = h() - Fl::box_dh( box() );
  77. int X, Y, W, H;
  78. fl_clip_box( bx, by, bw, bh, X, Y, W, H );
  79. if ( draw_with_gradient )
  80. {
  81. Fl_Color target = fl_color_average( color(), FL_WHITE, 0.50f );
  82. for ( int gy = 0; gy < bh; gy++ )
  83. {
  84. fl_color( fl_color_average( target, selection_color(), gy / (float)bh) );
  85. fl_line( X, by + gy, X + W, by + gy );
  86. }
  87. }
  88. if ( draw_with_grid )
  89. {
  90. fl_color( fl_darker( color() ) );
  91. const int inc = bh / 10;
  92. if ( inc )
  93. for ( int gy = 0; gy < bh; gy += inc )
  94. fl_line( X, by + gy, X + W, by + gy );
  95. }
  96. fl_color( fl_color_average( selection_color(), color(), 0.90f ) );
  97. fl_line_style( FL_SOLID, 4 );
  98. if ( draw_with_polygon )
  99. fl_begin_complex_polygon();
  100. else
  101. fl_begin_line();
  102. list <Sequence_Widget *>::const_iterator e = _widgets.end();
  103. e--;
  104. if ( _widgets.size() )
  105. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); ; r++ )
  106. {
  107. const int ry = (*r)->y();
  108. if ( r == _widgets.begin() )
  109. {
  110. if ( draw_with_gradient )
  111. {
  112. fl_vertex( bx, by );
  113. fl_vertex( bx, ry );
  114. }
  115. else
  116. {
  117. fl_vertex( bx, bh + by );
  118. fl_vertex( bx, ry );
  119. }
  120. }
  121. fl_vertex( (*r)->x(), ry );
  122. if ( r == e )
  123. {
  124. if ( draw_with_gradient )
  125. {
  126. fl_vertex( bx + bw, ry );
  127. fl_vertex( bx + bw, by );
  128. }
  129. else
  130. {
  131. fl_vertex( bx + bw, ry );
  132. fl_vertex( bx + bw, bh + by );
  133. }
  134. break;
  135. }
  136. }
  137. if ( draw_with_polygon )
  138. fl_end_complex_polygon();
  139. else
  140. fl_end_line();
  141. fl_line_style( FL_SOLID, 0 );
  142. timeline->draw_measure_lines( x(), y(), w(), h(), color() );
  143. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  144. (*r)->draw_box();
  145. fl_pop_clip();
  146. }
  147. int
  148. Control_Sequence::handle ( int m )
  149. {
  150. int r = Sequence::handle( m );
  151. if ( r )
  152. return r;
  153. switch ( m )
  154. {
  155. case FL_PUSH:
  156. {
  157. if ( Fl::event_button1() )
  158. {
  159. Control_Point *r = new Control_Point( this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ), (float)(Fl::event_y() - y()) / h() );
  160. add( r );
  161. }
  162. return 1;
  163. }
  164. default:
  165. return 0;
  166. }
  167. }