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.

333 lines
9.1KB

  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 "Waveform.H"
  22. #include <FL/fl_draw.H>
  23. #include <FL/Fl.H>
  24. #include <FL/Fl_Group.H>
  25. #include <FL/Fl_Widget.H>
  26. #include <FL/Fl_Box.H>
  27. #include <stdio.h>
  28. #include <algorithm>
  29. //using std::algorithm;
  30. using namespace std;
  31. extern Timeline timeline;
  32. void
  33. Region::init ( void )
  34. {
  35. /* align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP ); */
  36. /* labeltype( FL_SHADOW_LABEL ); */
  37. /* labelcolor( FL_WHITE ); */
  38. /* box( FL_PLASTIC_UP_BOX ); */
  39. _track = NULL;
  40. _offset = 0;
  41. _start = 0;
  42. _end = 0;
  43. _scale = 1.0f;
  44. _clip = NULL;
  45. }
  46. Region::Region ( const Region & rhs )
  47. {
  48. _offset = rhs._offset;
  49. _track = rhs._track;
  50. _clip = rhs._clip;
  51. _start = rhs._start;
  52. _end = rhs._end;
  53. _scale = rhs._scale;
  54. }
  55. Region::Region ( Clip *c )
  56. {
  57. init();
  58. _clip = c;
  59. _end = _clip->length();
  60. }
  61. /* void */
  62. /* Region::trim ( enum trim_e t, int X ) */
  63. /* { */
  64. /* switch ( t ) */
  65. /* { */
  66. /* case LEFT: */
  67. /* { */
  68. /* int d = X - x(); */
  69. /* long td = timeline.x_to_ts( d ); */
  70. /* if ( td < 0 && _start < 0 - td ) */
  71. /* td = 0 - _start; */
  72. /* _start += td; */
  73. /* _offset += td; */
  74. /* resize(); */
  75. /* // Fl_Widget::resize( x() + d, y(), w() - d, h() ); */
  76. /* // _offset = timeline.x_to_ts( x() ); */
  77. /* break; */
  78. /* } */
  79. /* case RIGHT: */
  80. /* { */
  81. /* int d = (x() + w()) - X; */
  82. /* long td = timeline.x_to_ts( d ); */
  83. /* _end -= td; */
  84. /* resize(); */
  85. /* // _end = _start + timeline.x_to_ts( w() - d ); */
  86. /* // Fl_Widget::resize( x(), y(), w() - d, h() ); */
  87. /* break; */
  88. /* } */
  89. /* default: */
  90. /* return; */
  91. /* } */
  92. /* redraw(); */
  93. /* parent()->redraw(); */
  94. /* } */
  95. int
  96. Region::handle ( int m ) { return 0; }
  97. /* { */
  98. /* /\* if ( Fl_Widget::handle( m ) ) *\/ */
  99. /* /\* return 1; *\/ */
  100. /* static int ox, oy; */
  101. /* static enum trim_e trimming; */
  102. /* static bool copied = false; */
  103. /* static nframes_t os; */
  104. /* int X = Fl::event_x(); */
  105. /* int Y = Fl::event_y(); */
  106. /* switch ( m ) */
  107. /* { */
  108. /* case FL_PUSH: */
  109. /* { */
  110. /* if ( Fl::event_state() & FL_SHIFT && */
  111. /* ! ( Fl::event_state() & FL_CTRL )) */
  112. /* { */
  113. /* switch ( Fl::event_button() ) */
  114. /* { */
  115. /* case 1: */
  116. /* trim( trimming = LEFT, X ); */
  117. /* break; */
  118. /* case 3: */
  119. /* trim( trimming = RIGHT, X ); */
  120. /* break; */
  121. /* default: */
  122. /* return 0; */
  123. /* } */
  124. /* fl_cursor( FL_CURSOR_WE ); */
  125. /* return 1; */
  126. /* } */
  127. /* else */
  128. /* { */
  129. /* ox = x() - X; */
  130. /* oy = y() - Y; */
  131. /* if ( Fl::event_state() && FL_CTRL ) */
  132. /* { */
  133. /* os = _start; */
  134. /* // Fl::local_grab( this ); */
  135. /* } */
  136. /* if ( Fl::event_button() == 2 ) */
  137. /* normalize(); */
  138. /* return 1; */
  139. /* } */
  140. /* return 0; */
  141. /* break; */
  142. /* } */
  143. /* case FL_RELEASE: */
  144. /* fl_cursor( FL_CURSOR_DEFAULT ); */
  145. /* copied = false; */
  146. /* trimming = NO; */
  147. /* // Fl::release(); */
  148. /* return 1; */
  149. /* case FL_DRAG: */
  150. /* if ( Fl::event_state() & FL_SHIFT && */
  151. /* Fl::event_state() & FL_CTRL ) */
  152. /* { */
  153. /* int d = (ox + X) - x(); */
  154. /* long td = timeline.x_to_ts( d ); */
  155. /* if ( td > 0 && os < td ) */
  156. /* _start = 0; */
  157. /* else */
  158. /* _start = os - td; */
  159. /* redraw(); */
  160. /* return 1; */
  161. /* } */
  162. /* if ( Fl::event_state() & FL_SHIFT ) */
  163. /* if ( trimming ) */
  164. /* { */
  165. /* trim( trimming, X ); */
  166. /* return 1; */
  167. /* } */
  168. /* else */
  169. /* return 0; */
  170. /* if ( Fl::event_state() & FL_CTRL ) */
  171. /* { */
  172. /* if ( ! copied ) */
  173. /* { */
  174. /* _track->add( new Region( *this ) ); */
  175. /* copied = true; */
  176. /* return 1; */
  177. /* } */
  178. /* } */
  179. /* if ( ox + X >= _track->x() ) */
  180. /* { */
  181. /* int nx = ox + X; */
  182. /* // nx = _track->snap( this, nx ); */
  183. /* // _offset = timeline.x_to_ts( nx ); */
  184. /* position( nx, y() ); */
  185. /* _track->snap( this ); */
  186. /* } */
  187. /* if ( Y > y() + h() ) */
  188. /* { */
  189. /* if ( _track->next() ) */
  190. /* _track->next()->add( this ); */
  191. /* } */
  192. /* else */
  193. /* if ( Y < y() ) */
  194. /* { */
  195. /* if ( _track->prev() ) */
  196. /* _track->prev()->add( this ); */
  197. /* } */
  198. /* parent()->redraw(); */
  199. /* fl_cursor( FL_CURSOR_MOVE ); */
  200. /* if ( X >= timeline.scroll->x() + timeline.scroll->w() || */
  201. /* X <= timeline.scroll->x() ) */
  202. /* { */
  203. /* /\* this drag needs to scroll *\/ */
  204. /* long pos = timeline.scroll->xposition(); */
  205. /* if ( X <= timeline.scroll->x() ) */
  206. /* pos -= 100; */
  207. /* else */
  208. /* pos += 100; */
  209. /* if ( pos < 0 ) */
  210. /* pos = 0; */
  211. /* timeline.scroll->position( pos, timeline.scroll->yposition() ); */
  212. /* } */
  213. /* // _offset = timeline.x_to_ts( x() ); */
  214. /* return 1; */
  215. /* default: */
  216. /* return 0; */
  217. /* break; */
  218. /* } */
  219. /* } */
  220. /** must be called whenever zoom is adjusted */
  221. void
  222. Region::resize ( void )
  223. {
  224. int X = timeline.ts_to_x( _offset );
  225. assert( _end >= _start );
  226. int W = timeline.ts_to_x( _end - _start );
  227. printf( "%dx%d\n", X, W );
  228. // if ( W )
  229. // Fl_Widget::resize( X, y(), W, h() );
  230. }
  231. /* X is the timeline offset, W is the width of the track */
  232. void
  233. Region::draw ( int X, int Y, int W, int H )
  234. {
  235. int rx = timeline.ts_to_x( _offset ) - X;
  236. int rw = min( timeline.ts_to_x( _end - _start ), W );
  237. fl_draw_box( FL_PLASTIC_UP_BOX, rx, Y, rw, H, FL_CYAN );
  238. // fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
  239. draw_waveform( rx, Y, rw, H, _clip, _start, _end, _scale, FL_GREEN );
  240. // fl_pop_clip();
  241. fl_font( FL_HELVETICA, 14 );
  242. fl_color( FL_BLACK );
  243. int bx = Fl::box_dx( FL_PLASTIC_UP_BOX );
  244. int by = Fl::box_dy( FL_PLASTIC_UP_BOX );
  245. int bw = Fl::box_dw( FL_PLASTIC_UP_BOX );
  246. int bh = Fl::box_dh( FL_PLASTIC_UP_BOX );
  247. Fl_Align align = (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP);
  248. fl_draw( _clip->name(), bx + rx + 1, Y + 1 + by, rw - bw, H - bh, align );
  249. fl_color( FL_WHITE );
  250. fl_draw( _clip->name(), bx + rx, Y + by , rw - bw, H - bh, align );
  251. // fl_draw( _clip->name(), X, Y );
  252. //(Fl_Align)FL_ALIGN_LEFT | FL_ALIGN_BOTTOM );
  253. }