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.

200 lines
4.9KB

  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::use_gradient = true;
  21. bool Control_Sequence::use_polygon = true;
  22. Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 )
  23. {
  24. init();
  25. _track = track;
  26. if ( track )
  27. track->add( this );
  28. log_create();
  29. }
  30. Control_Sequence::~Control_Sequence ( )
  31. {
  32. log_destroy();
  33. }
  34. void
  35. Control_Sequence::init ( void )
  36. {
  37. _track = NULL;
  38. color( fl_darker( FL_GREEN ) );
  39. }
  40. void
  41. Control_Sequence::get ( Log_Entry &e )
  42. {
  43. Sequence::get( e );
  44. e.add( ":t", _track );
  45. }
  46. void
  47. Control_Sequence::set ( Log_Entry &e )
  48. {
  49. Sequence::set( e );
  50. for ( int i = 0; i < e.size(); ++i )
  51. {
  52. const char *s, *v;
  53. e.get( i, &s, &v );
  54. if ( ! strcmp( ":t", s ) )
  55. {
  56. int i;
  57. sscanf( v, "%X", &i );
  58. Track *t = (Track*)Loggable::find( i );
  59. assert( t );
  60. t->add( this );
  61. }
  62. }
  63. }
  64. void
  65. Control_Sequence::draw ( void )
  66. {
  67. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  68. return;
  69. fl_push_clip( x(), y(), w(), h() );
  70. draw_box();
  71. int X, Y, W, H;
  72. fl_clip_box( x(), y(), w(), h(), X, Y, W, H );
  73. if ( use_gradient )
  74. {
  75. Fl_Color target = fl_color_average( color(), FL_WHITE, 0.50f );
  76. for ( int gy = 0; gy < h(); gy++ )
  77. {
  78. fl_color( fl_color_average( target, selection_color(), gy / (float)h()) );
  79. fl_line( x(), y() + gy, x() + w(), y() + gy );
  80. }
  81. }
  82. fl_color( fl_color_average( selection_color(), color(), 0.90f ) );
  83. fl_line_style( FL_SOLID, 4 );
  84. if ( use_polygon )
  85. fl_begin_complex_polygon();
  86. else
  87. fl_begin_line();
  88. list <Sequence_Widget *>::const_iterator e = _widgets.end();
  89. e--;
  90. if ( _widgets.size() )
  91. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); ; r++ )
  92. {
  93. const int ry = (*r)->y();
  94. if ( r == _widgets.begin() )
  95. {
  96. if ( use_gradient )
  97. {
  98. fl_vertex( x(), y() );
  99. fl_vertex( x(), ry );
  100. }
  101. else
  102. {
  103. fl_vertex( x(), h() + y() );
  104. fl_vertex( x(), ry );
  105. }
  106. }
  107. fl_vertex( (*r)->x(), ry );
  108. if ( r == e )
  109. {
  110. if ( use_gradient )
  111. {
  112. fl_vertex( x() + w(), ry );
  113. fl_vertex( x() + w(), y() );
  114. }
  115. else
  116. {
  117. fl_vertex( x() + w(), ry );
  118. fl_vertex( x() + w(), h() + y() );
  119. }
  120. break;
  121. }
  122. }
  123. if ( use_polygon )
  124. fl_end_complex_polygon();
  125. else
  126. fl_end_line();
  127. fl_line_style( FL_SOLID, 0 );
  128. timeline->draw_measure_lines( x(), y(), w(), h(), color() );
  129. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  130. (*r)->draw_box();
  131. fl_pop_clip();
  132. }
  133. int
  134. Control_Sequence::handle ( int m )
  135. {
  136. int r = Sequence::handle( m );
  137. if ( r )
  138. return r;
  139. switch ( m )
  140. {
  141. case FL_PUSH:
  142. {
  143. if ( Fl::event_button1() )
  144. {
  145. Control_Point *r = new Control_Point( this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ), (float)(Fl::event_y() - y()) / h() );
  146. add( r );
  147. }
  148. return 1;
  149. }
  150. default:
  151. return 0;
  152. }
  153. }