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.

263 lines
7.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", (int)_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;
  73. /* snap to beat/bar lines */
  74. if ( timeline->nearest_line( _r->start, &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;
  88. /* snap to beat/bar lines */
  89. if ( timeline->nearest_line( _r->start + _r->length, &f ) )
  90. _r->set_right( f );
  91. break;
  92. }
  93. default:
  94. return;
  95. }
  96. }
  97. int
  98. Sequence_Region::handle ( int m )
  99. {
  100. static enum trim_e trimming;
  101. static bool copied = false;
  102. int X = Fl::event_x();
  103. int Y = Fl::event_y();
  104. Logger _log( this );
  105. switch ( m )
  106. {
  107. case FL_PUSH:
  108. {
  109. /* trimming */
  110. if ( Fl::event_shift() && ! Fl::event_ctrl() )
  111. {
  112. switch ( Fl::event_button() )
  113. {
  114. case 1:
  115. trim( trimming = LEFT, X );
  116. begin_drag( Drag( x() - X, y() - Y ) );
  117. _log.hold();
  118. break;
  119. case 3:
  120. trim( trimming = RIGHT, X );
  121. begin_drag( Drag( x() - X, y() - Y ) );
  122. _log.hold();
  123. break;
  124. default:
  125. return 0;
  126. break;
  127. }
  128. fl_cursor( FL_CURSOR_WE );
  129. return 1;
  130. }
  131. else if ( Fl::test_shortcut( FL_BUTTON2 ) && ! Fl::event_shift() )
  132. {
  133. if ( Sequence_Widget::current() == this )
  134. {
  135. if ( selected() )
  136. deselect();
  137. else
  138. select();
  139. }
  140. redraw();
  141. return 1;
  142. }
  143. else if ( Fl::test_shortcut( FL_CTRL + FL_BUTTON1 ) && ! Fl::event_shift() )
  144. {
  145. /* duplication */
  146. fl_cursor( FL_CURSOR_MOVE );
  147. return 1;
  148. }
  149. else
  150. return Sequence_Widget::handle( m );
  151. }
  152. case FL_RELEASE:
  153. {
  154. Sequence_Widget::handle( m );
  155. copied = false;
  156. if ( trimming != NO )
  157. trimming = NO;
  158. return 1;
  159. }
  160. case FL_DRAG:
  161. {
  162. if ( ! _drag )
  163. {
  164. begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  165. _log.hold();
  166. }
  167. /* trimming */
  168. if ( Fl::event_shift() )
  169. {
  170. if ( trimming )
  171. {
  172. trim( trimming, X );
  173. return 1;
  174. }
  175. else
  176. return 0;
  177. }
  178. else if ( Fl::event_button1() )
  179. {
  180. if ( Fl::event_state() & FL_CTRL )
  181. {
  182. /* duplication */
  183. if ( _drag->state == 0 )
  184. {
  185. // sequence()->add( new Audio_Region( *this ) );
  186. sequence()->add( this->clone() );
  187. _drag->state = 1;
  188. return 1;
  189. }
  190. }
  191. else if ( Fl::test_shortcut( FL_BUTTON1 ) && ! Fl::event_shift() && ! selected() )
  192. {
  193. /* track jumping */
  194. if ( Y > y() + h() || Y < y() )
  195. {
  196. Track *t = timeline->track_under( Y );
  197. fl_cursor( (Fl_Cursor)1 );
  198. if ( t )
  199. t->handle( FL_ENTER );
  200. return 0;
  201. }
  202. }
  203. }
  204. return Sequence_Widget::handle( m );
  205. }
  206. default:
  207. return Sequence_Widget::handle( m );
  208. break;
  209. }
  210. return 0;
  211. }