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
|
|
|
|
|
|
|
|
#include "Track.H"
|
2008-02-22 11:22:22 +01:00
|
|
|
#include "Loggable.H"
|
2008-03-03 22:00:38 +01:00
|
|
|
#include "Audio_File.H"
|
|
|
|
#include "Timeline.H"
|
|
|
|
#include <list>
|
2008-02-21 11:39:13 +01:00
|
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
struct Drag
|
|
|
|
{
|
|
|
|
/* mouse coords at start of drag */
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
Drag( int X, int Y ) : x( X ), y( Y ) { state = 0; }
|
|
|
|
};
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
/* Base class for virtual widget on a track */
|
2008-02-22 11:22:22 +01:00
|
|
|
class Track_Widget : public Loggable
|
2008-02-21 11:01:25 +01:00
|
|
|
{
|
|
|
|
|
2008-03-04 01:25:05 +01:00
|
|
|
static list <Track_Widget *> _selection; /* all the widgets making up the selection */
|
|
|
|
static Track_Widget * _current; /* the widget initiating events that affect the selection */
|
2008-03-03 22:00:38 +01:00
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
Track *_track; /* track this region belongs to */
|
|
|
|
|
|
|
|
nframes_t _offset; /* where on the timeline */
|
|
|
|
nframes_t _start; /* first sample from clip */
|
|
|
|
nframes_t _end; /* last sample from clip */
|
|
|
|
|
|
|
|
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-02-21 11:01:25 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
Track_Widget ( )
|
|
|
|
{
|
|
|
|
_track = NULL;
|
|
|
|
|
|
|
|
_offset = _start = _end = 0;
|
2008-03-04 01:25:05 +01:00
|
|
|
|
|
|
|
_drag = NULL;
|
2008-02-21 11:01:25 +01:00
|
|
|
}
|
|
|
|
|
2008-02-27 21:04:17 +01:00
|
|
|
virtual ~Track_Widget ( )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool selected ( void )
|
|
|
|
{
|
|
|
|
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-03-04 01:25:05 +01:00
|
|
|
static Track_Widget *current ( void ) { return _current; }
|
|
|
|
|
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();
|
|
|
|
_offset = where;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
long d = where - _offset;
|
|
|
|
|
|
|
|
for ( list <Track_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
|
|
|
|
{
|
|
|
|
(*i)->redraw();
|
|
|
|
|
|
|
|
if ( d < 0 )
|
|
|
|
(*i)->_offset -= 0 - d;
|
|
|
|
else
|
|
|
|
(*i)->_offset += d;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
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-02-21 11:01:25 +01:00
|
|
|
Fl_Group * parent ( void ) const { return _track; }
|
|
|
|
|
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 */
|
|
|
|
virtual int x ( void ) const { return _offset < timeline->xoffset ? _track->x() - 1 : min( 32767, _track->x() + timeline->ts_to_x( _offset - timeline->xoffset ) ); }
|
|
|
|
|
|
|
|
/* use this as x() when you need to draw lines between widgets */
|
|
|
|
int line_x ( void ) const
|
|
|
|
{
|
|
|
|
return _offset < timeline->xoffset ? max( -32768, _track->x() - timeline->ts_to_x( timeline->xoffset - _offset )) : min( 32767, _track->x() + timeline->ts_to_x( _offset - timeline->xoffset ) );
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
virtual int w ( void ) const
|
|
|
|
{
|
2008-02-21 17:20:36 +01:00
|
|
|
int tx = timeline->ts_to_x( _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-02-22 20:56:07 +01:00
|
|
|
int abs_x ( void ) const { return timeline->ts_to_x( _offset ); }
|
2008-02-21 17:20:36 +01:00
|
|
|
virtual int abs_w ( void ) const { return timeline->ts_to_x( _end - _start ); }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
Fl_Color color ( void ) { return _color; }
|
|
|
|
Fl_Color box_color ( void ) { return _box_color; }
|
|
|
|
|
|
|
|
Track * track ( void ) const { return _track; }
|
|
|
|
void track ( Track *t ) { _track = t; }
|
|
|
|
|
|
|
|
nframes_t offset ( void ) const { return _offset; }
|
2008-03-03 22:36:33 +01:00
|
|
|
// void offset ( nframes_t o ) { _offset = o; }
|
2008-02-21 11:01:25 +01:00
|
|
|
|
|
|
|
void end ( nframes_t v ) { _end = v; }
|
|
|
|
nframes_t end ( void ) const { return _end; }
|
|
|
|
void start ( nframes_t v ) { _start = v; }
|
|
|
|
nframes_t start ( void ) const { return _start; }
|
|
|
|
|
|
|
|
virtual nframes_t length ( void ) const { return _end - _start; }
|
|
|
|
|
|
|
|
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
|
|
|
|
draw_box ( int X, int Y, int W, int H )
|
|
|
|
{
|
2008-03-08 01:57:55 +01:00
|
|
|
if ( x() > X + W || x() + w() < X )
|
|
|
|
return;
|
|
|
|
|
2008-02-21 11:45:50 +01:00
|
|
|
fl_draw_box( box(), x(), y(), w(), h(), _box_color );
|
2008-02-21 11:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
draw ( int X, int Y, int W, int H )
|
|
|
|
{
|
2008-03-08 01:57:55 +01:00
|
|
|
if ( x() > X + W || x() + w() < X )
|
|
|
|
return;
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
draw_box( X, Y, W, H );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator< ( const Track_Widget & rhs )
|
|
|
|
{
|
|
|
|
return _offset < rhs._offset;
|
|
|
|
}
|
2008-03-03 22:00:38 +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
|
|
|
|
sort_func ( Track_Widget *lhs, Track_Widget *rhs )
|
|
|
|
{
|
|
|
|
return *lhs < *rhs;
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:01:25 +01:00
|
|
|
};
|