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.

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