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.

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