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.

266 lines
6.6KB

  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. #include <stdint.h>
  21. Sequence_Region::Sequence_Region ( )
  22. {
  23. color( FL_CYAN );
  24. }
  25. Sequence_Region::Sequence_Region ( const Sequence_Region &rhs ) : Sequence_Widget( rhs )
  26. {
  27. }
  28. Sequence_Region::~Sequence_Region ( )
  29. {
  30. }
  31. void
  32. Sequence_Region::get ( Log_Entry &e ) const
  33. {
  34. e.add( ":color", _box_color );
  35. e.add( ":length", _r->length );
  36. Sequence_Widget::get( e );
  37. }
  38. void
  39. Sequence_Region::set ( Log_Entry &e )
  40. {
  41. for ( int i = 0; i < e.size(); ++i )
  42. {
  43. const char *s, *v;
  44. e.get( i, &s, &v );
  45. if ( ! strcmp( s, ":color" ) )
  46. _box_color = (Fl_Color)atoll( v );
  47. else if ( ! strcmp( s, ":length" ) )
  48. _r->length = atoll( v );
  49. }
  50. Sequence_Widget::set( e );
  51. }
  52. void
  53. Sequence_Region::trim_left ( nframes_t where )
  54. {
  55. int64_t td = (int64_t)where - _r->start;
  56. /* beyond the beginning */
  57. if ( td < 0 && _r->offset < (nframes_t)( 0 - td ) )
  58. td = (int64_t)0 - _r->offset;
  59. if ( td > 0 && (nframes_t)td >= _r->length )
  60. td = (int64_t)_r->length - timeline->x_to_ts( 1 );
  61. _r->trim_left( 0 - td );
  62. nframes_t f = _r->start;
  63. /* snap to beat/bar lines */
  64. if ( timeline->nearest_line( &f ) )
  65. _r->set_left( f );
  66. }
  67. void
  68. Sequence_Region::trim_right ( nframes_t where )
  69. {
  70. int64_t td = (int64_t)( _r->start + _r->length ) - where;
  71. if ( td >= 0 && _r->length < (nframes_t)td )
  72. td = _r->length - timeline->x_to_ts( 1 );
  73. _r->trim_right( 0 - td );
  74. nframes_t f = _r->start + _r->length;
  75. /* snap to beat/bar lines */
  76. if ( timeline->nearest_line( &f ) )
  77. _r->set_right( f );
  78. }
  79. void
  80. Sequence_Region::trim ( enum trim_e t, int X )
  81. {
  82. redraw();
  83. nframes_t where = timeline->x_to_offset( X );
  84. switch ( t )
  85. {
  86. case LEFT:
  87. trim_left( where );
  88. break;
  89. case RIGHT:
  90. trim_right( where );
  91. break;
  92. default:
  93. break;
  94. }
  95. }
  96. /** split region at absolute frame /where/. due to inheritance issues,
  97. * the copy must be made in the derived classed and passed in */
  98. void
  99. Sequence_Region::split ( Sequence_Region * copy, nframes_t where )
  100. {
  101. trim_right( where );
  102. copy->trim_left( where );
  103. sequence()->add( copy );
  104. }
  105. #include "FL/test_press.H"
  106. int
  107. Sequence_Region::handle ( int m )
  108. {
  109. static enum trim_e trimming;
  110. int X = Fl::event_x();
  111. int Y = Fl::event_y();
  112. Logger _log( this );
  113. switch ( m )
  114. {
  115. case FL_PUSH:
  116. {
  117. /* trimming */
  118. if ( Fl::event_shift() && ! Fl::event_ctrl() )
  119. {
  120. switch ( Fl::event_button() )
  121. {
  122. case 1:
  123. trim( trimming = LEFT, X );
  124. begin_drag( Drag( x() - X, y() - Y ) );
  125. _log.hold();
  126. break;
  127. case 3:
  128. trim( trimming = RIGHT, X );
  129. begin_drag( Drag( x() - X, y() - Y ) );
  130. _log.hold();
  131. break;
  132. default:
  133. return 0;
  134. break;
  135. }
  136. fl_cursor( FL_CURSOR_WE );
  137. return 1;
  138. }
  139. else if ( test_press( FL_BUTTON2 ) )
  140. {
  141. if ( Sequence_Widget::current() == this )
  142. {
  143. if ( selected() )
  144. deselect();
  145. else
  146. select();
  147. }
  148. redraw();
  149. return 1;
  150. }
  151. /* else if ( test_press( FL_CTRL + FL_BUTTON1 ) ) */
  152. /* { */
  153. /* /\* duplication *\/ */
  154. /* fl_cursor( FL_CURSOR_MOVE ); */
  155. /* return 1; */
  156. /* } */
  157. else
  158. return Sequence_Widget::handle( m );
  159. }
  160. case FL_RELEASE:
  161. {
  162. Sequence_Widget::handle( m );
  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_Color c = selected() ? selection_color() : box_color();
  197. fl_draw_box( box(), line_x(), y(), abs_w(), h(), fl_color_add_alpha( c, 127 ) );
  198. }
  199. void
  200. Sequence_Region::draw ( void )
  201. {
  202. }
  203. void
  204. Sequence_Region::draw_label ( const char *label, Fl_Align align, Fl_Color color, int xo, int yo )
  205. {
  206. fl_color( FL_WHITE );
  207. fl_font( FL_HELVETICA_ITALIC, 10 );
  208. fl_draw( label, line_x() + Fl::box_dx( box() ), y() + Fl::box_dy( box() ), abs_w() - Fl::box_dw( box() ), h() - Fl::box_dh( box() ), align );
  209. }