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.

260 lines
7.0KB

  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->offset += td;
  72. _r->start += td;
  73. _r->length -= td;
  74. break;
  75. }
  76. case RIGHT:
  77. {
  78. int d = (( abs_x() - scroll_x() ) + abs_w() ) - X;
  79. /* _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), d, h() ); */
  80. long td = timeline->x_to_ts( d );
  81. // printf( "%li %li\n", td, _r->length - _r->offset );
  82. if ( td >= 0 && _r->length < (nframes_t)td )
  83. _r->length = timeline->x_to_ts( 1 );
  84. else
  85. _r->length -= td;
  86. break;
  87. }
  88. default:
  89. return;
  90. }
  91. }
  92. int
  93. Sequence_Region::handle ( int m )
  94. {
  95. static enum trim_e trimming;
  96. static bool copied = false;
  97. /* if ( ! active_r() ) */
  98. /* return 0; */
  99. // int X = Fl::event_x() - _track->x();
  100. int X = Fl::event_x();
  101. int Y = Fl::event_y();
  102. int ret;
  103. Logger _log( this );
  104. //log_r->offset();
  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 ) )
  144. {
  145. /* duplication */
  146. return 1;
  147. }
  148. else
  149. return Sequence_Widget::handle( m );
  150. break;
  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_state() & FL_SHIFT )
  169. if ( trimming )
  170. {
  171. trim( trimming, X );
  172. return 1;
  173. }
  174. else
  175. return 0;
  176. else if ( Fl::event_button1() )
  177. {
  178. if ( Fl::event_state() & FL_CTRL )
  179. {
  180. /* duplication */
  181. if ( _drag->state == 0 )
  182. {
  183. // sequence()->add( new Audio_Region( *this ) );
  184. sequence()->add( this->clone() );
  185. _drag->state = 1;
  186. return 1;
  187. }
  188. }
  189. else if ( ! selected() )
  190. {
  191. /* track jumping */
  192. if ( Y > y() + h() || Y < y() )
  193. {
  194. Track *t = timeline->track_under( Y );
  195. fl_cursor( (Fl_Cursor)1 );
  196. if ( t )
  197. t->handle( FL_ENTER );
  198. return 0;
  199. }
  200. }
  201. }
  202. ret = Sequence_Widget::handle( m );
  203. return ret | 1;
  204. }
  205. default:
  206. return Sequence_Widget::handle( m );
  207. break;
  208. }
  209. return 0;
  210. }