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.

576 lines
14KB

  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 "Transport.H"
  20. /* #include "Port.H" */
  21. #include "../FL/Fl_Sometimes_Input.H"
  22. #include <FL/fl_ask.H>
  23. #include <FL/Fl_Color_Chooser.H>
  24. // #include <FL/fl_draw.H>
  25. #include <FL/Fl.H>
  26. #include "Control_Sequence.H"
  27. #include "Annotation_Sequence.H"
  28. int Track::_soloing = 0;
  29. const char *Track::capture_format = "Wav 24";
  30. void
  31. Track::cb_input_field ( Fl_Widget *, void *v )
  32. {
  33. ((Track*)v)->cb_input_field();
  34. }
  35. void
  36. Track::cb_button ( Fl_Widget *w, void *v )
  37. {
  38. ((Track*)v)->cb_button( w );
  39. }
  40. void
  41. Track::cb_input_field ( void )
  42. {
  43. log_start();
  44. name( name_field->value() );
  45. log_end();
  46. }
  47. void
  48. Track::cb_button ( Fl_Widget *w )
  49. {
  50. if ( w == record_button )
  51. {
  52. }
  53. if ( w == mute_button )
  54. {
  55. }
  56. if ( w == solo_button )
  57. {
  58. if ( solo_button->value() )
  59. ++_soloing;
  60. else
  61. --_soloing;
  62. }
  63. else
  64. if ( w == take_menu )
  65. {
  66. int v = take_menu->value();
  67. switch ( v )
  68. {
  69. case 0: /* show all takes */
  70. show_all_takes( take_menu->menu()[ v ].value() );
  71. return;
  72. case 1: /* new */
  73. sequence( (Audio_Sequence*)sequence()->clone_empty() );
  74. return;
  75. }
  76. const char *s = take_menu->menu()[ v ].text;
  77. for ( int i = takes->children(); i--; )
  78. {
  79. Audio_Sequence *t = (Audio_Sequence*)takes->child( i );
  80. if ( ! strcmp( s, t->name() ) )
  81. {
  82. sequence( t );
  83. redraw();
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. void
  90. Track::init ( void )
  91. {
  92. _sequence = NULL;
  93. _name = NULL;
  94. _selected = false;
  95. _show_all_takes = false;
  96. _size = 1;
  97. record_ds = NULL;
  98. playback_ds = NULL;
  99. labeltype( FL_NO_LABEL );
  100. Fl_Group::size( timeline->w(), height() );
  101. Track *o = this;
  102. o->box( FL_THIN_UP_BOX );
  103. {
  104. Fl_Group *o = new Fl_Group( 0, 0, 149, 70 );
  105. o->color( ( Fl_Color ) 53 );
  106. {
  107. Fl_Input *o = name_field = new Fl_Sometimes_Input( 2, 2, 144, 24 );
  108. o->color( FL_BACKGROUND_COLOR );
  109. o->labeltype( FL_NO_LABEL );
  110. o->labelcolor( FL_GRAY0 );
  111. o->textcolor( FL_FOREGROUND_COLOR );
  112. o->callback( cb_input_field, (void*)this );
  113. }
  114. {
  115. Fl_Group *o = controls = new Fl_Group( 2, 28, 149, 24 );
  116. {
  117. Fl_Button *o = record_button =
  118. new Fl_Button( 6, 28, 26, 24, "@circle" );
  119. o->type( 1 );
  120. o->box( FL_THIN_UP_BOX );
  121. o->color( FL_LIGHT1 );
  122. o->selection_color( FL_RED );
  123. o->labelsize( 8 );
  124. o->callback( cb_button, this );
  125. }
  126. {
  127. Fl_Button *o = mute_button =
  128. new Fl_Button( 35, 28, 26, 24, "m" );
  129. o->type( 1 );
  130. o->box( FL_THIN_UP_BOX );
  131. o->color( FL_LIGHT1 );
  132. o->labelsize( 11 );
  133. o->callback( cb_button, this );
  134. }
  135. {
  136. Fl_Button *o = solo_button =
  137. new Fl_Button( 66, 28, 26, 24, "s" );
  138. o->type( 1 );
  139. o->box( FL_THIN_UP_BOX );
  140. o->color( FL_LIGHT1 );
  141. o->labelsize( 11 );
  142. o->callback( cb_button, this );
  143. }
  144. {
  145. Fl_Menu_Button *o = take_menu =
  146. new Fl_Menu_Button( 97, 28, 47, 24, "T" );
  147. o->box( FL_THIN_UP_BOX );
  148. o->color( FL_LIGHT1 );
  149. o->align( FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
  150. o->callback( cb_button, this );
  151. o->add( "Show all takes", 0, 0, 0, FL_MENU_TOGGLE );
  152. o->add( "New", 0, 0, 0, FL_MENU_DIVIDER );
  153. }
  154. o->end();
  155. }
  156. {
  157. Fl_Box *o = new Fl_Box( 0, 72, 149, 38 );
  158. o->box( FL_NO_BOX );
  159. Fl_Group::current()->resizable( o );
  160. }
  161. o->size( Track::width(), h() );
  162. o->end();
  163. }
  164. {
  165. Fl_Pack *o = pack = new Fl_Pack( width(), 0, 1006, 115 );
  166. o->labeltype( FL_NO_LABEL );
  167. o->resize( x() + width(), y(), w() - width(), h() );
  168. resizable( o );
  169. {
  170. // Fl_Pack *o = annotation = new Fl_Pack( width(), 0, pack->w(), 0 );
  171. Fl_Pack *o = annotation = new Fl_Pack( width(), 0, pack->w(), 1 );
  172. o->end();
  173. }
  174. {
  175. Fl_Pack *o = control = new Fl_Pack( width(), 0, pack->w(), 0 );
  176. o->end();
  177. }
  178. {
  179. Fl_Pack *o = takes = new Fl_Pack( width(), 0, pack->w(), 0 );
  180. o->end();
  181. o->hide();
  182. }
  183. o->end();
  184. }
  185. end();
  186. }
  187. Track::Track ( const char *L, int channels ) :
  188. Fl_Group ( 0, 0, 0, 0, 0 )
  189. {
  190. init();
  191. if ( L )
  192. name( L );
  193. color( (Fl_Color)rand() );
  194. configure_inputs( channels );
  195. configure_outputs( channels );
  196. log_create();
  197. }
  198. Track::~Track ( )
  199. {
  200. /* FIXME: why is this necessary? */
  201. timeline->remove_track( this );
  202. /* give up our ports */
  203. configure_inputs( 0 );
  204. configure_outputs( 0 );
  205. /* controls too */
  206. for ( int i = control_out.size(); i--; )
  207. {
  208. control_out.back()->shutdown();
  209. delete control_out.back();
  210. control_out.pop_back();
  211. }
  212. log_destroy();
  213. if ( _name )
  214. free( _name );
  215. }
  216. static int pack_visible( Fl_Pack *p )
  217. {
  218. int v = 0;
  219. for ( int i = p->children(); i--; )
  220. if ( p->child( i )->visible() )
  221. v++;
  222. return v;
  223. }
  224. /* adjust size of widget and children */
  225. void
  226. Track::resize ( void )
  227. {
  228. for ( int i = takes->children(); i--; )
  229. takes->child( i )->size( w(), height() );
  230. for ( int i = annotation->children(); i--; )
  231. annotation->child( i )->size( w(), 24 );
  232. for ( int i = control->children(); i--; )
  233. control->child( i )->size( w(), height() );
  234. /* FIXME: hack! */
  235. if ( annotation->children() )
  236. annotation->show();
  237. else
  238. annotation->hide();
  239. if ( _show_all_takes )
  240. {
  241. takes->show();
  242. Fl_Group::size( w(), height() * ( 1 + takes->children() + pack_visible( control ) ) );
  243. }
  244. else
  245. {
  246. takes->hide();
  247. Fl_Group::size( w(), height() * ( 1 + pack_visible( control ) ) );
  248. }
  249. Fl_Group::size( w(), h() + ( ( 24 ) * pack_visible( annotation ) ) );
  250. if ( sequence() )
  251. sequence()->size( w(), height() );
  252. if ( controls->y() + controls->h() > y() + h() )
  253. controls->hide();
  254. else
  255. controls->show();
  256. /* FIXME: why is this necessary? */
  257. if ( parent() )
  258. parent()->parent()->redraw();
  259. }
  260. void
  261. Track::size ( int v )
  262. {
  263. if ( v < 0 || v > 3 )
  264. return;
  265. _size = v;
  266. resize();
  267. }
  268. void
  269. Track::add ( Audio_Sequence * t )
  270. {
  271. takes->insert( *t, 0 );
  272. if ( ! t->name() )
  273. {
  274. char pat[20];
  275. snprintf( pat, sizeof( pat ), "%d", takes->children() );
  276. t->name( strdup( pat ) );
  277. }
  278. take_menu->add( t->name() );
  279. t->labeltype( FL_ENGRAVED_LABEL );
  280. }
  281. void
  282. Track::remove ( Audio_Sequence *t )
  283. {
  284. takes->remove( t );
  285. resize();
  286. // take_menu->remove( t->name() );
  287. }
  288. void
  289. Track::remove ( Control_Sequence *t )
  290. {
  291. control->remove( t );
  292. resize();
  293. }
  294. void
  295. Track::sequence ( Audio_Sequence * t )
  296. {
  297. t->track( this );
  298. if ( sequence() )
  299. add( sequence() );
  300. _sequence = t;
  301. pack->insert( *t, 1 );
  302. t->labeltype( FL_NO_LABEL );
  303. resize();
  304. }
  305. void
  306. Track::add ( Control_Sequence *t )
  307. {
  308. DMESSAGE( "adding control sequence" );
  309. t->track( this );
  310. control->add( t );
  311. resize();
  312. }
  313. void
  314. Track::add ( Annotation_Sequence *t )
  315. {
  316. DMESSAGE( "adding annotation sequence" );
  317. t->track( this );
  318. annotation->add( t );
  319. resize();
  320. }
  321. /** add all widget on this track falling within the given rectangle to
  322. the selection. */
  323. void
  324. Track::select ( int X, int Y, int W, int H,
  325. bool include_control, bool merge_control )
  326. {
  327. Sequence *t = sequence();
  328. if ( ! ( t->y() > Y + H || t->y() + t->h() < Y ) )
  329. t->select_range( X, W );
  330. else
  331. include_control = true;
  332. if ( include_control )
  333. for ( int i = control->children(); i--; )
  334. {
  335. Control_Sequence *c = (Control_Sequence*)control->child( i );
  336. if ( merge_control ||
  337. ( c->y() >= Y && c->y() + c->h() <= Y + H ) )
  338. c->select_range( X, W );
  339. }
  340. }
  341. void
  342. Track::draw ( void )
  343. {
  344. if ( _selected )
  345. {
  346. Fl_Color c = color();
  347. color( FL_RED );
  348. Fl_Group::draw();
  349. color( c );
  350. }
  351. else
  352. Fl_Group::draw();
  353. }
  354. int
  355. Track::handle ( int m )
  356. {
  357. switch ( m )
  358. {
  359. case FL_MOUSEWHEEL:
  360. {
  361. Logger log( this );
  362. if ( ! Fl::event_shift() )
  363. return 0;
  364. int d = Fl::event_dy();
  365. if ( d < 0 )
  366. size( size() - 1 );
  367. else
  368. size( size() + 1 );
  369. return 1;
  370. }
  371. case FL_PUSH:
  372. {
  373. Logger log( this );
  374. int X = Fl::event_x();
  375. int Y = Fl::event_y();
  376. if ( Fl::event_button3() && X < Track::width() )
  377. {
  378. int c = output.size();
  379. /* context menu */
  380. Fl_Menu_Item menu[] =
  381. {
  382. { "Type", 0, 0, 0, FL_SUBMENU },
  383. { "Mono", 0, 0, 0, FL_MENU_RADIO | ( c == 1 ? FL_MENU_VALUE : 0 ) },
  384. { "Stereo", 0, 0, 0, FL_MENU_RADIO | ( c == 2 ? FL_MENU_VALUE : 0 ) },
  385. { "Quad", 0, 0, 0, FL_MENU_RADIO | ( c == 4 ? FL_MENU_VALUE : 0 ) },
  386. { "...", 0, 0, 0, FL_MENU_RADIO | ( c == 3 || c > 4 ? FL_MENU_VALUE : 0 ) },
  387. { 0 },
  388. { "Add Control" },
  389. { "Add Annotation" },
  390. { "Color" },
  391. { "Remove", 0, 0, 0, transport->rolling ? FL_MENU_INACTIVE : 0 },
  392. { 0 },
  393. };
  394. const Fl_Menu_Item *r = menu->popup( X, Y, "Track" );
  395. if ( r && r > &menu[ 0 ] )
  396. {
  397. if ( r < &menu[ 4 ] )
  398. {
  399. int c = r - &menu[1];
  400. int ca[] = { 1, 2, 4 };
  401. configure_inputs( ca[ c ] );
  402. configure_outputs( ca[ c ] );
  403. }
  404. else
  405. {
  406. if ( r == &menu[ 4 ] )
  407. {
  408. const char *s = fl_input( "How many channels?", "3" );
  409. int c = atoi( s );
  410. if ( c <= 0 || c > 10 )
  411. fl_alert( "Invalid number of channels." );
  412. else
  413. {
  414. configure_inputs( c );
  415. configure_outputs( c );
  416. }
  417. }
  418. else if ( r == &menu[ 6 ] )
  419. {
  420. new Control_Sequence( this );
  421. }
  422. else if ( r == &menu[ 7 ] )
  423. {
  424. add( new Annotation_Sequence( this ) );
  425. }
  426. else if ( r == &menu[ 8 ] )
  427. {
  428. unsigned char r, g, b;
  429. Fl::get_color( color(), r, g, b );
  430. if ( fl_color_chooser( "Track Color", r, g, b ) )
  431. {
  432. color( fl_rgb_color( r, g, b ) );
  433. }
  434. // color( fl_show_colormap( color() ) );
  435. redraw();
  436. }
  437. else if ( r == &menu[ 9 ] )
  438. {
  439. int r = fl_choice( "Are you certain you want to remove track \"%s\"?", "Cancel", NULL, "Remove", name() );
  440. if ( r == 2 )
  441. {
  442. timeline->remove_track( this );
  443. /* FIXME: need to queue deletion. in a way that won't crash the playback. */
  444. // delete this;
  445. Fl::delete_widget( this );
  446. }
  447. }
  448. }
  449. }
  450. return 1;
  451. }
  452. }
  453. default:
  454. return Fl_Group::handle( m );
  455. }
  456. return 0;
  457. }