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.

211 lines
5.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. /* Controls the audio transport */
  19. #include "Transport.H"
  20. #include "Engine/Engine.H"
  21. // Transport transport;
  22. #define client engine->jack_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. _stop_disables_record = true;
  29. const int bw = W / 3;
  30. type( HORIZONTAL );
  31. Fl_Button *o;
  32. _home_button = o = new Fl_Button( 0, 0, bw, 0, "@|<" );
  33. o->labeltype( FL_EMBOSSED_LABEL );
  34. o->callback( cb_button, this );
  35. o->shortcut( FL_Home );
  36. o->box( FL_UP_BOX );
  37. _end_button = o = new Fl_Button( 0, 0, bw, 0, "@>|" );
  38. o->labeltype( FL_EMBOSSED_LABEL );
  39. o->callback( cb_button, this );
  40. o->shortcut( FL_End );
  41. _play_button = o = new Fl_Button( 0, 0, bw, 0, "@>" );
  42. o->labeltype( FL_EMBOSSED_LABEL );
  43. o->callback( cb_button, this );
  44. o->shortcut( ' ' );
  45. o->box( FL_UP_BOX );
  46. _record_button = o = new Fl_Button( 0, 0, bw, 0, "@circle" );
  47. o->type( FL_TOGGLE_BUTTON );
  48. o->labeltype( FL_EMBOSSED_LABEL );
  49. o->labelcolor( fl_color_average( FL_RED, FL_WHITE, 0.25f ) );
  50. o->shortcut( 'R' );
  51. o->callback( cb_button, this );
  52. o->when( FL_WHEN_CHANGED );
  53. o->box( FL_UP_BOX );
  54. end();
  55. }
  56. void
  57. Transport::cb_button ( Fl_Widget *w, void *v )
  58. {
  59. ((Transport*)v)->cb_button( w );
  60. }
  61. void
  62. Transport::update_record_state ( void )
  63. {
  64. Fl_Button *w = _record_button;
  65. /* handle display */
  66. if ( w->value() )
  67. w->labelcolor( FL_RED );
  68. else
  69. w->labelcolor( fl_color_average( FL_RED, FL_WHITE, 0.25f ) );
  70. w->redraw();
  71. /* this covers the case where the record toggle button is
  72. * pressed while the transport is already rolling. Recording
  73. * should begin or end on the next frame */
  74. if ( rolling )
  75. {
  76. if ( ! recording && w->value() )
  77. {
  78. timeline->record();
  79. recording = true;
  80. }
  81. else if ( recording )
  82. {
  83. timeline->stop();
  84. recording = false;
  85. }
  86. }
  87. }
  88. /** cb_button
  89. * common handler for all transport buttons */
  90. void
  91. Transport::cb_button ( Fl_Widget *w )
  92. {
  93. if ( w == _home_button )
  94. locate( 0 );
  95. else if ( w == _end_button )
  96. locate( timeline->length() );
  97. else if ( w == _play_button )
  98. toggle();
  99. else if ( w == _record_button )
  100. update_record_state();
  101. }
  102. void
  103. Transport::toggle_record ( void )
  104. {
  105. _record_button->value( ! _record_button->value() );
  106. update_record_state();
  107. }
  108. bool
  109. Transport::rec_enabled ( void ) const
  110. {
  111. return _record_button->value();
  112. }
  113. int
  114. Transport::handle ( int m )
  115. {
  116. /* FIXME: hack to avoid stealing focus */
  117. if ( m == FL_FOCUS )
  118. return 0;
  119. else
  120. return Fl_Pack::handle( m );
  121. }
  122. /***********/
  123. /* Control */
  124. /***********/
  125. void
  126. Transport::poll ( void )
  127. {
  128. jack_transport_state_t ts;
  129. ts = jack_transport_query( client, this );
  130. rolling = ts == JackTransportRolling;
  131. }
  132. void
  133. Transport::locate ( nframes_t frame )
  134. {
  135. if ( ! recording )
  136. // don't allow seeking while record is in progress
  137. jack_transport_locate( client, frame );
  138. }
  139. void
  140. Transport::start ( void )
  141. {
  142. // MESSAGE( "Starting transport" );
  143. if ( _record_button->value() )
  144. {
  145. rolling = true;
  146. update_record_state();
  147. }
  148. jack_transport_start( client );
  149. }
  150. void
  151. Transport::stop ( void )
  152. {
  153. // MESSAGE( "Stopping transport" );
  154. if ( _record_button->value() )
  155. {
  156. if ( _stop_disables_record )
  157. _record_button->value( 0 );
  158. update_record_state();
  159. }
  160. jack_transport_stop( client );
  161. }
  162. void
  163. Transport::toggle ( void )
  164. {
  165. if ( rolling )
  166. stop();
  167. else
  168. start();
  169. }