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.

359 lines
9.0KB

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