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.

346 lines
8.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 <FL/fl_ask.H>
  19. #include "Control_Sequence.H"
  20. #include "Track.H"
  21. #include "Engine/Engine.H" // for lock()
  22. #include <list>
  23. using std::list;
  24. bool Control_Sequence::draw_with_gradient = true;
  25. bool Control_Sequence::draw_with_polygon = true;
  26. bool Control_Sequence::draw_with_grid = true;
  27. Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0 )
  28. {
  29. init();
  30. _track = track;
  31. _output = new JACK::Port( engine->client(), JACK::Port::Output, track->name(), track->ncontrols(), "cv" );
  32. if ( track )
  33. track->add( this );
  34. log_create();
  35. }
  36. Control_Sequence::~Control_Sequence ( )
  37. {
  38. Loggable::block_start();
  39. clear();
  40. log_destroy();
  41. engine->lock();
  42. track()->remove( this );
  43. engine->unlock();
  44. _output->shutdown();
  45. delete _output;
  46. _output = NULL;
  47. Loggable::block_end();
  48. }
  49. void
  50. Control_Sequence::init ( void )
  51. {
  52. _track = NULL;
  53. _highlighted = false;
  54. _output = NULL;
  55. color( fl_darker( FL_YELLOW ) );
  56. }
  57. void
  58. Control_Sequence::get ( Log_Entry &e ) const
  59. {
  60. e.add( ":track", _track );
  61. e.add( ":name", name() );
  62. }
  63. void
  64. Control_Sequence::set ( Log_Entry &e )
  65. {
  66. for ( int i = 0; i < e.size(); ++i )
  67. {
  68. const char *s, *v;
  69. e.get( i, &s, &v );
  70. if ( ! strcmp( ":track", s ) )
  71. {
  72. int i;
  73. sscanf( v, "%X", &i );
  74. Track *t = (Track*)Loggable::find( i );
  75. assert( t );
  76. _output = new JACK::Port( engine->client(), JACK::Port::Output, t->name(), t->ncontrols(), "cv" );
  77. t->add( this );
  78. }
  79. else if ( ! strcmp( ":name", s ) )
  80. name( v );
  81. }
  82. }
  83. void
  84. Control_Sequence::draw_curve ( bool flip, bool filled )
  85. {
  86. const int bx = x();
  87. const int by = y() + Fl::box_dy( box() );
  88. const int bw = w();
  89. const int bh = h() - Fl::box_dh( box() );
  90. list <Sequence_Widget *>::const_iterator e = _widgets.end();
  91. e--;
  92. if ( _widgets.size() )
  93. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); ; r++ )
  94. {
  95. const int ry = (*r)->y();
  96. if ( r == _widgets.begin() )
  97. {
  98. if ( flip )
  99. {
  100. if ( filled )
  101. fl_vertex( bx, by );
  102. fl_vertex( bx, ry );
  103. }
  104. else
  105. {
  106. if ( filled )
  107. fl_vertex( bx, bh + by );
  108. fl_vertex( bx, ry );
  109. }
  110. }
  111. fl_vertex( (*r)->line_x(), ry );
  112. if ( r == e )
  113. {
  114. if ( flip )
  115. {
  116. fl_vertex( bx + bw, ry );
  117. if ( filled )
  118. fl_vertex( bx + bw, by );
  119. }
  120. else
  121. {
  122. fl_vertex( bx + bw, ry );
  123. if ( filled )
  124. fl_vertex( bx + bw, bh + by );
  125. }
  126. break;
  127. }
  128. }
  129. }
  130. void
  131. Control_Sequence::draw ( void )
  132. {
  133. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  134. return;
  135. fl_push_clip( x(), y(), w(), h() );
  136. /* draw the box with the ends cut off. */
  137. draw_box( box(), x() - Fl::box_dx( box() ), y(), w() + Fl::box_dw( box() ) + 1, h(), color() );
  138. const int bx = x();
  139. const int by = y() + Fl::box_dy( box() );
  140. const int bw = w();
  141. const int bh = h() - Fl::box_dh( box() );
  142. int X, Y, W, H;
  143. fl_clip_box( bx, by, bw, bh, X, Y, W, H );
  144. bool active = active_r();
  145. const Fl_Color color = active ? this->color() : fl_inactive( this->color() );
  146. const Fl_Color selection_color = active ? this->selection_color() : fl_inactive( this->selection_color() );
  147. if ( draw_with_gradient )
  148. {
  149. /* const Fl_Color c2 = fl_color_average( selection_color, FL_WHITE, 0.90f ); */
  150. /* const Fl_Color c1 = fl_color_average( color, c2, 0.60f ); */
  151. const Fl_Color c1 = fl_color_average( selection_color, FL_WHITE, 0.90f );
  152. const Fl_Color c2 = fl_color_average( color, c1, 0.60f );
  153. for ( int gy = 0; gy < bh; gy++ )
  154. {
  155. fl_color( fl_color_average( c1, c2, gy / (float)bh) );
  156. fl_line( X, by + gy, X + W, by + gy );
  157. }
  158. }
  159. if ( draw_with_grid )
  160. {
  161. fl_color( fl_darker( color ) );
  162. const int inc = bh / 10;
  163. if ( inc )
  164. for ( int gy = 0; gy < bh; gy += inc )
  165. fl_line( X, by + gy, X + W, by + gy );
  166. }
  167. if ( draw_with_polygon )
  168. {
  169. fl_color( draw_with_gradient ? color : fl_color_average( color, selection_color, 0.45f ) );
  170. fl_begin_complex_polygon();
  171. draw_curve( draw_with_gradient, true );
  172. fl_end_complex_polygon();
  173. fl_color( selection_color );
  174. fl_line_style( FL_SOLID, 2 );
  175. fl_begin_line();
  176. draw_curve( draw_with_gradient, false );
  177. fl_end_line();
  178. }
  179. else
  180. {
  181. // fl_color( fl_color_average( selection_color, color, 0.70f ) );
  182. fl_color( selection_color );
  183. fl_line_style( FL_SOLID, 2 );
  184. fl_begin_line();
  185. draw_curve( draw_with_gradient, false );
  186. fl_end_line();
  187. }
  188. fl_line_style( FL_SOLID, 0 );
  189. timeline->draw_measure_lines( x(), y(), w(), h(), color );
  190. if ( _highlighted || Fl::focus() == this )
  191. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  192. (*r)->draw_box();
  193. else
  194. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  195. if ( (*r)->selected() )
  196. (*r)->draw_box();
  197. fl_pop_clip();
  198. }
  199. int
  200. Control_Sequence::handle ( int m )
  201. {
  202. switch ( m )
  203. {
  204. case FL_ENTER:
  205. _highlighted = true;
  206. fl_cursor( cursor() );
  207. redraw();
  208. return 1;
  209. case FL_LEAVE:
  210. _highlighted = false;
  211. redraw();
  212. return 1;
  213. default:
  214. break;
  215. }
  216. int r = Sequence::handle( m );
  217. if ( r )
  218. return r;
  219. switch ( m )
  220. {
  221. case FL_PUSH:
  222. {
  223. Logger log( this );
  224. if ( Fl::event_button1() )
  225. {
  226. Control_Point *r = new Control_Point( this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ), (float)(Fl::event_y() - y()) / h() );
  227. add( r );
  228. }
  229. else if ( Fl::event_button3() && ! ( Fl::event_state() & ( FL_ALT | FL_SHIFT | FL_CTRL ) ) )
  230. {
  231. Fl_Menu_Item menu[] =
  232. {
  233. { "Rename" },
  234. { "Remove" },
  235. { 0 }
  236. };
  237. const Fl_Menu_Item *r = menu->popup( Fl::event_x(), Fl::event_y(), "Control Sequence" );
  238. if ( r )
  239. {
  240. if ( r == &menu[ 0 ] )
  241. {
  242. const char *s = fl_input( "Input new name for control sequence:", name() );
  243. if ( s )
  244. name( s );
  245. redraw();
  246. }
  247. else if ( r == &menu[ 1 ] )
  248. {
  249. Fl::delete_widget( this );
  250. }
  251. }
  252. return 1;
  253. }
  254. return 1;
  255. }
  256. default:
  257. return 0;
  258. }
  259. }