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.

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