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.

294 lines
7.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. /* TODO:
  19. What if we solve the continuous-modification/sync issue by making a
  20. copy of the 'pushed' widget, and operating on that instead (hiding
  21. the original), then when the widget is released, copy its data into
  22. the original?
  23. */
  24. #include "Sequence_Widget.H"
  25. list <Sequence_Widget *> Sequence_Widget::_selection;
  26. Sequence_Widget * Sequence_Widget::_current = NULL;
  27. Sequence_Widget * Sequence_Widget::_pushed = NULL;
  28. Sequence_Widget * Sequence_Widget::_belowmouse = NULL;
  29. Fl_Color Sequence_Widget::_selection_color = FL_MAGENTA;
  30. void
  31. Sequence_Widget::get ( Log_Entry &e ) const
  32. {
  33. e.add( ":start", _r->start );
  34. // e.add( ":offset", _r->offset );
  35. // e.add( ":length", _r->length );
  36. e.add( ":sequence", _sequence );
  37. e.add( ":selected", selected() );
  38. }
  39. void
  40. Sequence_Widget::set ( Log_Entry &e )
  41. {
  42. for ( int i = 0; i < e.size(); ++i )
  43. {
  44. const char *s, *v;
  45. e.get( i, &s, &v );
  46. if ( ! strcmp( s, ":start" ) )
  47. _r->start = atoll( v );
  48. // else if ( ! strcmp( s, ":offset" ) )
  49. // _r->offset = atoll( v );
  50. // else if ( ! strcmp( s, ":length" ) )
  51. // _r->length = atoll( v );
  52. else if ( ! strcmp( s, ":selected" ) )
  53. {
  54. if ( atoi( v ) )
  55. select();
  56. else
  57. deselect();
  58. }
  59. else if ( ! strcmp( s, ":sequence" ) )
  60. {
  61. int i;
  62. sscanf( v, "%X", &i );
  63. Sequence *t = (Sequence*)Loggable::find( i );
  64. assert( t );
  65. t->add( this );
  66. }
  67. // else
  68. // e.erase( i );
  69. }
  70. if ( _sequence )
  71. _sequence->redraw();
  72. }
  73. void
  74. Sequence_Widget::draw_label ( const char *label, Fl_Align align, Fl_Color color )
  75. {
  76. int X, Y;
  77. X = x();
  78. Y = y();
  79. /* FIXME: why do we have to to this here? why doesn't Fl_Lable::draw take care of this stuff? */
  80. if ( ! (align & FL_ALIGN_INSIDE) )
  81. {
  82. if ( align & FL_ALIGN_RIGHT )
  83. {
  84. X += abs_w();
  85. align = (Fl_Align)((align & ~FL_ALIGN_RIGHT) | FL_ALIGN_LEFT);
  86. }
  87. if ( align & FL_ALIGN_BOTTOM )
  88. {
  89. Y += h();
  90. align = (Fl_Align)((align & ~FL_ALIGN_BOTTOM) | FL_ALIGN_TOP);
  91. }
  92. }
  93. Fl_Label lab;
  94. lab.color = color;
  95. // lab.type = FL_SHADOW_LABEL;
  96. lab.type = FL_NORMAL_LABEL;
  97. lab.value = label;
  98. lab.font = FL_HELVETICA;
  99. lab.size = 14;
  100. int lw = 0, lh = 0;
  101. fl_font( lab.font, lab.size );
  102. fl_measure( lab.value, lw, lh );
  103. int W = w();
  104. int H = h();
  105. if ( align & FL_ALIGN_INSIDE )
  106. {
  107. X += Fl::box_dx( box() );
  108. Y += Fl::box_dy( box() );
  109. W -= Fl::box_dw( box() );
  110. H -= Fl::box_dh( box() );
  111. }
  112. if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );
  113. int dx = 0;
  114. /* adjust for scrolling */
  115. if ( abs_x() < scroll_x() )
  116. dx = min( 32767, scroll_x() - abs_x() );
  117. // const Fl_Boxtype b = FL_ROUND_UP_BOX;
  118. const Fl_Boxtype b = FL_ROUNDED_BOX;
  119. const int bx = Fl::box_dx( b ) + 1;
  120. const int bw = Fl::box_dw( b ) + 1;
  121. if ( align & FL_ALIGN_BOTTOM )
  122. fl_draw_box( b, X - dx - bx, Y + H - lh, lw + bw, lh, FL_GRAY );
  123. else if ( align == FL_ALIGN_LEFT )
  124. fl_draw_box( b, X - dx, Y + ((H >> 1) - (lh >> 1)), lw + bw, lh, FL_GRAY );
  125. else if ( align & FL_ALIGN_TOP )
  126. fl_draw_box( b, X - dx - bx + ((W >> 1) - (lw >> 1)), Y + ((H >> 1) - (lh >> 1)), lw + bw, lh, FL_GRAY );
  127. // lab.draw( X - dx, Y, W, H, align );
  128. fl_color( color );
  129. fl_draw( label, ( X - dx ) + bx, Y, W, H, align );
  130. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  131. }
  132. int
  133. Sequence_Widget::dispatch ( int m )
  134. {
  135. Sequence_Widget::_current = this;
  136. if ( selected() )
  137. {
  138. Loggable::block_start();
  139. int r = 0;
  140. for ( list <Sequence_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
  141. if ( *i != this )
  142. r |= (*i)->handle( m );
  143. r |= handle( m );
  144. Loggable::block_end();
  145. return r;
  146. }
  147. else
  148. return handle( m );
  149. }
  150. /* base hanlde just does basic dragging */
  151. int
  152. Sequence_Widget::handle ( int m )
  153. {
  154. int X = Fl::event_x();
  155. int Y = Fl::event_y();
  156. Logger _log( this );
  157. switch ( m )
  158. {
  159. case FL_ENTER:
  160. fl_cursor( FL_CURSOR_HAND );
  161. return 1;
  162. case FL_LEAVE:
  163. fl_cursor( sequence()->cursor() );
  164. return 1;
  165. case FL_PUSH:
  166. {
  167. /* deletion */
  168. if ( Fl::event_state() & FL_CTRL &&
  169. Fl::event_button3() )
  170. {
  171. redraw();
  172. sequence()->queue_delete( this );
  173. return 1;
  174. }
  175. else
  176. if ( Fl::event_button1() )
  177. return 1;
  178. return 0;
  179. }
  180. case FL_RELEASE:
  181. if ( _drag )
  182. {
  183. end_drag();
  184. _log.release();
  185. }
  186. fl_cursor( FL_CURSOR_HAND );
  187. return 1;
  188. case FL_DRAG:
  189. {
  190. if ( ! _drag )
  191. {
  192. begin_drag ( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  193. _log.hold();
  194. }
  195. fl_cursor( FL_CURSOR_MOVE );
  196. redraw();
  197. {
  198. const nframes_t of = timeline->x_to_offset( X );
  199. if ( of >= _drag->start )
  200. {
  201. _r->start = of - _drag->start;
  202. if ( Sequence_Widget::_current == this )
  203. sequence()->snap( this );
  204. }
  205. else
  206. _r->start = 0;
  207. }
  208. if ( X >= sequence()->x() + sequence()->w() ||
  209. X <= sequence()->x() )
  210. {
  211. /* this drag needs to scroll */
  212. nframes_t pos = timeline->xoffset;
  213. nframes_t d = timeline->x_to_ts( 100 );
  214. if ( X <= sequence()->x() )
  215. {
  216. if ( pos > d )
  217. pos -= d;
  218. else
  219. pos = 0;
  220. }
  221. else
  222. pos += d;
  223. timeline->xposition( timeline->ts_to_x( pos ) );
  224. /* FIXME: why isn't this enough? */
  225. // sequence()->redraw();
  226. timeline->redraw();
  227. }
  228. return 1;
  229. }
  230. default:
  231. return 0;
  232. }
  233. }