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.

208 lines
4.9KB

  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::update_record_state ( void )
  62. {
  63. Fl_Button *w = _record_button;
  64. /* handle display */
  65. if ( w->value() )
  66. w->labelcolor( FL_RED );
  67. else
  68. w->labelcolor( fl_color_average( FL_RED, FL_WHITE, 0.25f ) );
  69. w->redraw();
  70. /* this covers the case where the record toggle button is
  71. * pressed while the transport is already rolling. Recording
  72. * should begin or end on the next frame */
  73. if ( rolling )
  74. {
  75. if ( w->value() )
  76. {
  77. timeline->record();
  78. recording = true;
  79. }
  80. else
  81. {
  82. timeline->stop();
  83. recording = false;
  84. }
  85. }
  86. }
  87. /** cb_button
  88. * common handler for all transport buttons */
  89. void
  90. Transport::cb_button ( Fl_Widget *w )
  91. {
  92. if ( w == _home_button )
  93. locate( 0 );
  94. else if ( w == _end_button )
  95. locate( timeline->length() );
  96. else if ( w == _play_button )
  97. toggle();
  98. else if ( w == _record_button )
  99. update_record_state();
  100. }
  101. void
  102. Transport::toggle_record ( void )
  103. {
  104. _record_button->value( ! _record_button->value() );
  105. update_record_state();
  106. }
  107. bool
  108. Transport::rec_enabled ( void ) const
  109. {
  110. return _record_button->value();
  111. }
  112. int
  113. Transport::handle ( int m )
  114. {
  115. /* FIXME: hack to avoid stealing focus */
  116. if ( m == FL_FOCUS )
  117. return 0;
  118. else
  119. return Fl_Pack::handle( m );
  120. }
  121. /***********/
  122. /* Control */
  123. /***********/
  124. void
  125. Transport::poll ( void )
  126. {
  127. jack_transport_state_t ts;
  128. ts = jack_transport_query( client, this );
  129. rolling = ts == JackTransportRolling;
  130. }
  131. void
  132. Transport::locate ( nframes_t frame )
  133. {
  134. if ( ! recording )
  135. // don't allow seeking while record is in progress
  136. jack_transport_locate( client, frame );
  137. }
  138. void
  139. Transport::start ( void )
  140. {
  141. // MESSAGE( "Starting transport" );
  142. if ( _record_button->value() )
  143. {
  144. rolling = true;
  145. update_record_state();
  146. }
  147. jack_transport_start( client );
  148. }
  149. void
  150. Transport::stop ( void )
  151. {
  152. // MESSAGE( "Stopping transport" );
  153. if ( _record_button->value() )
  154. {
  155. _record_button->value( 0 );
  156. update_record_state();
  157. }
  158. jack_transport_stop( client );
  159. }
  160. void
  161. Transport::toggle ( void )
  162. {
  163. if ( rolling )
  164. stop();
  165. else
  166. start();
  167. }