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.

240 lines
6.0KB

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