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.

134 lines
3.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 <FL/fl_draw.H>
  19. #include "Control_Point.H"
  20. Control_Point::Control_Point ( Sequence *t, nframes_t when, float y )
  21. {
  22. _sequence = t;
  23. _y = y;
  24. _r->start = when;
  25. _box_color = FL_WHITE;
  26. log_create();
  27. }
  28. Control_Point::Control_Point ( const Control_Point &rhs ) : Sequence_Point( rhs )
  29. {
  30. _y = rhs._y;
  31. log_create();
  32. }
  33. void
  34. Control_Point::get ( Log_Entry &e ) const
  35. {
  36. Sequence_Point::get( e );
  37. e.add( ":y", _y );
  38. }
  39. void
  40. Control_Point::set ( Log_Entry &e )
  41. {
  42. for ( int i = 0; i < e.size(); ++i )
  43. {
  44. const char *s, *v;
  45. e.get( i, &s, &v );
  46. if ( ! strcmp( s, ":y" ) )
  47. _y = atof( v );
  48. redraw();
  49. // _make_label();
  50. }
  51. Sequence_Point::set( e );
  52. }
  53. void
  54. Control_Point::draw_box ( void )
  55. {
  56. if ( selected() )
  57. fl_color( selection_color() );
  58. else
  59. fl_color( box_color() );
  60. fl_pie( x() - w() / 2, y() - h() / 2, w(), h(), 0, 360 );
  61. if ( this == Sequence_Widget::belowmouse() ||
  62. this == Sequence_Widget::pushed() )
  63. {
  64. char val[10];
  65. snprintf( val, sizeof( val ), "%+.2f", 1.0 - _y * 2 );
  66. Fl_Align a = 0;
  67. if ( x() < _sequence->x() + ( _sequence->w() / 2 ) )
  68. a |= FL_ALIGN_RIGHT;
  69. else
  70. a |= FL_ALIGN_LEFT;
  71. if ( y() < _sequence->y() + ( _sequence->h() / 2 ) )
  72. a |= FL_ALIGN_BOTTOM;
  73. else
  74. a |= FL_ALIGN_TOP;
  75. draw_label( val, a, FL_FOREGROUND_COLOR );
  76. }
  77. }
  78. int
  79. Control_Point::handle ( int m )
  80. {
  81. int r = Sequence_Widget::handle( m );
  82. switch ( m )
  83. {
  84. case FL_RELEASE:
  85. redraw();
  86. break;
  87. case FL_DRAG:
  88. {
  89. if ( nselected() > 1 )
  90. // only allow horizontal movement when part of a selection...
  91. break;
  92. int Y = Fl::event_y() - parent()->y();
  93. if ( Y >= 0 && Y < parent()->h() )
  94. {
  95. _y = (float)Y / parent()->h();
  96. redraw();
  97. }
  98. break;
  99. }
  100. }
  101. return r;
  102. }