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.

235 lines
6.2KB

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