@@ -44,7 +44,7 @@ protected: | |||
int i = 0; | |||
asprintf( &sa[i++], ":x %lu", _offset ); | |||
asprintf( &sa[i++], ":x %lu", _r->offset ); | |||
asprintf( &sa[i++], ":y %.2f", _y ); | |||
asprintf( &sa[i++], ":track 0x%X", _track ? _track->id() : 0 ); | |||
@@ -65,7 +65,7 @@ protected: | |||
char *v = s + strlen( s ) + 1; | |||
if ( ! strcmp( s, ":x" ) ) | |||
_offset = atol( v ); | |||
_r->offset = atol( v ); | |||
else | |||
if ( ! strcmp( s, ":y" ) ) | |||
_y = atof( v ); | |||
@@ -117,7 +117,7 @@ public: | |||
{ | |||
_track = t; | |||
_y = y; | |||
_offset = when; | |||
_r->offset = when; | |||
// _make_label(); | |||
@@ -126,7 +126,7 @@ public: | |||
Control_Point ( const Control_Point &rhs ) | |||
{ | |||
_offset = rhs._offset; | |||
_r->offset = rhs._r->offset; | |||
_y = rhs._y; | |||
} | |||
@@ -81,9 +81,9 @@ Region::init ( void ) | |||
{ | |||
_track = NULL; | |||
_offset = 0; | |||
_start = 0; | |||
_end = 0; | |||
_r->offset = 0; | |||
_r->start = 0; | |||
_r->end = 0; | |||
_scale = 1.0f; | |||
_clip = NULL; | |||
@@ -94,12 +94,12 @@ Region::init ( void ) | |||
/* copy constructor */ | |||
Region::Region ( const Region & rhs ) | |||
{ | |||
_offset = rhs._offset; | |||
_r->offset = rhs._r->offset; | |||
_track = rhs._track; | |||
// _track = NULL; | |||
_clip = rhs._clip; | |||
_start = rhs._start; | |||
_end = rhs._end; | |||
_r->start = rhs._r->start; | |||
_r->end = rhs._r->end; | |||
_scale = rhs._scale; | |||
_box_color = rhs._box_color; | |||
_color = rhs._color; | |||
@@ -118,7 +118,7 @@ Region::Region ( Audio_File *c ) | |||
{ | |||
init(); | |||
_clip = c; | |||
_end = _clip->length(); | |||
_r->end = _clip->length(); | |||
log_create(); | |||
} | |||
@@ -129,9 +129,9 @@ Region::Region ( Audio_File *c, Track *t, nframes_t o ) | |||
{ | |||
init(); | |||
_clip = c; | |||
_end = _clip->length(); | |||
_r->end = _clip->length(); | |||
_track = t; | |||
_offset = o; | |||
_r->offset = o; | |||
_track->add( this ); | |||
@@ -175,14 +175,14 @@ Region::trim ( enum trim_e t, int X ) | |||
long td = timeline->x_to_ts( d ); | |||
if ( td < 0 && _start < 0 - td ) | |||
td = 0 - _start; | |||
if ( td < 0 && _r->start < 0 - td ) | |||
td = 0 - _r->start; | |||
if ( _start + td >= _end ) | |||
td = (_end - _start) - timeline->x_to_ts( 1 ); | |||
if ( _r->start + td >= _r->end ) | |||
td = (_r->end - _r->start) - timeline->x_to_ts( 1 ); | |||
_start += td; | |||
_offset += td; | |||
_r->start += td; | |||
_r->offset += td; | |||
break; | |||
} | |||
case RIGHT: | |||
@@ -193,12 +193,12 @@ Region::trim ( enum trim_e t, int X ) | |||
long td = timeline->x_to_ts( d ); | |||
// printf( "%li %li\n", td, _end - _start ); | |||
// printf( "%li %li\n", td, _r->end - _r->start ); | |||
if ( td >= 0 && _end - _start < td ) | |||
_end = _start + timeline->x_to_ts( 1 ); | |||
if ( td >= 0 && _r->end - _r->start < td ) | |||
_r->end = _r->start + timeline->x_to_ts( 1 ); | |||
else | |||
_end -= td; | |||
_r->end -= td; | |||
break; | |||
} | |||
@@ -224,7 +224,7 @@ Region::handle ( int m ) | |||
int ret; | |||
Logger _log( this ); | |||
//log_start(); | |||
//log_r->start(); | |||
switch ( m ) | |||
{ | |||
@@ -246,12 +246,12 @@ Region::handle ( int m ) | |||
{ | |||
case 1: | |||
trim( trimming = LEFT, X ); | |||
_drag = new Drag( x() - X, y() - Y ); | |||
begin_drag( Drag( x() - X, y() - Y ) ); | |||
_log.hold(); | |||
break; | |||
case 3: | |||
trim( trimming = RIGHT, X ); | |||
_drag = new Drag( x() - X, y() - Y ); | |||
begin_drag( Drag( x() - X, y() - Y ) ); | |||
_log.hold(); | |||
break; | |||
case 2: | |||
@@ -287,7 +287,7 @@ Region::handle ( int m ) | |||
ox = x() - X; | |||
oy = y() - Y; | |||
/* for panning */ | |||
os = _start; | |||
os = _r->start; | |||
/* normalization and selection */ | |||
if ( Fl::event_button2() ) | |||
@@ -333,7 +333,7 @@ Region::handle ( int m ) | |||
if ( ! _drag ) | |||
{ | |||
_drag = new Drag( x() - X, y() - Y ); | |||
begin_drag( Drag( x() - X, y() - Y ) ); | |||
_log.hold(); | |||
} | |||
@@ -344,14 +344,14 @@ Region::handle ( int m ) | |||
int d = (ox + X) - x(); | |||
long td = timeline->x_to_ts( d ); | |||
nframes_t W = _end - _start; | |||
nframes_t W = _r->end - _r->start; | |||
if ( td > 0 && os < td ) | |||
_start = 0; | |||
_r->start = 0; | |||
else | |||
_start = os - td; | |||
_r->start = os - td; | |||
_end = _start + W; | |||
_r->end = _r->start + W; | |||
_track->redraw(); | |||
return 1; | |||
@@ -439,15 +439,15 @@ Region::draw ( int X, int Y, int W, int H ) | |||
return; | |||
int OX = scroll_x(); | |||
int ox = timeline->ts_to_x( _offset ); | |||
int ox = timeline->ts_to_x( _r->offset ); | |||
if ( ox > OX + _track->w() || | |||
ox < OX && ox + abs_w() < OX ) | |||
return; | |||
int rw = timeline->ts_to_x( _end - _start ); | |||
int rw = timeline->ts_to_x( _r->end - _r->start ); | |||
nframes_t end = _offset + ( _end - _start ); | |||
nframes_t end = _r->offset + ( _r->end - _r->start ); | |||
/* calculate waveform offset due to scrolling */ | |||
nframes_t offset = 0; | |||
@@ -455,7 +455,7 @@ Region::draw ( int X, int Y, int W, int H ) | |||
{ | |||
offset = timeline->x_to_ts( OX - ox ); | |||
rw = timeline->ts_to_x( (_end - _start) - offset ); | |||
rw = timeline->ts_to_x( (_r->end - _r->start) - offset ); | |||
} | |||
rw = min( rw, _track->w() ); | |||
@@ -469,7 +469,7 @@ Region::draw ( int X, int Y, int W, int H ) | |||
int peaks; | |||
Peak *pbuf; | |||
const nframes_t start = _start + offset + timeline->x_to_ts( X - rx ); | |||
const nframes_t start = _r->start + offset + timeline->x_to_ts( X - rx ); | |||
_clip->read_peaks( timeline->fpp(), | |||
start, | |||
start + timeline->x_to_ts( W ), | |||
@@ -500,7 +500,7 @@ Region::draw ( int X, int Y, int W, int H ) | |||
/* for ( int i = _clip->channels(); i--; ) */ | |||
/* Waveform::draw( rx, X, (y() + Fl::box_dy( box() )) + (i * ch), W, */ | |||
/* ch, _clip, i, timeline->fpp(), */ | |||
/* _start + offset, min( (_end - _start) - offset, _end), */ | |||
/* _r->start + offset, min( (_r->end - _r->start) - offset, _r->end), */ | |||
/* _scale, selected() ? fl_invert_color( _color ) : _color ); */ | |||
@@ -531,9 +531,9 @@ Region::draw ( int X, int Y, int W, int H ) | |||
void | |||
Region::normalize ( void ) | |||
{ | |||
printf( "normalize: start=%lu end=%lu\n", _start, _end ); | |||
printf( "normalize: start=%lu end=%lu\n", _r->start, _r->end ); | |||
/* FIXME: figure out a way to do this via the peak server */ | |||
/* _scale = _clip->peaks( 0 )->normalization_factor( timeline->fpp(), _start, _end ); */ | |||
/* _scale = _clip->peaks( 0 )->normalization_factor( timeline->fpp(), _r->start, _r->end ); */ | |||
} |
@@ -55,9 +55,9 @@ protected: | |||
asprintf( &sa[ i++ ], ":source \"%s\"", _clip ? _clip->name() : "" ); | |||
asprintf( &sa[ i++ ], ":track 0x%X", _track ? _track->id() : 0 ); | |||
asprintf( &sa[ i++ ], ":x %lu", _offset ); | |||
asprintf( &sa[ i++ ], ":l %lu", _start ); | |||
asprintf( &sa[ i++ ], ":r %lu", _end ); | |||
asprintf( &sa[ i++ ], ":x %lu", _r->offset ); | |||
asprintf( &sa[ i++ ], ":l %lu", _r->start ); | |||
asprintf( &sa[ i++ ], ":r %lu", _r->end ); | |||
asprintf( &sa[ i++ ], ":selected %d", selected() ); | |||
asprintf( &sa[ i++ ], ":gain %f", _scale ); | |||
@@ -84,11 +84,11 @@ protected: | |||
} | |||
if ( ! strcmp( s, ":x" ) ) | |||
_offset = atol( v ); | |||
_r->offset = atol( v ); | |||
else if ( ! strcmp( s, ":l" ) ) | |||
_start = atol( v ); | |||
_r->start = atol( v ); | |||
else if ( ! strcmp( s, ":r" ) ) | |||
_end = atol( v ); | |||
_r->end = atol( v ); | |||
else if ( ! strcmp( s, ":selected" ) ) | |||
{ | |||
if ( atoi( v ) ) | |||
@@ -131,7 +131,6 @@ public: | |||
Region_Base ( ) | |||
{ | |||
_start = _offset = _end = 0; | |||
_clip = NULL; | |||
_scale = 1.0f; | |||
} | |||
@@ -47,7 +47,7 @@ protected: | |||
int i = 0; | |||
asprintf( &sa[i++], ":track 0x%X", _track ? _track->id() : 0 ); | |||
asprintf( &sa[i++], ":x %lu", _offset ); | |||
asprintf( &sa[i++], ":x %lu", _r->offset ); | |||
asprintf( &sa[i++], ":tempo %.2f", _tempo ); | |||
sa[i] = NULL; | |||
@@ -67,7 +67,7 @@ protected: | |||
char *v = s + strlen( s ) + 1; | |||
if ( ! strcmp( s, ":x" ) ) | |||
_offset = atol( v ); | |||
_r->offset = atol( v ); | |||
else | |||
if ( ! strcmp( s, ":tempo" ) ) | |||
_tempo = atof( v ); | |||
@@ -116,7 +116,7 @@ public: | |||
Tempo_Point ( nframes_t when, float bpm ) | |||
{ | |||
_tempo = bpm; | |||
_offset = when; | |||
_r->offset = when; | |||
_make_label(); | |||
@@ -125,7 +125,7 @@ public: | |||
Tempo_Point ( const Tempo_Point &rhs ) | |||
{ | |||
_offset = rhs._offset; | |||
_r->offset = rhs._r->offset; | |||
_tempo = rhs._tempo; | |||
} | |||
@@ -72,7 +72,7 @@ protected: | |||
int i = 0; | |||
asprintf( &sa[i++], ":track 0x%X", _track ? _track->id() : 0 ); | |||
asprintf( &sa[i++], ":x %lu", _offset ); | |||
asprintf( &sa[i++], ":x %lu", _r->offset ); | |||
asprintf( &sa[i++], ":beats_per_bar %d", _time.beats_per_bar ); | |||
asprintf( &sa[i++], ":beat_type %d", _time.beat_type ); | |||
@@ -93,7 +93,7 @@ protected: | |||
char *v = s + strlen( s ) + 1; | |||
if ( ! strcmp( s, ":x" ) ) | |||
_offset = atol( v ); | |||
_r->offset = atol( v ); | |||
else | |||
if ( ! strcmp( s, ":beats_per_bar" ) ) | |||
_time.beats_per_bar = atoi( v ); | |||
@@ -139,7 +139,7 @@ public: | |||
Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note ) | |||
{ | |||
_offset = when; | |||
_r->offset = when; | |||
_make_label(); | |||
log_create(); | |||
@@ -147,7 +147,7 @@ public: | |||
Time_Point ( const Time_Point &rhs ) | |||
{ | |||
_offset = rhs._offset; | |||
_r->offset = rhs._r->offset; | |||
_time = rhs._time; | |||
} | |||
@@ -374,20 +374,10 @@ Track::handle ( int m ) | |||
int retval = r->dispatch( m ); | |||
if ( retval && m == FL_PUSH ) | |||
{ | |||
Track_Widget::original( r ); | |||
Track_Widget::pushed( r->clone( r ) ); | |||
r->hide(); | |||
} | |||
Track_Widget::pushed( r ); | |||
if ( retval && m == FL_RELEASE ) | |||
{ | |||
*Track_Widget::original() = *Track_Widget::pushed(); | |||
delete Track_Widget::pushed(); | |||
Track_Widget::pushed( NULL ); | |||
Track_Widget::original( NULL ); | |||
} | |||
Loggable::block_start(); | |||
@@ -30,7 +30,6 @@ | |||
list <Track_Widget *> Track_Widget::_selection; | |||
Track_Widget * Track_Widget::_current = NULL; | |||
Track_Widget * Track_Widget::_pushed = NULL; | |||
Track_Widget * Track_Widget::_original = NULL; | |||
Track_Widget * Track_Widget::_belowmouse = NULL; | |||
void | |||
@@ -171,9 +170,8 @@ Track_Widget::handle ( int m ) | |||
case FL_RELEASE: | |||
if ( _drag ) | |||
{ | |||
end_drag(); | |||
_log.release(); | |||
delete _drag; | |||
_drag = NULL; | |||
} | |||
fl_cursor( FL_CURSOR_HAND ); | |||
@@ -184,8 +182,7 @@ Track_Widget::handle ( int m ) | |||
{ | |||
if ( ! _drag ) | |||
{ | |||
_drag = new Drag( x() - X, y() - Y ); | |||
begin_drag ( Drag( x() - X, y() - Y ) ); | |||
_log.hold(); | |||
} | |||
@@ -199,7 +196,7 @@ Track_Widget::handle ( int m ) | |||
{ | |||
int nx = (ox + X) - _track->x(); | |||
// _offset = timeline->x_to_ts( nx ) + timeline->xoffset; | |||
// _r->offset = timeline->x_to_ts( nx ) + timeline->xoffset; | |||
offset( timeline->x_to_ts( nx ) + timeline->xoffset ); | |||
if ( Track_Widget::_current == this ) | |||
@@ -26,6 +26,8 @@ | |||
#include <algorithm> | |||
using namespace std; | |||
class Track_Widget; | |||
struct Drag | |||
{ | |||
/* mouse coords at start of drag */ | |||
@@ -33,9 +35,18 @@ struct Drag | |||
int y; | |||
int state; | |||
Track_Widget *original; | |||
Drag( int X, int Y ) : x( X ), y( Y ) { state = 0; } | |||
}; | |||
struct Range | |||
{ | |||
nframes_t offset; /* where on the timeline */ | |||
nframes_t start; /* first sample from clip */ | |||
nframes_t end; /* last sample from clip */ | |||
}; | |||
/* Base class for virtual widget on a track */ | |||
class Track_Widget : public Loggable | |||
{ | |||
@@ -54,9 +65,8 @@ 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 */ | |||
Range _range; /* range for playback */ | |||
Range *_r; /* range for editing / display (points to the same thing as above, except for when dragging etc) */ | |||
Fl_Color _color; /* color of waveform */ | |||
Fl_Color _box_color; /* color of background (box) */ | |||
@@ -71,7 +81,9 @@ public: | |||
{ | |||
_track = NULL; | |||
_offset = _start = _end = 0; | |||
_r = &_range; | |||
_r->offset = _r->start = _r->end = 0; | |||
_shown = true; | |||
@@ -90,7 +102,7 @@ public: | |||
Track_Widget ( const Track_Widget &rhs ) | |||
{ | |||
_offset = rhs._offset; | |||
*_r = *rhs._r; | |||
_track = rhs._track; | |||
} | |||
@@ -129,11 +141,9 @@ public: | |||
static Track_Widget *current ( void ) { return Track_Widget::_current; } | |||
static Track_Widget *pushed ( void ) { return Track_Widget::_pushed; } | |||
static Track_Widget *original ( void ) { return Track_Widget::_original; } | |||
static Track_Widget *belowmouse ( void ) { return Track_Widget::_belowmouse; } | |||
static void pushed ( Track_Widget *w ) { Track_Widget::_pushed = w; } | |||
static void original ( Track_Widget *w ) { Track_Widget::_original = w; } | |||
static void belowmouse ( Track_Widget *w ) { Track_Widget::_belowmouse = w; } | |||
// static void pushed ( Track_Widget *w ) { Track_Widget::_pushed = w; } | |||
@@ -142,6 +152,22 @@ public: | |||
void show ( void ) { _shown = true; } | |||
void hide ( void ) { _shown = false; } | |||
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; | |||
} | |||
void | |||
offset ( nframes_t where ) | |||
{ | |||
@@ -149,20 +175,20 @@ public: | |||
if ( ! selected() ) | |||
{ | |||
redraw(); | |||
_offset = where; | |||
_r->offset = where; | |||
} | |||
else | |||
{ | |||
long d = where - _offset; | |||
long d = where - _r->offset; | |||
for ( list <Track_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ ) | |||
{ | |||
(*i)->redraw(); | |||
if ( d < 0 ) | |||
(*i)->_offset -= 0 - d; | |||
(*i)->_r->offset -= 0 - d; | |||
else | |||
(*i)->_offset += d; | |||
(*i)->_r->offset += d; | |||
} | |||
} | |||
@@ -180,17 +206,17 @@ public: | |||
virtual int h ( void ) const { return _track->h(); } | |||
/* 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 ) ); } | |||
virtual int x ( void ) const { return _r->offset < timeline->xoffset ? _track->x() - 1 : min( 32767, _track->x() + timeline->ts_to_x( _r->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 ) ); | |||
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 ) ); | |||
} | |||
virtual int w ( void ) const | |||
{ | |||
int tx = timeline->ts_to_x( _offset ); | |||
int tx = timeline->ts_to_x( _r->offset ); | |||
int rw; | |||
if ( tx < scroll_x() ) | |||
@@ -201,8 +227,8 @@ public: | |||
return min( rw, _track->w() ); | |||
} | |||
int abs_x ( void ) const { return timeline->ts_to_x( _offset ); } | |||
virtual int abs_w ( void ) const { return timeline->ts_to_x( _end - _start ); } | |||
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 ); } | |||
Fl_Color color ( void ) { return _color; } | |||
void color ( Fl_Color v ) { _color = v; } | |||
@@ -211,15 +237,15 @@ public: | |||
Track * track ( void ) const { return _track; } | |||
void track ( Track *t ) { _track = t; } | |||
nframes_t offset ( void ) const { return _offset; } | |||
// void offset ( nframes_t o ) { _offset = o; } | |||
nframes_t offset ( void ) const { return _r->offset; } | |||
// void offset ( nframes_t o ) { _r->offset = o; } | |||
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; } | |||
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; } | |||
virtual nframes_t length ( void ) const { return _end - _start; } | |||
virtual nframes_t length ( void ) const { return _r->end - _r->start; } | |||
virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; } | |||
virtual Fl_Align align ( void ) const { return (Fl_Align)0; } | |||
@@ -258,13 +284,13 @@ public: | |||
bool | |||
operator< ( const Track_Widget & rhs ) | |||
{ | |||
return _offset < rhs._offset; | |||
return _r->offset < rhs._r->offset; | |||
} | |||
bool | |||
operator<=( const Track_Widget & rhs ) | |||
{ | |||
return _offset <= rhs._offset; | |||
return _r->offset <= rhs._r->offset; | |||
} | |||
virtual void draw_label ( const char *label, Fl_Align align, Fl_Color color=(Fl_Color)0 ); | |||
@@ -50,7 +50,7 @@ Waveform::draw ( int X, int Y, int W, int H, | |||
int j; | |||
// int start = timeline->ts_to_x( _start ) + (X - ox); | |||
// int start = timeline->ts_to_x( _r->start ) + (X - ox); | |||
int start = 0; | |||