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"
|
2012-06-05 02:14:37 +02:00
|
|
|
|
#include "Timeline.H"
|
2008-05-22 09:05:49 +02:00
|
|
|
|
|
|
|
|
|
#include "Engine/Engine.H"
|
2008-04-12 21:50:36 +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 )
|
2013-02-13 01:50:19 +01:00
|
|
|
|
: Fl_Flowpack( X, Y, W, H, L )
|
2008-06-10 04:14:43 +02:00
|
|
|
|
{
|
|
|
|
|
recording = false;
|
|
|
|
|
rolling = false;
|
2010-01-29 21:12:24 +01:00
|
|
|
|
_stop_disables_record = true;
|
2008-06-10 04:14:43 +02:00
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
|
bar = 0;
|
|
|
|
|
beat = 0;
|
|
|
|
|
tick = 0;
|
|
|
|
|
beats_per_minute = 120;
|
|
|
|
|
ticks_per_beat = 1920;
|
|
|
|
|
beat_type = 4;
|
|
|
|
|
beats_per_bar = 4;
|
|
|
|
|
next_time = 0;
|
|
|
|
|
frame_time =0;
|
|
|
|
|
frame_rate = 48000;
|
|
|
|
|
frame = 0;
|
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
{ _home_button = new Fl_Button(5, 5, 40, 44, "@|<");
|
|
|
|
|
} // Fl_Button* _home_button
|
|
|
|
|
{ _end_button = new Fl_Button(45, 5, 40, 44, "@>|");
|
|
|
|
|
} // Fl_Button* _end_button
|
|
|
|
|
{ _play_button = new Fl_Button(85, 5, 40, 44, "@>");
|
|
|
|
|
} // Fl_Button* _play_button
|
|
|
|
|
{ _record_button = new Fl_Button(130, 5, 40, 44, "@circle");
|
|
|
|
|
} // Fl_Button* _record_button
|
|
|
|
|
{ _punch_button = new Fl_Button(175, 5, 38, 21, "Punch");
|
|
|
|
|
_punch_button->type(1);
|
|
|
|
|
_punch_button->labelsize(10);
|
|
|
|
|
} // Fl_Button* _punch_button
|
|
|
|
|
{ _loop_button = new Fl_Button(175, 20, 38, 21, "Loop");
|
|
|
|
|
_loop_button->type(1);
|
|
|
|
|
_loop_button->labelsize(10);
|
|
|
|
|
} // Fl_Button* _loop_button
|
|
|
|
|
{ _new_take_button = new Fl_Button(225, 5, 60, 21, "New Take");
|
|
|
|
|
_new_take_button->type(1);
|
|
|
|
|
_new_take_button->labelsize(10);
|
|
|
|
|
} // Fl_Button* _new_take_button
|
2013-05-02 07:04:16 +02:00
|
|
|
|
{ _freewheel_button = new Fl_Button(225, 5, 60, 21, "Freewheel");
|
|
|
|
|
_freewheel_button->type(1);
|
|
|
|
|
_freewheel_button->labelsize(10);
|
|
|
|
|
} // Fl_Button* _new_take_button
|
2013-02-13 01:50:19 +01:00
|
|
|
|
end();
|
2008-06-10 04:14:43 +02:00
|
|
|
|
|
|
|
|
|
Fl_Button *o;
|
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
o = _home_button;
|
2008-06-10 04:14:43 +02:00
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->shortcut( FL_Home );
|
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
o = _end_button;
|
2008-06-10 04:14:43 +02:00
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->shortcut( FL_End );
|
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
o = _play_button;
|
2008-06-10 04:14:43 +02:00
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->shortcut( ' ' );
|
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
o = _record_button;
|
2008-06-10 04:14:43 +02:00
|
|
|
|
o->type( FL_TOGGLE_BUTTON );
|
|
|
|
|
o->shortcut( 'R' );
|
|
|
|
|
o->callback( cb_button, this );
|
2013-03-02 02:02:59 +01:00
|
|
|
|
o->color2( FL_RED );
|
2008-06-10 04:14:43 +02:00
|
|
|
|
o->when( FL_WHEN_CHANGED );
|
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
o = _punch_button;
|
2012-06-14 03:28:49 +02:00
|
|
|
|
o->type( FL_TOGGLE_BUTTON );
|
|
|
|
|
o->shortcut( 'P' );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->when( FL_WHEN_CHANGED );
|
2013-02-13 01:50:19 +01:00
|
|
|
|
o->color2( fl_color_average( FL_GRAY, FL_RED, 0.50 ));
|
|
|
|
|
o->tooltip( "Toggle punch in/out recording mode" );
|
|
|
|
|
|
|
|
|
|
o = _loop_button;
|
|
|
|
|
o->type( FL_TOGGLE_BUTTON );
|
|
|
|
|
o->shortcut( 'L' );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->when( FL_WHEN_CHANGED );
|
|
|
|
|
o->color2( fl_color_average( FL_GRAY, FL_GREEN, 0.50 ));
|
|
|
|
|
o->tooltip( "Toggle looped playback" );
|
2012-06-14 03:28:49 +02:00
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
o = _new_take_button;
|
|
|
|
|
o->type( FL_TOGGLE_BUTTON );
|
|
|
|
|
o->shortcut( 'T' );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->when( FL_WHEN_CHANGED );
|
|
|
|
|
o->color2( fl_color_average( FL_GRAY, FL_YELLOW, 0.50 ) );
|
|
|
|
|
o->tooltip( "Toggle automatic creation of new takes for armed tracks" );
|
2013-02-22 03:19:44 +01:00
|
|
|
|
|
2013-05-02 07:04:16 +02:00
|
|
|
|
o = _freewheel_button;
|
|
|
|
|
o->type( FL_TOGGLE_BUTTON );
|
|
|
|
|
o->shortcut( 'T' );
|
|
|
|
|
o->callback( cb_button, this );
|
|
|
|
|
o->when( FL_WHEN_CHANGED );
|
|
|
|
|
o->color2( fl_color_average( FL_GRAY, FL_BLUE, 0.50 ) );
|
|
|
|
|
o->tooltip( "When active, the next playback will be done in freewheeling mode" );
|
|
|
|
|
|
2013-02-22 03:19:44 +01:00
|
|
|
|
flowdown( true );
|
2008-06-10 04:14:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
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() )
|
2013-03-02 02:02:59 +01:00
|
|
|
|
w->labelcolor( FL_BACKGROUND_COLOR );
|
2009-10-28 05:03:47 +01:00
|
|
|
|
else
|
2013-03-02 02:02:59 +01:00
|
|
|
|
w->labelcolor( FL_FOREGROUND_COLOR );
|
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 )
|
2012-10-24 07:44:19 +02:00
|
|
|
|
locate( timeline->playback_home() );
|
2009-10-28 05:03:47 +01:00
|
|
|
|
else if ( w == _end_button )
|
2012-10-24 07:44:19 +02:00
|
|
|
|
locate( timeline->playback_end() );
|
2009-10-28 05:03:47 +01:00
|
|
|
|
else if ( w == _play_button )
|
|
|
|
|
toggle();
|
|
|
|
|
else if ( w == _record_button )
|
|
|
|
|
update_record_state();
|
2012-10-24 07:44:19 +02:00
|
|
|
|
else if ( w == _punch_button )
|
|
|
|
|
timeline->redraw();
|
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
|
|
|
|
|
2013-08-24 23:21:44 +02:00
|
|
|
|
bool
|
|
|
|
|
Transport::freewheel_enabled ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return _freewheel_button->value();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2012-06-14 03:28:49 +02:00
|
|
|
|
bool
|
|
|
|
|
Transport::punch_enabled ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return _punch_button->value();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 01:50:19 +01:00
|
|
|
|
bool
|
|
|
|
|
Transport::loop_enabled ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return _loop_button->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::loop_enabled ( bool b )
|
|
|
|
|
{
|
|
|
|
|
_loop_button->value( b );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Transport::automatically_create_takes ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return _new_take_button->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::automatically_create_takes ( bool b )
|
|
|
|
|
{
|
|
|
|
|
_new_take_button->value( b );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2013-02-13 01:50:19 +01:00
|
|
|
|
return Fl_Flowpack::handle( m );
|
2008-06-10 04:14:43 +02:00
|
|
|
|
}
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
|
|
|
|
/***********/
|
|
|
|
|
/* Control */
|
|
|
|
|
/***********/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::poll ( void )
|
|
|
|
|
{
|
2010-01-21 01:33:02 +01:00
|
|
|
|
|
2008-06-21 06:38:29 +02:00
|
|
|
|
jack_transport_state_t ts;
|
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
|
ts = engine->transport_query( this );
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
|
|
|
|
rolling = ts == JackTransportRolling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::locate ( nframes_t frame )
|
|
|
|
|
{
|
2010-01-21 01:33:02 +01:00
|
|
|
|
if ( ! engine )
|
|
|
|
|
return;
|
|
|
|
|
|
2009-10-28 05:03:47 +01:00
|
|
|
|
if ( ! recording )
|
2012-10-24 07:44:19 +02:00
|
|
|
|
{
|
2009-10-28 05:03:47 +01:00
|
|
|
|
// don't allow seeking while record is in progress
|
2010-01-21 01:33:02 +01:00
|
|
|
|
engine->transport_locate( frame );
|
2012-10-24 07:44:19 +02:00
|
|
|
|
|
|
|
|
|
/* so there isn't a race waiting for the transport to sync */
|
|
|
|
|
this->frame = frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeline->_created_new_takes = false;
|
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
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
|
if ( engine )
|
2013-05-02 07:04:16 +02:00
|
|
|
|
{
|
|
|
|
|
if ( _freewheel_button->value() )
|
|
|
|
|
engine->freewheeling( true );
|
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
|
engine->transport_start();
|
2013-05-02 07:04:16 +02:00
|
|
|
|
}
|
2008-06-21 06:38:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
2012-10-24 07:44:19 +02:00
|
|
|
|
timeline->_created_new_takes = false;
|
|
|
|
|
|
2009-10-28 05:03:47 +01:00
|
|
|
|
update_record_state();
|
|
|
|
|
}
|
2008-06-21 06:38:29 +02:00
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
|
if ( engine )
|
2013-05-02 07:04:16 +02:00
|
|
|
|
{
|
2010-01-21 01:33:02 +01:00
|
|
|
|
engine->transport_stop();
|
2013-05-02 07:04:16 +02:00
|
|
|
|
|
|
|
|
|
if ( _freewheel_button->value() )
|
|
|
|
|
{
|
|
|
|
|
engine->freewheeling( false );
|
|
|
|
|
_freewheel_button->value( false );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-21 06:38:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Transport::toggle ( void )
|
|
|
|
|
{
|
|
|
|
|
if ( rolling )
|
|
|
|
|
stop();
|
|
|
|
|
else
|
|
|
|
|
start();
|
|
|
|
|
}
|