Add playhead to the GUI.

This commit is contained in:
Jonathan Moore Liles 2008-04-12 14:50:36 -05:00
parent 904daf8fe4
commit afe06f59e9
7 changed files with 116 additions and 6 deletions

View File

@ -18,6 +18,7 @@
/*******************************************************************************/
#include "Engine.H"
#include "Transport.H"
#include "Timeline.H" // for process()
@ -69,7 +70,7 @@ Engine::sync ( jack_transport_state_t state, jack_position_t *pos )
cycle */
request_locate( pos->frame );
return 1;
case JackTransportStarting: /* this means JACK is polling slow-sync clients */
case JackTransportStarting: /* this means JACK is polling slow-sync clients */
{
if ( ! seeking )
{
@ -101,12 +102,9 @@ Engine::sync ( jack_transport_state_t state, jack_position_t *pos )
int
Engine::process ( nframes_t nframes )
{
jack_position_t pos;
jack_transport_state_t ts;
transport.poll();
ts = jack_transport_query( _client, &pos );
if ( ts != JackTransportRolling )
if ( ! transport.rolling )
return 0;
if ( ! trylock() )

View File

@ -50,6 +50,7 @@ class Engine : public Mutex
private:
friend class Port;
friend class Transport;
jack_client_t * client ( void ) { return _client; }
public:

View File

@ -14,6 +14,7 @@ SRCS= \
Port.C \
Disk_Stream.C \
Engine.C \
Transport.C \
Loggable.C \
OBJS=$(SRCS:.C=.o)

View File

@ -29,9 +29,13 @@
#include "Track_Header.H"
const float UPDATE_FREQ = 0.02f;
#include "Disk_Stream.H"
#include "Transport.H"
void
Timeline::cb_scroll ( Fl_Widget *w, void *v )
{
@ -178,6 +182,7 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi
}
/* make sure scrollbars are on top */
add( vscroll );
add( hscroll );
@ -187,6 +192,9 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi
redraw();
end();
Fl::add_timeout( UPDATE_FREQ, update_cb, this );
}
@ -446,9 +454,43 @@ Timeline::draw ( void )
}
void
Timeline::draw_playhead ( void )
{
int x = ( ts_to_x( transport.frame ) - ts_to_x( xoffset ) ) + tracks->x() + Track_Header::width();
if ( x < 0 || x > tracks->w() )
return;
fl_color( FL_RED );
fl_line( x, rulers->y() + rulers->h(), x, rulers->y() + rulers->h() + tracks->h() );
}
void
Timeline::redraw_playhead ( void )
{
redraw_overlay();
}
/** called so many times a second to redraw the playhead etc. */
void
Timeline::update_cb ( void *arg )
{
Fl::repeat_timeout( UPDATE_FREQ, update_cb, arg );
Timeline *tl = (Timeline *)arg;
tl->redraw_playhead();
}
void
Timeline::draw_overlay ( void )
{
draw_playhead();
if ( ! ( _selection.w && _selection.h ) )
return;

View File

@ -138,9 +138,12 @@ public:
void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
void xposition ( int X );
void yposition ( int Y );
void draw_playhead ( void );
void redraw_playhead ( void );
void draw ( void );
void draw_overlay ( void );
int handle ( int m );
static void update_cb ( void *arg );
void select( const Rectangle &r );

33
Timeline/Transport.C Normal file
View File

@ -0,0 +1,33 @@
/*******************************************************************************/
/* 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. */
/*******************************************************************************/
#include "Transport.H"
#include "Engine.H"
Transport transport;
void
Transport::poll ( void )
{
jack_transport_state_t ts;
ts = jack_transport_query( engine->client(), this );
rolling = ts == JackTransportRolling;
}

32
Timeline/Transport.H Normal file
View File

@ -0,0 +1,32 @@
/*******************************************************************************/
/* 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. */
/*******************************************************************************/
#pragma once
#include <jack/transport.h>
#include "types.h"
struct Transport : public jack_position_t
{
bool rolling;
void poll ( void );
};
extern Transport transport;