2008-02-21 11:01:25 +01: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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Sequence.H"
|
2008-02-22 11:22:22 +01:00
|
|
|
#include "Loggable.H"
|
2008-03-03 22:00:38 +01:00
|
|
|
#include "Timeline.H"
|
|
|
|
#include <list>
|
2008-02-21 11:39:13 +01:00
|
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
class Sequence_Widget;
|
2008-04-02 09:19:48 +02:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
struct Drag
|
|
|
|
{
|
|
|
|
/* mouse coords at start of drag */
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int state;
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence_Widget *original;
|
2008-04-02 09:19:48 +02:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
Drag( int X, int Y ) : x( X ), y( Y ) { state = 0; }
|
|
|
|
};
|
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
struct Range
|
|
|
|
{
|
|
|
|
nframes_t offset; /* where on the timeline */
|
|
|
|
nframes_t start; /* first sample from clip */
|
|
|
|
nframes_t end; /* last sample from clip */
|
|
|
|
};
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
/* Base class for virtual widget on a track */
|
2008-04-19 06:16:21 +02:00
|
|
|
class Sequence_Widget : public Loggable
|
2008-02-21 11:01:25 +01:00
|
|
|
{
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
static list <Sequence_Widget *> _selection; /* all the widgets making up the selection */
|
2008-03-31 12:00:47 +02:00
|
|
|
|
|
|
|
/* FIXME: is this not the same as /pushed/? */
|
2008-04-19 06:16:21 +02:00
|
|
|
static Sequence_Widget * _current; /* the widget initiating events that affect the selection */
|
2008-03-03 22:00:38 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
/* these are actually managed in the Sequence classes */
|
|
|
|
static Sequence_Widget * _pushed; /* the widget receiving drag events (a copy) */
|
|
|
|
static Sequence_Widget * _original; /* the original of the /pushed/ widget */
|
|
|
|
static Sequence_Widget * _belowmouse; /* the widget below the mouse cursor */
|
2008-03-31 12:00:47 +02:00
|
|
|
|
2008-04-13 00:55:25 +02:00
|
|
|
/* can't have this */
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence_Widget ( const Sequence_Widget &rhs );
|
2008-04-13 00:55:25 +02:00
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
protected:
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence *_track; /* track this region belongs to */
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
Range _range; /* range for playback */
|
|
|
|
Range *_r; /* range for editing / display (points to the same thing as above, except for when dragging etc) */
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
Fl_Color _color; /* color of waveform */
|
|
|
|
Fl_Color _box_color; /* color of background (box) */
|
|
|
|
|
2008-03-04 01:25:05 +01:00
|
|
|
Drag *_drag;
|
|
|
|
|
2008-04-20 04:15:54 +02:00
|
|
|
|
2008-04-25 08:34:08 +02:00
|
|
|
virtual void get ( Log_Entry &e ) const
|
2008-04-20 04:15:54 +02:00
|
|
|
{
|
|
|
|
e.add( ":x", _r->offset );
|
|
|
|
e.add( ":l", _r->start );
|
|
|
|
e.add( ":r", _r->end );
|
|
|
|
e.add( ":t", _track );
|
|
|
|
e.add( ":s", selected() );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
set ( Log_Entry &e )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < e.size(); ++i )
|
|
|
|
{
|
|
|
|
const char *s, *v;
|
|
|
|
|
|
|
|
e.get( i, &s, &v );
|
|
|
|
|
|
|
|
if ( ! strcmp( s, ":x" ) )
|
2008-04-26 11:01:54 +02:00
|
|
|
_r->offset = atoll( v );
|
2008-04-20 04:15:54 +02:00
|
|
|
else if ( ! strcmp( s, ":l" ) )
|
2008-04-26 11:01:54 +02:00
|
|
|
_r->start = atoll( v );
|
2008-04-20 04:15:54 +02:00
|
|
|
else if ( ! strcmp( s, ":r" ) )
|
2008-04-26 11:01:54 +02:00
|
|
|
_r->end = atoll( v );
|
2008-04-20 04:15:54 +02:00
|
|
|
else if ( ! strcmp( s, ":s" ) )
|
|
|
|
{
|
|
|
|
if ( atoi( v ) )
|
|
|
|
select();
|
|
|
|
else
|
|
|
|
deselect();
|
|
|
|
}
|
2008-04-20 23:46:47 +02:00
|
|
|
else if ( ! strcmp( s, ":t" ) )
|
2008-04-20 04:15:54 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
sscanf( v, "%X", &i );
|
|
|
|
Sequence *t = (Sequence*)Loggable::find( i );
|
|
|
|
|
|
|
|
assert( t );
|
|
|
|
|
|
|
|
t->add( this );
|
|
|
|
}
|
|
|
|
// else
|
|
|
|
// e.erase( i );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( _track )
|
|
|
|
_track->redraw();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
public:
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence_Widget ( )
|
2008-02-21 11:01:25 +01:00
|
|
|
{
|
|
|
|
_track = NULL;
|
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
_r = &_range;
|
|
|
|
|
|
|
|
_r->offset = _r->start = _r->end = 0;
|
2008-03-04 01:25:05 +01:00
|
|
|
|
|
|
|
_drag = NULL;
|
2008-04-25 08:34:08 +02:00
|
|
|
|
|
|
|
_box_color = FL_BACKGROUND_COLOR;
|
|
|
|
_color = FL_FOREGROUND_COLOR;
|
2008-02-21 11:01:25 +01:00
|
|
|
}
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
virtual ~Sequence_Widget ( )
|
2008-02-27 21:04:17 +01:00
|
|
|
{
|
|
|
|
redraw();
|
2008-03-03 22:00:38 +01:00
|
|
|
|
2008-02-27 21:04:17 +01:00
|
|
|
_track->remove( this );
|
2008-03-03 22:00:38 +01:00
|
|
|
|
|
|
|
_selection.remove( this );
|
|
|
|
}
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
const Sequence_Widget &
|
|
|
|
operator= ( const Sequence_Widget &rhs )
|
2008-03-31 12:00:47 +02:00
|
|
|
{
|
2008-04-13 00:55:25 +02:00
|
|
|
if ( this == &rhs )
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
_r = &_range;
|
|
|
|
_range = rhs._range;
|
|
|
|
_track = rhs._track;
|
|
|
|
_box_color = rhs._box_color;
|
|
|
|
_color = rhs._color;
|
|
|
|
|
|
|
|
return *this;
|
2008-03-31 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
2008-04-13 00:55:25 +02:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
/* Sequence_Widget ( const Sequence_Widget &rhs ) */
|
2008-04-13 00:55:25 +02:00
|
|
|
/* { */
|
|
|
|
/* *this = rhs; */
|
|
|
|
/* } */
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
virtual Sequence_Widget *clone ( const Sequence_Widget *r ) = 0;
|
2008-03-31 12:00:47 +02:00
|
|
|
|
2008-04-25 08:34:08 +02:00
|
|
|
bool selected ( void ) const
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
|
|
|
return ::find( _selection.begin(), _selection.end(), this ) != _selection.end();
|
2008-02-27 21:04:17 +01:00
|
|
|
}
|
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
void select ( void )
|
|
|
|
{
|
2008-03-05 20:06:41 +01:00
|
|
|
if ( selected() )
|
|
|
|
return;
|
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
_selection.push_back( this );
|
2008-03-05 20:38:25 +01:00
|
|
|
_selection.sort( sort_func );
|
2008-03-05 20:06:41 +01:00
|
|
|
|
|
|
|
redraw();
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void deselect ( void )
|
|
|
|
{
|
|
|
|
_selection.remove( this );
|
2008-03-05 20:06:41 +01:00
|
|
|
redraw();
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_selected ( void )
|
|
|
|
{
|
|
|
|
while ( _selection.size() )
|
|
|
|
delete _selection.front();
|
|
|
|
}
|
|
|
|
|
2008-04-29 23:16:09 +02:00
|
|
|
static void
|
|
|
|
select_none ( void )
|
|
|
|
{
|
|
|
|
while ( _selection.size() )
|
|
|
|
{
|
|
|
|
_selection.front()->redraw();
|
|
|
|
_selection.pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
static Sequence_Widget *current ( void ) { return Sequence_Widget::_current; }
|
2008-03-31 12:00:47 +02:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
static Sequence_Widget *pushed ( void ) { return Sequence_Widget::_pushed; }
|
|
|
|
static Sequence_Widget *belowmouse ( void ) { return Sequence_Widget::_belowmouse; }
|
2008-03-31 12:00:47 +02:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
static void pushed ( Sequence_Widget *w ) { Sequence_Widget::_pushed = w; }
|
|
|
|
static void belowmouse ( Sequence_Widget *w ) { Sequence_Widget::_belowmouse = w; }
|
2008-03-31 12:00:47 +02:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
// static void pushed ( Sequence_Widget *w ) { Sequence_Widget::_pushed = w; }
|
2008-03-04 01:25:05 +01:00
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
void begin_drag ( const Drag &d )
|
|
|
|
{
|
|
|
|
_drag = new Drag( d );
|
|
|
|
_r = new Range( _range );
|
|
|
|
}
|
|
|
|
|
|
|
|
void end_drag ( void )
|
|
|
|
{
|
|
|
|
_range = *_r;
|
|
|
|
delete _r;
|
|
|
|
_r = &_range;
|
|
|
|
|
|
|
|
delete _drag;
|
|
|
|
_drag = NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-03 22:36:33 +01:00
|
|
|
void
|
|
|
|
offset ( nframes_t where )
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
2008-03-03 22:36:33 +01:00
|
|
|
|
|
|
|
if ( ! selected() )
|
|
|
|
{
|
|
|
|
redraw();
|
2008-04-02 09:19:48 +02:00
|
|
|
_r->offset = where;
|
2008-03-03 22:36:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-02 09:19:48 +02:00
|
|
|
long d = where - _r->offset;
|
2008-03-03 22:36:33 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
for ( list <Sequence_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
|
2008-03-03 22:36:33 +01:00
|
|
|
{
|
|
|
|
(*i)->redraw();
|
|
|
|
|
|
|
|
if ( d < 0 )
|
2008-04-02 09:19:48 +02:00
|
|
|
(*i)->_r->offset -= 0 - d;
|
2008-03-03 22:36:33 +01:00
|
|
|
else
|
2008-04-02 09:19:48 +02:00
|
|
|
(*i)->_r->offset += d;
|
2008-03-03 22:36:33 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
2008-03-03 19:59:05 +01:00
|
|
|
|
2008-03-03 22:36:33 +01:00
|
|
|
|
2008-03-04 01:25:05 +01:00
|
|
|
int dispatch ( int m );
|
|
|
|
|
2008-03-09 22:18:22 +01:00
|
|
|
Fl_Widget * parent ( void ) const { return _track; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
int scroll_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); }
|
|
|
|
nframes_t scroll_ts ( void ) const { return timeline->xoffset; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-03-07 05:47:52 +01:00
|
|
|
virtual int y ( void ) const { return _track->y(); }
|
2008-03-08 01:06:42 +01:00
|
|
|
virtual int h ( void ) const { return _track->h(); }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-03-08 01:57:55 +01:00
|
|
|
/* used by regions */
|
2008-04-27 07:11:00 +02:00
|
|
|
virtual int x ( void ) const
|
|
|
|
{
|
|
|
|
return _r->offset < timeline->xoffset ? _track->x() : min( _track->x() + _track->w(), _track->x() + timeline->ts_to_x( _r->offset - timeline->xoffset ) );
|
|
|
|
}
|
2008-03-08 01:57:55 +01:00
|
|
|
|
|
|
|
/* use this as x() when you need to draw lines between widgets */
|
|
|
|
int line_x ( void ) const
|
|
|
|
{
|
2008-04-02 09:19:48 +02:00
|
|
|
return _r->offset < timeline->xoffset ? max( -32768, _track->x() - timeline->ts_to_x( timeline->xoffset - _r->offset )) : min( 32767, _track->x() + timeline->ts_to_x( _r->offset - timeline->xoffset ) );
|
2008-03-08 01:57:55 +01:00
|
|
|
}
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
virtual int w ( void ) const
|
|
|
|
{
|
2008-04-02 09:19:48 +02:00
|
|
|
int tx = timeline->ts_to_x( _r->offset );
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
int rw;
|
|
|
|
if ( tx < scroll_x() )
|
|
|
|
rw = abs_w() - (scroll_x() - tx);
|
|
|
|
else
|
|
|
|
rw = abs_w();
|
|
|
|
|
|
|
|
return min( rw, _track->w() );
|
|
|
|
}
|
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
int abs_x ( void ) const { return timeline->ts_to_x( _r->offset ); }
|
|
|
|
virtual int abs_w ( void ) const { return timeline->ts_to_x( _r->end - _r->start ); }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
Fl_Color color ( void ) { return _color; }
|
2008-03-09 19:28:48 +01:00
|
|
|
void color ( Fl_Color v ) { _color = v; }
|
2008-02-21 11:01:25 +01:00
|
|
|
Fl_Color box_color ( void ) { return _box_color; }
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence * track ( void ) const { return _track; }
|
|
|
|
void track ( Sequence *t ) { _track = t; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
nframes_t offset ( void ) const { return _r->offset; }
|
|
|
|
// void offset ( nframes_t o ) { _r->offset = o; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
void end ( nframes_t v ) { _r->end = v; }
|
|
|
|
nframes_t end ( void ) const { return _r->end; }
|
|
|
|
void start ( nframes_t v ) { _r->start = v; }
|
|
|
|
nframes_t start ( void ) const { return _r->start; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-04-26 13:58:50 +02:00
|
|
|
/** convert a screen x coord into an offset into the region */
|
|
|
|
nframes_t x_to_offset ( int X )
|
|
|
|
{
|
|
|
|
return timeline->x_to_ts( scroll_x() + ( X - _track->x() ) ) - _r->offset;
|
|
|
|
}
|
2008-04-25 08:58:08 +02:00
|
|
|
|
|
|
|
int active_r ( void ) const { return _track->active_r(); }
|
2008-04-02 09:19:48 +02:00
|
|
|
virtual nframes_t length ( void ) const { return _r->end - _r->start; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }
|
2008-02-22 09:51:22 +01:00
|
|
|
virtual Fl_Align align ( void ) const { return (Fl_Align)0; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-02-22 09:51:22 +01:00
|
|
|
virtual void
|
2008-02-21 19:31:15 +01:00
|
|
|
redraw ( void )
|
|
|
|
{
|
2008-02-22 09:51:22 +01:00
|
|
|
if ( ! (align() & FL_ALIGN_INSIDE) )
|
|
|
|
{
|
|
|
|
// FIXME: to better..
|
|
|
|
_track->redraw();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );
|
2008-02-21 19:31:15 +01:00
|
|
|
}
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-02-21 19:31:15 +01:00
|
|
|
/* just draw a simple box */
|
2008-02-21 11:01:25 +01:00
|
|
|
virtual void
|
2008-04-17 17:35:20 +02:00
|
|
|
draw_box ( void )
|
2008-02-21 11:01:25 +01:00
|
|
|
{
|
2008-04-29 22:57:52 +02:00
|
|
|
fl_draw_box( box(), x(), y(), w(), h(), selected() ? FL_MAGENTA : _box_color );
|
2008-02-21 11:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
2008-04-17 17:35:20 +02:00
|
|
|
draw ( void )
|
2008-02-21 11:01:25 +01:00
|
|
|
{
|
2008-04-17 17:35:20 +02:00
|
|
|
draw_box();
|
2008-02-21 11:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2008-04-19 06:16:21 +02:00
|
|
|
operator< ( const Sequence_Widget & rhs )
|
2008-02-21 11:01:25 +01:00
|
|
|
{
|
2008-04-02 09:19:48 +02:00
|
|
|
return _r->offset < rhs._r->offset;
|
2008-02-21 11:01:25 +01:00
|
|
|
}
|
2008-03-03 22:00:38 +01:00
|
|
|
|
2008-03-10 02:07:04 +01:00
|
|
|
bool
|
2008-04-19 06:16:21 +02:00
|
|
|
operator<=( const Sequence_Widget & rhs )
|
2008-03-10 02:07:04 +01:00
|
|
|
{
|
2008-04-02 09:19:48 +02:00
|
|
|
return _r->offset <= rhs._r->offset;
|
2008-03-10 02:07:04 +01:00
|
|
|
}
|
|
|
|
|
2008-03-06 04:24:31 +01:00
|
|
|
virtual void draw_label ( const char *label, Fl_Align align, Fl_Color color=(Fl_Color)0 );
|
2008-03-03 22:00:38 +01:00
|
|
|
virtual int handle ( int m );
|
|
|
|
|
2008-03-05 20:38:25 +01:00
|
|
|
static bool
|
2008-04-19 06:16:21 +02:00
|
|
|
sort_func ( Sequence_Widget *lhs, Sequence_Widget *rhs )
|
2008-03-05 20:38:25 +01:00
|
|
|
{
|
|
|
|
return *lhs < *rhs;
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
};
|