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.

187 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. bool
  86. Transport::rec_enabled ( void ) const
  87. {
  88. return _record_button->value();
  89. }
  90. void
  91. Transport::toggle_record ( void )
  92. {
  93. if ( _record_button->value() )
  94. _record_button->value( 0 );
  95. else
  96. _record_button->value( 1 );
  97. _record_button->do_callback();
  98. }
  99. int
  100. Transport::handle ( int m )
  101. {
  102. /* FIXME: hack to avoid stealing focus */
  103. if ( m == FL_FOCUS )
  104. return 0;
  105. else
  106. return Fl_Pack::handle( m );
  107. }
  108. /***********/
  109. /* Control */
  110. /***********/
  111. void
  112. Transport::poll ( void )
  113. {
  114. jack_transport_state_t ts;
  115. ts = jack_transport_query( client, this );
  116. rolling = ts == JackTransportRolling;
  117. }
  118. void
  119. Transport::locate ( nframes_t frame )
  120. {
  121. jack_transport_locate( client, frame );
  122. }
  123. void
  124. Transport::start ( void )
  125. {
  126. // MESSAGE( "Starting transport" );
  127. if ( _record_button->value() )
  128. timeline->record();
  129. jack_transport_start( client );
  130. }
  131. void
  132. Transport::stop ( void )
  133. {
  134. // MESSAGE( "Stopping transport" );
  135. if ( _record_button->value() )
  136. toggle_record();
  137. jack_transport_stop( client );
  138. }
  139. void
  140. Transport::toggle ( void )
  141. {
  142. if ( rolling )
  143. stop();
  144. else
  145. start();
  146. }