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.

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