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.

267 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 "Track.H"
  19. #include "Region.H"
  20. #include "Timeline.H"
  21. #include <FL/fl_draw.H>
  22. #include <FL/Fl.H>
  23. #include <FL/Fl_Group.H>
  24. #include <FL/Fl_Widget.H>
  25. #include <stdio.h>
  26. extern Timeline timeline;
  27. Region::Region ( int X, int Y, int W, int H, const char *L ) : Waveform( X, Y, W, H, L )
  28. {
  29. init();
  30. }
  31. void
  32. Region::init ( void )
  33. {
  34. align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP );
  35. labeltype( FL_SHADOW_LABEL );
  36. labelcolor( FL_WHITE );
  37. box( FL_PLASTIC_UP_BOX );
  38. _track = NULL;
  39. // _offset = 0;
  40. _offset = timeline.x_to_ts( x() );
  41. }
  42. Region::Region ( const Region & rhs ) : Waveform( rhs )
  43. {
  44. box( rhs.box() );
  45. align( rhs.align() );
  46. color( rhs.color() );
  47. selection_color( rhs.selection_color() );
  48. labelcolor( rhs.labelcolor() );
  49. labeltype( rhs.labeltype() );
  50. _offset = rhs._offset;
  51. _track = rhs._track;
  52. }
  53. Region::Region ( Clip *c ) : Waveform( c )
  54. {
  55. init();
  56. }
  57. void
  58. Region::trim ( enum trim_e t, int X )
  59. {
  60. switch ( t )
  61. {
  62. case LEFT:
  63. {
  64. int d = X - x();
  65. _start += timeline.x_to_ts( d );
  66. Fl_Widget::resize( x() + d, y(), w() - d, h() );
  67. _offset = timeline.x_to_ts( x() );
  68. break;
  69. }
  70. case RIGHT:
  71. {
  72. int d = (x() + w()) - X;
  73. _end = _start + timeline.x_to_ts( w() - d );
  74. Fl_Widget::resize( x(), y(), w() - d, h() );
  75. break;
  76. }
  77. default:
  78. return;
  79. }
  80. redraw();
  81. parent()->redraw();
  82. }
  83. int
  84. Region::handle ( int m )
  85. {
  86. if ( Fl_Widget::handle( m ) )
  87. return 1;
  88. static int ox, oy;
  89. static enum trim_e trimming;
  90. static bool copied = false;
  91. int X = Fl::event_x();
  92. int Y = Fl::event_y();
  93. switch ( m )
  94. {
  95. case FL_PUSH:
  96. {
  97. if ( Fl::event_state() & FL_SHIFT )
  98. {
  99. switch ( Fl::event_button() )
  100. {
  101. case 1:
  102. trim( trimming = LEFT, X );
  103. break;
  104. case 3:
  105. trim( trimming = RIGHT, X );
  106. break;
  107. default:
  108. return 0;
  109. }
  110. fl_cursor( FL_CURSOR_WE );
  111. return 1;
  112. }
  113. else
  114. {
  115. ox = x() - X;
  116. oy = y() - Y;
  117. if ( Fl::event_button() == 2 )
  118. normalize();
  119. return 1;
  120. }
  121. return 0;
  122. break;
  123. }
  124. case FL_RELEASE:
  125. fl_cursor( FL_CURSOR_DEFAULT );
  126. copied = false;
  127. trimming = NO;
  128. return 1;
  129. case FL_DRAG:
  130. if ( Fl::event_state() & FL_SHIFT )
  131. if ( trimming )
  132. {
  133. trim( trimming, X );
  134. return 1;
  135. }
  136. else
  137. return 0;
  138. if ( Fl::event_state() & FL_CTRL )
  139. {
  140. if ( ! copied )
  141. {
  142. _track->add( new Region( *this ) );
  143. copied = true;
  144. return 1;
  145. }
  146. }
  147. if ( ox + X >= _track->x() )
  148. position( ox + X, y() );
  149. if ( Y > y() + h() )
  150. {
  151. if ( _track->next() )
  152. _track->next()->add( this );
  153. }
  154. else
  155. if ( Y < y() )
  156. {
  157. if ( _track->prev() )
  158. _track->prev()->add( this );
  159. }
  160. parent()->redraw();
  161. fl_cursor( FL_CURSOR_MOVE );
  162. if ( X >= timeline.scroll->x() + timeline.scroll->w() ||
  163. X <= timeline.scroll->x() )
  164. {
  165. /* this drag needs to scroll */
  166. long pos = timeline.scroll->xposition();
  167. if ( X <= timeline.scroll->x() )
  168. pos -= 100;
  169. else
  170. pos += 100;
  171. if ( pos < 0 )
  172. pos = 0;
  173. timeline.scroll->position( pos, timeline.scroll->yposition() );
  174. }
  175. _offset = timeline.x_to_ts( x() );
  176. return 1;
  177. default:
  178. return 0;
  179. break;
  180. }
  181. }
  182. /** must be called whenever zoom is adjusted */
  183. void
  184. Region::resize ( void )
  185. {
  186. int X = timeline.ts_to_x( _offset );
  187. int W = timeline.ts_to_x( _end - _start );
  188. if ( W )
  189. Fl_Widget::resize( X, y(), W, h() );
  190. }
  191. void
  192. Region::draw ( void )
  193. {
  194. draw_box();
  195. // fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
  196. Waveform::draw();
  197. // fl_pop_clip();
  198. /* fl_color( FL_RED ); */
  199. /* int sx = x() - timeline.ts_to_x( _start ); */
  200. /* fl_line( sx, y(), sx, y() + h() ); */
  201. /* int ex = x() + timeline.ts_to_x( _end - _start ); */
  202. /* fl_line( ex, y(), ex, y() + h() ); */
  203. draw_label();
  204. /* static char pat[200]; */
  205. /* sprintf( pat, "start %lu, end %lu", _start, _end ); */
  206. /* fl_draw( pat, x(), y() + h() / 2 ); */
  207. }