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.

216 lines
5.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 "Sequence_Region.H"
  19. #include "Track.H"
  20. void
  21. Sequence_Region::draw_box ( void )
  22. {
  23. fl_draw_box( box(), x(), y(), w(), h(), box_color() );
  24. }
  25. void
  26. Sequence_Region::draw ( void )
  27. {
  28. }
  29. void
  30. Sequence_Region::trim ( enum trim_e t, int X )
  31. {
  32. X -= sequence()->x();
  33. redraw();
  34. switch ( t )
  35. {
  36. case LEFT:
  37. {
  38. /* if ( d < 0 ) */
  39. /* // _track->damage( FL_DAMAGE_EXPOSE, x() + d, y(), 1 - d, h() ); */
  40. /* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() ); */
  41. /* else */
  42. /* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), d, h() ); */
  43. int d = X - ( abs_x() - scroll_x() );
  44. long td = timeline->x_to_ts( d );
  45. if ( td < 0 && _r->start < 0 - td )
  46. td = 0 - _r->start;
  47. if ( _r->start + td >= _r->end )
  48. td = (_r->end - _r->start) - timeline->x_to_ts( 1 );
  49. _r->start += td;
  50. _r->offset += td;
  51. break;
  52. }
  53. case RIGHT:
  54. {
  55. int d = (( abs_x() - scroll_x() ) + abs_w() ) - X;
  56. /* _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), d, h() ); */
  57. long td = timeline->x_to_ts( d );
  58. // printf( "%li %li\n", td, _r->end - _r->start );
  59. if ( td >= 0 && _r->end - _r->start < td )
  60. _r->end = _r->start + timeline->x_to_ts( 1 );
  61. else
  62. _r->end -= td;
  63. break;
  64. }
  65. default:
  66. return;
  67. }
  68. }
  69. int
  70. Sequence_Region::handle ( int m )
  71. {
  72. static enum trim_e trimming;
  73. static bool copied = false;
  74. /* if ( ! active_r() ) */
  75. /* return 0; */
  76. // int X = Fl::event_x() - _track->x();
  77. int X = Fl::event_x();
  78. int Y = Fl::event_y();
  79. int ret;
  80. Logger _log( this );
  81. //log_r->start();
  82. switch ( m )
  83. {
  84. case FL_PUSH:
  85. {
  86. /* trimming */
  87. if ( Fl::event_shift() && ! Fl::event_ctrl() )
  88. {
  89. switch ( Fl::event_button() )
  90. {
  91. case 1:
  92. trim( trimming = LEFT, X );
  93. begin_drag( Drag( x() - X, y() - Y ) );
  94. _log.hold();
  95. break;
  96. case 3:
  97. trim( trimming = RIGHT, X );
  98. begin_drag( Drag( x() - X, y() - Y ) );
  99. _log.hold();
  100. break;
  101. default:
  102. return 0;
  103. break;
  104. }
  105. fl_cursor( FL_CURSOR_WE );
  106. return 1;
  107. }
  108. else if ( Fl::test_shortcut( FL_BUTTON2 ) && ! Fl::event_shift() )
  109. {
  110. if ( Sequence_Widget::current() == this )
  111. {
  112. if ( selected() )
  113. deselect();
  114. else
  115. select();
  116. }
  117. redraw();
  118. return 1;
  119. }
  120. else if ( Fl::test_shortcut( FL_CTRL + FL_BUTTON1 ) )
  121. {
  122. /* duplication */
  123. return 1;
  124. }
  125. else
  126. return Sequence_Widget::handle( m );
  127. break;
  128. }
  129. case FL_RELEASE:
  130. {
  131. Sequence_Widget::handle( m );
  132. copied = false;
  133. if ( trimming != NO )
  134. trimming = NO;
  135. return 1;
  136. }
  137. case FL_DRAG:
  138. {
  139. if ( ! _drag )
  140. {
  141. begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  142. _log.hold();
  143. }
  144. /* trimming */
  145. if ( Fl::event_state() & FL_SHIFT )
  146. if ( trimming )
  147. {
  148. trim( trimming, X );
  149. return 1;
  150. }
  151. else
  152. return 0;
  153. /* track jumping */
  154. if ( ! selected() )
  155. {
  156. if ( Y > y() + h() || Y < y() )
  157. {
  158. printf( "wants to jump tracks\n" );
  159. Track *t = timeline->track_under( Y );
  160. fl_cursor( (Fl_Cursor)1 );
  161. if ( t )
  162. t->handle( FL_ENTER );
  163. return 0;
  164. }
  165. }
  166. ret = Sequence_Widget::handle( m );
  167. return ret | 1;
  168. }
  169. default:
  170. return Sequence_Widget::handle( m );
  171. break;
  172. }
  173. return 0;
  174. }