Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
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.

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