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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
2008-05-22 17:32:26 +02:00
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
#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>
|
2008-05-18 07:09:18 +02:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
2008-02-21 11:39:13 +01:00
|
|
|
|
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
|
|
|
|
{
|
2008-05-07 20:43:56 +02:00
|
|
|
/* mouse coords at offset of drag */
|
2008-03-05 20:06:41 +01:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int state;
|
|
|
|
|
2013-09-24 08:33:24 +02:00
|
|
|
// nframes_t start;
|
|
|
|
int64_t offset;
|
2008-04-02 09:19:48 +02:00
|
|
|
|
2013-09-24 08:33:24 +02:00
|
|
|
Drag( int X, int Y, uint64_t offset=0 ) : x( X ), y( Y ), offset( offset ) { state = 0; }
|
2008-03-05 20:06:41 +01:00
|
|
|
};
|
|
|
|
|
2008-05-12 18:23:55 +02:00
|
|
|
/* most common position description. /offset/ is only used by Regions,
|
2008-06-23 03:01:09 +02:00
|
|
|
but it's more convenient to have it here */
|
2008-04-02 09:19:48 +02:00
|
|
|
struct Range
|
|
|
|
{
|
2008-05-07 20:43:56 +02:00
|
|
|
nframes_t start; /* where on the timeline */
|
|
|
|
nframes_t offset; /* first sample from clip */
|
|
|
|
nframes_t length; /* total number of samples */
|
2008-05-12 18:23:55 +02:00
|
|
|
|
2008-05-17 07:14:26 +02:00
|
|
|
void
|
|
|
|
set_left ( nframes_t f )
|
|
|
|
{
|
|
|
|
offset += f - start;
|
|
|
|
length -= f - start;
|
|
|
|
start = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_right ( nframes_t f )
|
|
|
|
{
|
|
|
|
length = f - start;
|
|
|
|
}
|
|
|
|
|
2008-05-13 07:39:29 +02:00
|
|
|
Range ( ) : start( 0 ), offset( 0 ), length( 0 )
|
|
|
|
{
|
|
|
|
}
|
2008-05-12 18:23:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Used by time/tempo points or any other child of Sequence_Widget
|
2008-06-23 03:01:09 +02:00
|
|
|
which must be locked to a point in musical time rather than wallclock
|
|
|
|
time. Bar and beat start at 1. */
|
2008-05-12 18:23:55 +02:00
|
|
|
struct BBT
|
|
|
|
{
|
|
|
|
unsigned short bar;
|
|
|
|
unsigned char beat;
|
|
|
|
unsigned short tick;
|
2008-05-13 07:39:29 +02:00
|
|
|
|
|
|
|
BBT ( ) : bar( 0 ), beat( 0 ), tick( 0 )
|
|
|
|
{
|
|
|
|
}
|
2008-04-02 09:19:48 +02:00
|
|
|
};
|
|
|
|
|
2008-05-12 18:23:55 +02:00
|
|
|
|
2008-05-14 20:31:11 +02:00
|
|
|
/* FIXME: wrong place for this */
|
|
|
|
struct position_info
|
|
|
|
{
|
|
|
|
nframes_t frame;
|
|
|
|
|
|
|
|
float tempo;
|
|
|
|
int beats_per_bar;
|
|
|
|
int beat_type;
|
|
|
|
|
|
|
|
BBT bbt;
|
|
|
|
};
|
|
|
|
|
2008-06-23 03:01:09 +02:00
|
|
|
#define SEQUENCE_WIDGET_CLONE_FUNC(class) \
|
|
|
|
virtual Sequence_Widget *clone ( void ) const \
|
|
|
|
{ \
|
|
|
|
return new class ( *this ); \
|
|
|
|
}
|
|
|
|
|
2008-05-14 20:31:11 +02:00
|
|
|
|
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-05-18 07:09:18 +02:00
|
|
|
static std::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-05-01 07:26:57 +02:00
|
|
|
|
|
|
|
static Fl_Color _selection_color;
|
|
|
|
|
2008-04-13 00:55:25 +02:00
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
protected:
|
2012-10-24 07:44:19 +02:00
|
|
|
|
|
|
|
char *_label;
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
Sequence *_sequence; /* track this region belongs to */
|
2012-12-11 06:47:44 +01:00
|
|
|
|
|
|
|
Range _range; /* always used by RT/osc threads */
|
|
|
|
Range _dragging_range; /* used when dragging */
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
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-05-07 20:43:56 +02:00
|
|
|
virtual void get ( Log_Entry &e ) const;
|
|
|
|
virtual void set ( Log_Entry &e );
|
2008-04-20 04:15:54 +02:00
|
|
|
|
2008-06-23 03:01:09 +02:00
|
|
|
Sequence_Widget ( const Sequence_Widget &rhs );
|
2008-05-28 08:13:23 +02:00
|
|
|
Sequence_Widget ( );
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
const Sequence_Widget &
|
2008-06-23 03:01:09 +02:00
|
|
|
operator= ( const Sequence_Widget &rhs );
|
2008-03-31 12:00:47 +02:00
|
|
|
|
2008-06-23 03:01:09 +02:00
|
|
|
public:
|
2008-04-13 00:55:25 +02:00
|
|
|
|
2012-11-01 11:35:04 +01:00
|
|
|
|
2008-06-23 03:01:09 +02:00
|
|
|
virtual ~Sequence_Widget ( );
|
2008-04-13 00:55:25 +02:00
|
|
|
|
2008-05-08 01:09:52 +02:00
|
|
|
virtual Sequence_Widget *clone ( void ) const = 0;
|
2008-03-31 12:00:47 +02:00
|
|
|
|
2008-06-23 03:01:09 +02:00
|
|
|
bool selected ( void ) const;
|
2010-01-12 09:53:00 +01:00
|
|
|
static int nselected ( void )
|
2008-12-28 07:27:43 +01:00
|
|
|
{ return _selection.size(); }
|
2008-06-23 03:01:09 +02:00
|
|
|
void select ( void );
|
|
|
|
void deselect ( void );
|
|
|
|
void remove ( void );
|
2008-02-27 21:04:17 +01:00
|
|
|
|
2008-06-23 03:01:09 +02:00
|
|
|
static void delete_selected ( void );
|
|
|
|
static void select_none ( void );
|
2008-04-29 23:16:09 +02:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
static Sequence_Widget *current ( void ) { return Sequence_Widget::_current; }
|
|
|
|
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-05-22 21:20:15 +02:00
|
|
|
void begin_drag ( const Drag &d );
|
|
|
|
void end_drag ( void );
|
2008-04-02 09:19:48 +02:00
|
|
|
|
2008-03-04 01:25:05 +01:00
|
|
|
int dispatch ( int m );
|
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
Fl_Widget * parent ( void ) const { return _sequence; }
|
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-05-07 18:42:31 +02:00
|
|
|
virtual int y ( void ) const { return _sequence->y(); }
|
|
|
|
virtual int h ( void ) const { return _sequence->h(); }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-03-08 01:57:55 +01:00
|
|
|
/* used by regions */
|
2012-06-13 05:53:21 +02:00
|
|
|
|
|
|
|
int get_x( nframes_t frame ) const
|
|
|
|
{
|
2012-12-11 06:47:44 +01:00
|
|
|
return frame < timeline->xoffset ?
|
|
|
|
_sequence->drawable_x() :
|
|
|
|
min( _sequence->drawable_x() + _sequence->drawable_w(), _sequence->drawable_x() + timeline->ts_to_x( frame - timeline->xoffset ) );
|
2012-06-13 05:53:21 +02:00
|
|
|
}
|
|
|
|
|
2008-04-27 07:11:00 +02:00
|
|
|
virtual int x ( void ) const
|
|
|
|
{
|
2012-06-13 05:53:21 +02:00
|
|
|
return get_x( _r->start );
|
2008-04-27 07:11:00 +02:00
|
|
|
}
|
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
|
|
|
|
{
|
2012-12-11 06:47:44 +01:00
|
|
|
return _r->start < timeline->xoffset ?
|
|
|
|
max( -32767, _sequence->drawable_x() - timeline->ts_to_x( timeline->xoffset - _r->start )) :
|
|
|
|
min( 32767, _sequence->drawable_x() + timeline->ts_to_x( _r->start - timeline->xoffset ) );
|
2008-03-08 01:57:55 +01:00
|
|
|
}
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
virtual int w ( void ) const
|
|
|
|
{
|
2013-09-24 08:33:24 +02:00
|
|
|
// int tx = timeline->ts_to_x( _r->start );
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
int rw;
|
2013-09-24 08:33:24 +02:00
|
|
|
|
|
|
|
if ( _r->start < timeline->xoffset )
|
|
|
|
{
|
|
|
|
if ( _r->start + _r->length < timeline->xoffset )
|
|
|
|
rw = 0;
|
|
|
|
else
|
|
|
|
rw = timeline->ts_to_x( ( _r->start + _r->length ) - timeline->xoffset );
|
|
|
|
}
|
2008-02-21 11:01:25 +01:00
|
|
|
else
|
|
|
|
rw = abs_w();
|
|
|
|
|
2012-12-11 06:47:44 +01:00
|
|
|
return min( rw, _sequence->drawable_w() );
|
2008-02-21 11:01:25 +01:00
|
|
|
}
|
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
int abs_x ( void ) const { return timeline->ts_to_x( _r->start ); }
|
|
|
|
virtual int abs_w ( void ) const { return timeline->ts_to_x( _r->length ); }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-05-01 07:26:57 +02:00
|
|
|
Fl_Color color ( void ) const { return _color; }
|
2008-03-09 19:28:48 +01:00
|
|
|
void color ( Fl_Color v ) { _color = v; }
|
2012-10-24 07:44:19 +02:00
|
|
|
virtual Fl_Color box_color ( void ) const { return _box_color; }
|
|
|
|
virtual void box_color ( Fl_Color v ) { _box_color = v; }
|
2008-05-01 07:26:57 +02:00
|
|
|
virtual Fl_Color selection_color ( void ) const { return _selection_color; }
|
|
|
|
virtual void selection_color ( Fl_Color v ) { _selection_color = v; }
|
2012-11-01 11:35:04 +01:00
|
|
|
virtual Fl_Color actual_box_color ( void ) const { return box_color(); }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
Sequence * sequence ( void ) const { return _sequence; }
|
2008-05-07 18:54:41 +02:00
|
|
|
void sequence ( Sequence *t ) { _sequence = t; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
nframes_t start ( void ) const { return _r->start; }
|
2008-05-19 04:40:42 +02:00
|
|
|
|
|
|
|
/* void start ( nframes_t o ) { _r->start = o; } */
|
|
|
|
|
|
|
|
void start ( nframes_t where );
|
2008-05-07 20:43:56 +02:00
|
|
|
void length ( nframes_t v ) { _r->length = v; }
|
|
|
|
virtual nframes_t length ( void ) const { return _r->length; }
|
|
|
|
void offset ( nframes_t v ) { _r->offset = v; }
|
|
|
|
nframes_t offset ( void ) const { return _r->offset; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2012-10-24 07:44:19 +02:00
|
|
|
void set_left ( nframes_t v ) { _r->set_left( v ); }
|
|
|
|
void set_right ( nframes_t v ) { _r->set_right( v ); }
|
|
|
|
|
|
|
|
const char *label ( void ) const { return _label; }
|
|
|
|
void label ( const char *s )
|
|
|
|
{
|
|
|
|
if ( _label )
|
|
|
|
free( _label );
|
|
|
|
|
|
|
|
_label = NULL;
|
|
|
|
|
|
|
|
if ( s )
|
|
|
|
_label = strdup( s );
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
/** convert a screen x coord into an start into the region */
|
2008-04-26 13:58:50 +02:00
|
|
|
nframes_t x_to_offset ( int X )
|
|
|
|
{
|
2012-12-11 06:47:44 +01:00
|
|
|
return timeline->x_to_ts( scroll_x() + ( X - _sequence->drawable_x() ) ) - _r->start;
|
2008-04-26 13:58:50 +02:00
|
|
|
}
|
2008-04-25 08:58:08 +02:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
int active_r ( void ) const { return _sequence->active_r(); }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-05-29 18:38:06 +02:00
|
|
|
/** returns true if widget /w/ begins and ends completely within the range of this widget */
|
|
|
|
bool contains ( const Sequence_Widget *w ) const
|
|
|
|
{
|
|
|
|
return w->start() >= start() && w->start() + w->length() <= start() + length();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** returns true of widget /w/ overlaps this widget in any place */
|
|
|
|
bool overlaps ( const Sequence_Widget *w ) const
|
|
|
|
{
|
|
|
|
return ! ( w->start() > start() + length() || w->start() + w->length() < 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 )
|
|
|
|
{
|
2012-06-07 08:49:18 +02:00
|
|
|
if ( ! _sequence )
|
|
|
|
return;
|
|
|
|
|
2008-02-22 09:51:22 +01:00
|
|
|
if ( ! (align() & FL_ALIGN_INSIDE) )
|
|
|
|
{
|
2012-12-11 06:47:44 +01:00
|
|
|
// FIXME: do better..
|
|
|
|
_sequence->damage( FL_DAMAGE_USER1 );
|
2008-02-22 09:51:22 +01:00
|
|
|
}
|
|
|
|
else
|
2012-12-11 06:47:44 +01:00
|
|
|
_sequence->damage( FL_DAMAGE_USER1, x(), y(), w(), h() );
|
2008-02-21 19:31:15 +01:00
|
|
|
}
|
2008-02-21 11:01:25 +01:00
|
|
|
|
2008-05-18 07:09:18 +02:00
|
|
|
virtual void draw_box ( void );
|
|
|
|
virtual void draw ( void );
|
2012-06-07 09:29:54 +02:00
|
|
|
virtual void draw_label ( void );
|
2012-11-06 08:50:28 +01:00
|
|
|
virtual void draw_label ( const char *label, Fl_Align align, Fl_Color color=(Fl_Color)0, int xo=0, int yo=0 );
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
bool
|
2008-05-15 00:36:23 +02:00
|
|
|
operator< ( const Sequence_Widget & rhs ) const
|
2008-02-21 11:01:25 +01:00
|
|
|
{
|
2008-05-07 20:43:56 +02:00
|
|
|
return _r->start < rhs._r->start;
|
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-05-15 00:36:23 +02:00
|
|
|
operator<=( const Sequence_Widget & rhs ) const
|
2008-03-10 02:07:04 +01:00
|
|
|
{
|
2008-05-07 20:43:56 +02:00
|
|
|
return _r->start <= rhs._r->start;
|
2008-03-10 02:07:04 +01:00
|
|
|
}
|
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
virtual int handle ( int m );
|
|
|
|
|
2008-03-05 20:38:25 +01:00
|
|
|
static bool
|
2008-05-15 00:36:23 +02:00
|
|
|
sort_func ( const Sequence_Widget *lhs, const Sequence_Widget *rhs )
|
2008-03-05 20:38:25 +01:00
|
|
|
{
|
|
|
|
return *lhs < *rhs;
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
};
|