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.

269 lines
7.3KB

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