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.

181 lines
4.4KB

  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. /* Controls the audio transport */
  19. #include "Transport.H"
  20. #include "Engine/Engine.H"
  21. // Transport transport;
  22. #define client engine->client()
  23. Transport::Transport ( int X, int Y, int W, int H, const char *L )
  24. : Fl_Pack( X, Y, W, H, L )
  25. {
  26. recording = false;
  27. rolling = false;
  28. const int bw = W / 3;
  29. type( HORIZONTAL );
  30. Fl_Button *o;
  31. _home_button = o = new Fl_Button( 0, 0, bw, 0, "@|<" );
  32. o->labeltype( FL_EMBOSSED_LABEL );
  33. o->callback( cb_button, this );
  34. o->shortcut( FL_Home );
  35. o->box( FL_UP_BOX );
  36. _end_button = o = new Fl_Button( 0, 0, bw, 0, "@>|" );
  37. o->labeltype( FL_EMBOSSED_LABEL );
  38. o->callback( cb_button, this );
  39. o->shortcut( FL_End );
  40. _play_button = o = new Fl_Button( 0, 0, bw, 0, "@>" );
  41. o->labeltype( FL_EMBOSSED_LABEL );
  42. o->callback( cb_button, this );
  43. o->shortcut( ' ' );
  44. o->box( FL_UP_BOX );
  45. _record_button = o = new Fl_Button( 0, 0, bw, 0, "@circle" );
  46. o->type( FL_TOGGLE_BUTTON );
  47. o->labeltype( FL_EMBOSSED_LABEL );
  48. o->labelcolor( fl_color_average( FL_RED, FL_WHITE, 0.25f ) );
  49. o->shortcut( 'R' );
  50. o->callback( cb_button, this );
  51. o->when( FL_WHEN_CHANGED );
  52. o->box( FL_UP_BOX );
  53. end();
  54. }
  55. void
  56. Transport::cb_button ( Fl_Widget *w, void *v )
  57. {
  58. ((Transport*)v)->cb_button( w );
  59. }
  60. void
  61. Transport::cb_button ( Fl_Widget *w )
  62. {
  63. if ( w == _home_button )
  64. locate( 0 );
  65. if ( w == _end_button )
  66. locate( timeline->length() );
  67. else if ( w == _play_button )
  68. toggle();
  69. else if ( w == _record_button )
  70. {
  71. if ( _record_button->value() )
  72. w->labelcolor( FL_RED );
  73. else
  74. w->labelcolor( fl_color_average( FL_RED, FL_WHITE, 0.25f ) );
  75. redraw();
  76. if ( rolling )
  77. {
  78. if ( _record_button->value() )
  79. timeline->record();
  80. else
  81. timeline->stop();
  82. }
  83. }
  84. }
  85. void
  86. Transport::toggle_record ( void )
  87. {
  88. if ( _record_button->value() )
  89. _record_button->value( 0 );
  90. else
  91. _record_button->value( 1 );
  92. _record_button->do_callback();
  93. }
  94. int
  95. Transport::handle ( int m )
  96. {
  97. /* FIXME: hack to avoid stealing focus */
  98. if ( m == FL_FOCUS )
  99. return 0;
  100. else
  101. return Fl_Pack::handle( m );
  102. }
  103. /***********/
  104. /* Control */
  105. /***********/
  106. void
  107. Transport::poll ( void )
  108. {
  109. jack_transport_state_t ts;
  110. ts = jack_transport_query( client, this );
  111. rolling = ts == JackTransportRolling;
  112. }
  113. void
  114. Transport::locate ( nframes_t frame )
  115. {
  116. jack_transport_locate( client, frame );
  117. }
  118. void
  119. Transport::start ( void )
  120. {
  121. // MESSAGE( "Starting transport" );
  122. if ( _record_button->value() )
  123. timeline->record();
  124. jack_transport_start( client );
  125. }
  126. void
  127. Transport::stop ( void )
  128. {
  129. // MESSAGE( "Stopping transport" );
  130. if ( _record_button->value() )
  131. toggle_record();
  132. jack_transport_stop( client );
  133. }
  134. void
  135. Transport::toggle ( void )
  136. {
  137. if ( rolling )
  138. stop();
  139. else
  140. start();
  141. }