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.

254 lines
6.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. 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_left ( nframes_t where )
  53. {
  54. long td = where - _r->start;
  55. if ( td < 0 && _r->offset < (nframes_t)( 0 - td ) )
  56. td = 0 - _r->offset;
  57. if ( td > 0 && (nframes_t)td >= _r->length )
  58. td = _r->length - timeline->x_to_ts( 1 );
  59. _r->trim_left( 0 - td );
  60. nframes_t f = _r->start;
  61. /* snap to beat/bar lines */
  62. if ( timeline->nearest_line( &f ) )
  63. _r->set_left( f );
  64. }
  65. void
  66. Sequence_Region::trim_right ( nframes_t where )
  67. {
  68. long td = ( _r->start + _r->length ) - where;
  69. if ( td >= 0 && _r->length < (nframes_t)td )
  70. td = _r->length - timeline->x_to_ts( 1 );
  71. _r->trim_right( 0 - td );
  72. nframes_t f = _r->start + _r->length;
  73. /* snap to beat/bar lines */
  74. if ( timeline->nearest_line( &f ) )
  75. _r->set_right( f );
  76. }
  77. void
  78. Sequence_Region::trim ( enum trim_e t, int X )
  79. {
  80. redraw();
  81. nframes_t where = timeline->x_to_offset( X );
  82. switch ( t )
  83. {
  84. case LEFT:
  85. trim_left( where );
  86. break;
  87. case RIGHT:
  88. trim_right( where );
  89. break;
  90. default:
  91. break;
  92. }
  93. }
  94. /** split region at absolute frame /where/. due to inheritance issues,
  95. * the copy must be made in the derived classed and passed in */
  96. void
  97. Sequence_Region::split ( Sequence_Region * copy, nframes_t where )
  98. {
  99. trim_right( where );
  100. copy->trim_left( where );
  101. sequence()->add( copy );
  102. }
  103. #include "FL/test_press.H"
  104. int
  105. Sequence_Region::handle ( int m )
  106. {
  107. static enum trim_e trimming;
  108. static bool copied = false;
  109. int X = Fl::event_x();
  110. int Y = Fl::event_y();
  111. Logger _log( this );
  112. switch ( m )
  113. {
  114. case FL_PUSH:
  115. {
  116. /* trimming */
  117. if ( Fl::event_shift() && ! Fl::event_ctrl() )
  118. {
  119. switch ( Fl::event_button() )
  120. {
  121. case 1:
  122. trim( trimming = LEFT, X );
  123. begin_drag( Drag( x() - X, y() - Y ) );
  124. _log.hold();
  125. break;
  126. case 3:
  127. trim( trimming = RIGHT, X );
  128. begin_drag( Drag( x() - X, y() - Y ) );
  129. _log.hold();
  130. break;
  131. default:
  132. return 0;
  133. break;
  134. }
  135. fl_cursor( FL_CURSOR_WE );
  136. return 1;
  137. }
  138. else if ( test_press( FL_BUTTON2 ) )
  139. {
  140. if ( Sequence_Widget::current() == this )
  141. {
  142. if ( selected() )
  143. deselect();
  144. else
  145. select();
  146. }
  147. redraw();
  148. return 1;
  149. }
  150. /* else if ( test_press( FL_CTRL + FL_BUTTON1 ) ) */
  151. /* { */
  152. /* /\* duplication *\/ */
  153. /* fl_cursor( FL_CURSOR_MOVE ); */
  154. /* return 1; */
  155. /* } */
  156. else
  157. return Sequence_Widget::handle( m );
  158. }
  159. case FL_RELEASE:
  160. {
  161. Sequence_Widget::handle( m );
  162. copied = false;
  163. if ( trimming != NO )
  164. trimming = NO;
  165. return 1;
  166. }
  167. case FL_DRAG:
  168. {
  169. if ( ! _drag )
  170. {
  171. begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  172. _log.hold();
  173. }
  174. /* trimming */
  175. if ( Fl::event_shift() )
  176. {
  177. if ( trimming )
  178. {
  179. trim( trimming, X );
  180. return 1;
  181. }
  182. else
  183. return 0;
  184. }
  185. return Sequence_Widget::handle( m );
  186. }
  187. default:
  188. return Sequence_Widget::handle( m );
  189. break;
  190. }
  191. return 0;
  192. }
  193. void
  194. Sequence_Region::draw_box ( void )
  195. {
  196. fl_draw_box( box(), line_x(), y(), abs_w(), h(), box_color() );
  197. }
  198. void
  199. Sequence_Region::draw ( void )
  200. {
  201. }