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.

213 lines
5.7KB

  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. _track = rhs._track;
  43. }
  44. void
  45. Region::trim ( enum trim_e t, int X )
  46. {
  47. switch ( t )
  48. {
  49. case LEFT:
  50. {
  51. int d = X - x();
  52. _start += d;
  53. resize( x() + d, y(), w() - d, h() );
  54. break;
  55. }
  56. case RIGHT:
  57. {
  58. int d = (x() + w()) - X;
  59. _end -= d;
  60. resize( x(), y(), w() - d, h() );
  61. break;
  62. }
  63. default:
  64. return;
  65. }
  66. redraw();
  67. parent()->redraw();
  68. }
  69. int
  70. Region::handle ( int m )
  71. {
  72. if ( Fl_Widget::handle( m ) )
  73. return 1;
  74. static int ox, oy;
  75. static enum trim_e trimming;
  76. static bool copied = false;
  77. switch ( m )
  78. {
  79. case FL_PUSH:
  80. {
  81. int X = Fl::event_x();
  82. int Y = Fl::event_y();
  83. if ( Fl::event_state() & FL_SHIFT )
  84. {
  85. switch ( Fl::event_button() )
  86. {
  87. case 1:
  88. trim( trimming = LEFT, X );
  89. break;
  90. case 3:
  91. trim( trimming = RIGHT, X );
  92. break;
  93. default:
  94. return 0;
  95. }
  96. fl_cursor( FL_CURSOR_WE );
  97. return 1;
  98. }
  99. else
  100. {
  101. ox = x() - Fl::event_x();
  102. oy = y() - Fl::event_y();
  103. if ( Fl::event_button() == 2 )
  104. {
  105. // _track->add( new Region( *this ) );
  106. }
  107. return 1;
  108. }
  109. return 0;
  110. break;
  111. }
  112. case FL_RELEASE:
  113. fl_cursor( FL_CURSOR_DEFAULT );
  114. copied = false;
  115. trimming = NO;
  116. return 1;
  117. case FL_DRAG:
  118. if ( Fl::event_state() & FL_SHIFT )
  119. if ( trimming )
  120. {
  121. trim( trimming, Fl::event_x() );
  122. return 1;
  123. }
  124. else
  125. return 0;
  126. if ( Fl::event_state() & FL_CTRL )
  127. {
  128. if ( ! copied )
  129. {
  130. _track->add( new Region( *this ) );
  131. copied = true;
  132. return 1;
  133. }
  134. }
  135. if ( ox + Fl::event_x() >= _track->x() )
  136. position( ox + Fl::event_x(), y() );
  137. if ( Fl::event_y() > y() + h() )
  138. {
  139. if ( _track->next() )
  140. _track->next()->add( this );
  141. }
  142. else
  143. if ( Fl::event_y() < y() )
  144. {
  145. if ( _track->prev() )
  146. _track->prev()->add( this );
  147. }
  148. // if ( Fl::event_y() - oy >= h() )
  149. parent()->redraw();
  150. fl_cursor( FL_CURSOR_MOVE );
  151. if ( Fl::event_x() >= timeline.scroll->x() + timeline.scroll->w() ||
  152. Fl::event_x() <= timeline.scroll->x() )
  153. {
  154. int d;
  155. if ( Fl::event_x() <= timeline.scroll->x() )
  156. d = -100;
  157. else
  158. d = 100;
  159. /* this drag needs to scroll */
  160. timeline.scroll->position( timeline.scroll->xposition() + d, 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. draw_label();
  176. }