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.

177 lines
4.3KB

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