2008-04-12 21:50:36 +02:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
|
/* option) any later version. */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
|
|
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
|
|
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
|
|
|
|
/* more details. */
|
|
|
|
|
/* */
|
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2008-06-21 06:38:29 +02:00
|
|
|
|
/* Controls the audio transport */
|
2008-05-22 09:05:49 +02:00
|
|
|
|
|
2008-04-12 21:50:36 +02:00
|
|
|
|
#include "Transport.H"
|
2008-05-22 09:05:49 +02:00
|
|
|
|
|
|
|
|
|
#include "Engine/Engine.H"
|
2008-04-12 21:50:36 +02:00
|
|
|
|
|
2008-04-22 04:47:29 +02:00
|
|
|
|
// Transport transport;
|
2008-04-12 21:50:36 +02:00
|
|
|
|
|
2010-01-17 01:38:27 +01:00
|
|
|
|
#define client engine->jack_client()
|
2008-04-22 04:15:32 +02:00
|
|
|
|
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
2008-06-10 04:14:43 +02:00
|
|
|
|
|
|
|
|
|
Transport::Transport ( int X, int Y, int W, int H, const char *L )
|
|
|
|
|
: Fl_Pack( X, Y, W, H, L )
|
|
|
|
|
{
|
|
|
|
|
recording = false;
|
|
|
|
|
rolling = false;
|
2010-01-29 21:12:24 +01:00
|
|
|
|
_stop_disables_record = true;
|
2008-06-10 04:14:43 +02:00
|
|
|
|
|
|
|
|
|
const int bw = W / 3;
|
|
|
|
|
|
|
|
|
|
type( HORIZONTAL );
|
|
|
|
|
|
|
|
|
|
Fl_Button *o;
|
|
|
|
|
|
|
|
|
|
_home_button = o = new Fl_Button( 0, 0, bw, 0, "@|<" );
|
|
|
|
|
o->labeltype( FL_EMBOSSED_LABEL );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->shortcut( FL_Home );
|
|
|
|
|
o->box( FL_UP_BOX );
|
|
|
|
|
|
|
|
|
|
_end_button = o = new Fl_Button( 0, 0, bw, 0, "@>|" );
|
|
|
|
|
o->labeltype( FL_EMBOSSED_LABEL );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->shortcut( FL_End );
|
|
|
|
|
|
|
|
|
|
_play_button = o = new Fl_Button( 0, 0, bw, 0, "@>" );
|
|
|
|
|
o->labeltype( FL_EMBOSSED_LABEL );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->shortcut( ' ' );
|
|
|
|
|
o->box( FL_UP_BOX );
|
|
|
|
|
|
|
|
|
|
_record_button = o = new Fl_Button( 0, 0, bw, 0, "@circle" );
|
|
|
|
|
o->type( FL_TOGGLE_BUTTON );
|
|
|
|
|
o->labeltype( FL_EMBOSSED_LABEL );
|
|
|
|
|
o->labelcolor( fl_color_average( FL_RED, FL_WHITE, 0.25f ) );
|
|
|
|
|
o->shortcut( 'R' );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->when( FL_WHEN_CHANGED );
|
|
|
|
|
o->box( FL_UP_BOX );
|
|
|
|
|
|
|
|
|
|
end();
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
|
|
|
|
|
2008-06-10 04:14:43 +02:00
|
|
|
|
void
|
|
|
|
|
Transport::cb_button ( Fl_Widget *w, void *v )
|
|
|
|
|
{
|
|
|
|
|
((Transport*)v)->cb_button( w );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-10-28 05:03:47 +01:00
|
|
|
|
Transport::update_record_state ( void )
|
2008-06-10 04:14:43 +02:00
|
|
|
|
{
|
2009-10-28 05:03:47 +01:00
|
|
|
|
Fl_Button *w = _record_button;
|
|
|
|
|
|
|
|
|
|
/* handle display */
|
|
|
|
|
if ( w->value() )
|
|
|
|
|
w->labelcolor( FL_RED );
|
|
|
|
|
else
|
|
|
|
|
w->labelcolor( fl_color_average( FL_RED, FL_WHITE, 0.25f ) );
|
2008-06-10 04:14:43 +02:00
|
|
|
|
|
2009-10-28 05:03:47 +01:00
|
|
|
|
w->redraw();
|
2008-06-10 04:14:43 +02:00
|
|
|
|
|
2009-10-28 05:03:47 +01:00
|
|
|
|
/* this covers the case where the record toggle button is
|
|
|
|
|
* pressed while the transport is already rolling. Recording
|
|
|
|
|
* should begin or end on the next frame */
|
|
|
|
|
if ( rolling )
|
|
|
|
|
{
|
2010-01-29 21:12:24 +01:00
|
|
|
|
if ( ! recording && w->value() )
|
2009-10-28 05:03:47 +01:00
|
|
|
|
{
|
|
|
|
|
timeline->record();
|
|
|
|
|
recording = true;
|
|
|
|
|
}
|
2010-01-29 21:12:24 +01:00
|
|
|
|
else if ( recording )
|
2008-06-16 02:19:44 +02:00
|
|
|
|
{
|
2009-10-28 05:03:47 +01:00
|
|
|
|
timeline->stop();
|
|
|
|
|
recording = false;
|
2008-06-16 02:19:44 +02:00
|
|
|
|
}
|
2008-06-10 04:14:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-28 05:03:47 +01:00
|
|
|
|
/** cb_button
|
|
|
|
|
* common handler for all transport buttons */
|
|
|
|
|
void
|
|
|
|
|
Transport::cb_button ( Fl_Widget *w )
|
2008-07-26 08:49:18 +02:00
|
|
|
|
{
|
2009-10-28 05:03:47 +01:00
|
|
|
|
if ( w == _home_button )
|
|
|
|
|
locate( 0 );
|
|
|
|
|
else if ( w == _end_button )
|
|
|
|
|
locate( timeline->length() );
|
|
|
|
|
else if ( w == _play_button )
|
|
|
|
|
toggle();
|
|
|
|
|
else if ( w == _record_button )
|
|
|
|
|
update_record_state();
|
2008-07-26 08:49:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-10 04:14:43 +02:00
|
|
|
|
void
|
|
|
|
|
Transport::toggle_record ( void )
|
|
|
|
|
{
|
2009-10-28 05:03:47 +01:00
|
|
|
|
_record_button->value( ! _record_button->value() );
|
|
|
|
|
update_record_state();
|
|
|
|
|
}
|
2008-06-10 04:14:43 +02:00
|
|
|
|
|
2009-10-28 05:03:47 +01:00
|
|
|
|
bool
|
|
|
|
|
Transport::rec_enabled ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return _record_button->value();
|
2008-06-10 04:14:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
Transport::handle ( int m )
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: hack to avoid stealing focus */
|
|
|
|
|
|
|
|
|
|
if ( m == FL_FOCUS )
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return Fl_Pack::handle( m );
|
|
|
|
|
}
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
|
|
|
|
/***********/
|
|
|
|
|
/* Control */
|
|
|
|
|
/***********/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::poll ( void )
|
|
|
|
|
{
|
|
|
|
|
jack_transport_state_t ts;
|
|
|
|
|
|
|
|
|
|
ts = jack_transport_query( client, this );
|
|
|
|
|
|
|
|
|
|
rolling = ts == JackTransportRolling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::locate ( nframes_t frame )
|
|
|
|
|
{
|
2009-10-28 05:03:47 +01:00
|
|
|
|
if ( ! recording )
|
|
|
|
|
// don't allow seeking while record is in progress
|
|
|
|
|
jack_transport_locate( client, frame );
|
2008-06-21 06:38:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::start ( void )
|
|
|
|
|
{
|
|
|
|
|
// MESSAGE( "Starting transport" );
|
|
|
|
|
if ( _record_button->value() )
|
2009-10-28 05:03:47 +01:00
|
|
|
|
{
|
|
|
|
|
rolling = true;
|
|
|
|
|
update_record_state();
|
|
|
|
|
}
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
|
|
|
|
jack_transport_start( client );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::stop ( void )
|
|
|
|
|
{
|
|
|
|
|
// MESSAGE( "Stopping transport" );
|
|
|
|
|
if ( _record_button->value() )
|
2009-10-28 05:03:47 +01:00
|
|
|
|
{
|
2010-01-29 21:12:24 +01:00
|
|
|
|
if ( _stop_disables_record )
|
|
|
|
|
_record_button->value( 0 );
|
|
|
|
|
|
2009-10-28 05:03:47 +01:00
|
|
|
|
update_record_state();
|
|
|
|
|
}
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
|
|
|
|
jack_transport_stop( client );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::toggle ( void )
|
|
|
|
|
{
|
|
|
|
|
if ( rolling )
|
|
|
|
|
stop();
|
|
|
|
|
else
|
|
|
|
|
start();
|
|
|
|
|
}
|