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.

252 lines
6.5KB

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