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 -= _track->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 int ox, oy;
  73. static enum trim_e trimming;
  74. static bool copied = false;
  75. static nframes_t os;
  76. /* if ( ! active_r() ) */
  77. /* return 0; */
  78. // int X = Fl::event_x() - _track->x();
  79. int X = Fl::event_x();
  80. int Y = Fl::event_y();
  81. int ret;
  82. Logger _log( this );
  83. //log_r->start();
  84. switch ( m )
  85. {
  86. case FL_PUSH:
  87. {
  88. /* trimming */
  89. if ( Fl::event_shift() && ! Fl::event_ctrl() )
  90. {
  91. switch ( Fl::event_button() )
  92. {
  93. case 1:
  94. trim( trimming = LEFT, X );
  95. begin_drag( Drag( x() - X, y() - Y ) );
  96. _log.hold();
  97. break;
  98. case 3:
  99. trim( trimming = RIGHT, X );
  100. begin_drag( Drag( x() - X, y() - Y ) );
  101. _log.hold();
  102. break;
  103. default:
  104. return 0;
  105. break;
  106. }
  107. fl_cursor( FL_CURSOR_WE );
  108. return 1;
  109. }
  110. else if ( Fl::test_shortcut( FL_BUTTON3 ) )
  111. {
  112. if ( Sequence_Widget::current() == this )
  113. {
  114. if ( selected() )
  115. deselect();
  116. else
  117. select();
  118. }
  119. redraw();
  120. return 1;
  121. }
  122. else if ( Fl::test_shortcut( FL_CTRL + FL_BUTTON1 ) )
  123. {
  124. /* duplication */
  125. return 1;
  126. }
  127. else
  128. return Sequence_Widget::handle( m );
  129. break;
  130. }
  131. case FL_RELEASE:
  132. {
  133. Sequence_Widget::handle( m );
  134. copied = false;
  135. if ( trimming != NO )
  136. trimming = NO;
  137. return 1;
  138. }
  139. case FL_DRAG:
  140. {
  141. if ( ! _drag )
  142. {
  143. begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  144. _log.hold();
  145. }
  146. /* trimming */
  147. if ( Fl::event_state() & FL_SHIFT )
  148. if ( trimming )
  149. {
  150. trim( trimming, X );
  151. return 1;
  152. }
  153. else
  154. return 0;
  155. /* track jumping */
  156. if ( ! selected() )
  157. {
  158. if ( Y > y() + h() || Y < y() )
  159. {
  160. printf( "wants to jump tracks\n" );
  161. Track *t = timeline->track_under( Y );
  162. fl_cursor( (Fl_Cursor)1 );
  163. if ( t )
  164. t->handle( FL_ENTER );
  165. return 0;
  166. }
  167. }
  168. ret = Sequence_Widget::handle( m );
  169. return ret | 1;
  170. }
  171. default:
  172. return Sequence_Widget::handle( m );
  173. break;
  174. }
  175. }