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.

229 lines
5.8KB

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