2008-02-14 08:40:47 +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-02-16 04:50:16 +01:00
|
|
|
#include "Track.H"
|
2008-02-14 08:40:47 +01:00
|
|
|
#include "Region.H"
|
2008-02-16 08:21:15 +01:00
|
|
|
#include "Timeline.H"
|
2008-02-20 06:57:14 +01:00
|
|
|
#include "Waveform.H"
|
2008-02-14 08:40:47 +01:00
|
|
|
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Group.H>
|
2008-02-16 04:50:16 +01:00
|
|
|
#include <FL/Fl_Widget.H>
|
2008-02-20 06:57:14 +01:00
|
|
|
#include <FL/Fl_Box.H>
|
2008-02-16 04:50:16 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
#include <algorithm>
|
|
|
|
//using std::algorithm;
|
|
|
|
using namespace std;
|
2008-02-16 08:21:15 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
extern Timeline timeline;
|
2008-02-17 00:12:23 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
Region::init ( void )
|
2008-02-14 08:40:47 +01:00
|
|
|
{
|
2008-02-20 06:57:14 +01:00
|
|
|
|
|
|
|
/* align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP ); */
|
|
|
|
/* labeltype( FL_SHADOW_LABEL ); */
|
|
|
|
/* labelcolor( FL_WHITE ); */
|
|
|
|
/* box( FL_PLASTIC_UP_BOX ); */
|
2008-02-16 04:50:16 +01:00
|
|
|
|
|
|
|
_track = NULL;
|
2008-02-20 06:57:14 +01:00
|
|
|
_offset = 0;
|
|
|
|
_start = 0;
|
|
|
|
_end = 0;
|
|
|
|
_scale = 1.0f;
|
|
|
|
_clip = NULL;
|
2008-02-20 08:53:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
_box_color = FL_CYAN;
|
|
|
|
_color = FL_BLUE;
|
2008-02-14 08:40:47 +01:00
|
|
|
}
|
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
Region::Region ( const Region & rhs )
|
2008-02-16 08:46:43 +01:00
|
|
|
{
|
2008-02-17 10:00:38 +01:00
|
|
|
_offset = rhs._offset;
|
2008-02-20 06:57:14 +01:00
|
|
|
_track = rhs._track;
|
|
|
|
_clip = rhs._clip;
|
|
|
|
_start = rhs._start;
|
|
|
|
_end = rhs._end;
|
|
|
|
_scale = rhs._scale;
|
2008-02-16 08:46:43 +01:00
|
|
|
}
|
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
Region::Region ( Clip *c )
|
2008-02-17 00:12:23 +01:00
|
|
|
{
|
|
|
|
init();
|
2008-02-20 06:57:14 +01:00
|
|
|
_clip = c;
|
|
|
|
_end = _clip->length();
|
2008-02-17 00:12:23 +01:00
|
|
|
}
|
|
|
|
|
2008-02-18 02:13:20 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
void
|
|
|
|
Region::trim ( enum trim_e t, int X )
|
|
|
|
{
|
|
|
|
switch ( t )
|
|
|
|
{
|
|
|
|
case LEFT:
|
|
|
|
{
|
|
|
|
int d = X - x();
|
2008-02-17 01:35:53 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
long td = timeline.x_to_ts( d );
|
2008-02-18 02:13:20 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
if ( td < 0 && _start < 0 - td )
|
|
|
|
td = 0 - _start;
|
2008-02-18 08:15:12 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
_start += td;
|
2008-02-18 08:15:12 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
_offset += td;
|
2008-02-18 02:13:20 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
// resize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RIGHT:
|
|
|
|
{
|
|
|
|
int d = (x() + w()) - X;
|
|
|
|
long td = timeline.x_to_ts( d );
|
2008-02-18 02:13:20 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
_end -= td;
|
2008-02-16 05:23:58 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
// resize();
|
2008-02-16 05:23:58 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return;
|
2008-02-16 05:23:58 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
}
|
2008-02-16 05:23:58 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
_track->redraw();
|
|
|
|
// redraw();
|
|
|
|
// parent()->redraw();
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
|
|
|
int
|
2008-02-20 07:35:29 +01:00
|
|
|
Region::handle ( int m )
|
|
|
|
{
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
static int ox, oy;
|
|
|
|
static enum trim_e trimming;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
static bool copied = false;
|
|
|
|
static nframes_t os;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
int X = Fl::event_x();
|
|
|
|
int Y = Fl::event_y();
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
case FL_PUSH:
|
|
|
|
{
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
if ( Fl::event_state() & FL_SHIFT &&
|
|
|
|
! ( Fl::event_state() & FL_CTRL ))
|
|
|
|
{
|
|
|
|
switch ( Fl::event_button() )
|
|
|
|
{
|
2008-02-20 08:08:36 +01:00
|
|
|
case 1:
|
|
|
|
trim( trimming = LEFT, X );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
trim( trimming = RIGHT, X );
|
|
|
|
break;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
}
|
|
|
|
fl_cursor( FL_CURSOR_WE );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ox = x() - X;
|
|
|
|
oy = y() - Y;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
if ( Fl::event_state() && FL_CTRL )
|
|
|
|
{
|
|
|
|
os = _start;
|
|
|
|
// Fl::local_grab( this );
|
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
/* if ( Fl::event_button() == 2 ) */
|
|
|
|
/* normalize(); */
|
2008-02-20 06:57:14 +01:00
|
|
|
|
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FL_RELEASE:
|
|
|
|
fl_cursor( FL_CURSOR_DEFAULT );
|
|
|
|
copied = false;
|
|
|
|
trimming = NO;
|
|
|
|
// Fl::release();
|
|
|
|
return 1;
|
|
|
|
case FL_DRAG:
|
|
|
|
|
|
|
|
if ( Fl::event_state() & FL_SHIFT &&
|
|
|
|
Fl::event_state() & FL_CTRL )
|
|
|
|
{
|
|
|
|
int d = (ox + X) - x();
|
|
|
|
long td = timeline.x_to_ts( d );
|
|
|
|
|
|
|
|
if ( td > 0 && os < td )
|
|
|
|
_start = 0;
|
|
|
|
else
|
|
|
|
_start = os - td;
|
|
|
|
|
|
|
|
// redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 08:08:36 +01:00
|
|
|
if ( Fl::event_state() & FL_SHIFT )
|
|
|
|
if ( trimming )
|
|
|
|
{
|
|
|
|
trim( trimming, X );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
if ( Fl::event_state() & FL_CTRL )
|
|
|
|
{
|
|
|
|
if ( ! copied )
|
|
|
|
{
|
|
|
|
_track->add( new Region( *this ) );
|
|
|
|
copied = true;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
if ( ox + X >= _track->x() )
|
|
|
|
{
|
|
|
|
int nx = ox + X;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
// nx = _track->snap( this, nx );
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
// _offset = timeline.x_to_ts( nx );
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
// position( nx, y() );
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
_offset = timeline.x_to_ts( nx ) + timeline.xoffset;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 08:24:56 +01:00
|
|
|
_track->snap( this );
|
2008-02-20 07:35:29 +01:00
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
if ( Y > y() + h() )
|
|
|
|
{
|
|
|
|
if ( _track->next() )
|
|
|
|
_track->next()->add( this );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( Y < y() )
|
|
|
|
{
|
|
|
|
if ( _track->prev() )
|
|
|
|
_track->prev()->add( this );
|
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
_track->redraw();
|
|
|
|
|
|
|
|
fl_cursor( FL_CURSOR_MOVE );
|
2008-02-20 06:57:14 +01:00
|
|
|
|
|
|
|
/* if ( X >= timeline.scroll->x() + timeline.scroll->w() || */
|
|
|
|
/* X <= timeline.scroll->x() ) */
|
|
|
|
/* { */
|
|
|
|
/* /\* this drag needs to scroll *\/ */
|
|
|
|
|
|
|
|
/* long pos = timeline.scroll->xposition(); */
|
|
|
|
|
|
|
|
/* if ( X <= timeline.scroll->x() ) */
|
|
|
|
/* pos -= 100; */
|
|
|
|
/* else */
|
|
|
|
/* pos += 100; */
|
|
|
|
|
|
|
|
/* if ( pos < 0 ) */
|
|
|
|
/* pos = 0; */
|
|
|
|
|
|
|
|
/* timeline.scroll->position( pos, timeline.scroll->yposition() ); */
|
|
|
|
/* } */
|
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
// _offset = timeline.x_to_ts( x() );
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-14 08:40:47 +01:00
|
|
|
|
|
|
|
|
2008-02-17 10:00:38 +01:00
|
|
|
/** must be called whenever zoom is adjusted */
|
|
|
|
void
|
|
|
|
Region::resize ( void )
|
|
|
|
{
|
|
|
|
int X = timeline.ts_to_x( _offset );
|
2008-02-19 07:22:42 +01:00
|
|
|
|
|
|
|
assert( _end >= _start );
|
|
|
|
|
2008-02-17 10:00:38 +01:00
|
|
|
int W = timeline.ts_to_x( _end - _start );
|
|
|
|
|
2008-02-19 07:22:42 +01:00
|
|
|
printf( "%dx%d\n", X, W );
|
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
// if ( W )
|
|
|
|
// Fl_Widget::resize( X, y(), W, h() );
|
2008-02-17 10:00:38 +01:00
|
|
|
}
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
|
|
|
|
/* X is the timeline offset, W is the width of the track */
|
2008-02-14 08:40:47 +01:00
|
|
|
void
|
2008-02-20 06:57:14 +01:00
|
|
|
Region::draw ( int X, int Y, int W, int H )
|
2008-02-14 08:40:47 +01:00
|
|
|
{
|
2008-02-20 11:45:10 +01:00
|
|
|
if ( ! ( W > 0 && H > 0 ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( _offset > timeline.xoffset + timeline.x_to_ts( _track->w() ) ||
|
|
|
|
( _offset < timeline.xoffset &&
|
|
|
|
_offset + (_end - _start) < timeline.xoffset ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int rw = timeline.ts_to_x( _end - _start );
|
|
|
|
|
|
|
|
nframes_t end = _offset + ( _end - _start );
|
|
|
|
|
|
|
|
/* calculate waveform offset due to scrolling */
|
|
|
|
nframes_t offset = 0;
|
|
|
|
if ( _offset < timeline.xoffset )
|
|
|
|
{
|
|
|
|
offset = timeline.xoffset - _offset;
|
|
|
|
|
|
|
|
rw = timeline.ts_to_x( (_end - _start) - offset );
|
|
|
|
}
|
|
|
|
|
|
|
|
rw = min( rw, _track->w() );
|
|
|
|
|
|
|
|
int rx = x();
|
|
|
|
|
|
|
|
printf( "rx %d, rw %d\n", rx, rw );
|
2008-02-17 10:00:38 +01:00
|
|
|
|
2008-02-20 08:53:54 +01:00
|
|
|
fl_push_clip( rx, Y, rw, H );
|
|
|
|
|
|
|
|
/* dirty hack to keep the box from flipping to vertical at small sizes */
|
|
|
|
fl_draw_box( FL_PLASTIC_UP_BOX, rx - 10, Y, rw + 50, H, _box_color );
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-02-16 05:23:58 +01:00
|
|
|
// fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
|
|
|
|
|
2008-02-20 11:45:10 +01:00
|
|
|
draw_waveform( rx, Y, rw, H, _clip, _start + offset, _end - offset, _scale, _color );
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-02-20 08:53:54 +01:00
|
|
|
fl_color( FL_BLACK );
|
|
|
|
fl_line( rx, Y, rx, Y + H );
|
|
|
|
fl_line( rx + rw - 1, Y, rx + rw - 1, Y + H );
|
2008-02-16 05:23:58 +01:00
|
|
|
|
2008-02-20 08:53:54 +01:00
|
|
|
fl_pop_clip();
|
2008-02-17 04:32:31 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
fl_font( FL_HELVETICA, 14 );
|
|
|
|
fl_color( FL_BLACK );
|
2008-02-16 11:30:56 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
int bx = Fl::box_dx( FL_PLASTIC_UP_BOX );
|
|
|
|
int by = Fl::box_dy( FL_PLASTIC_UP_BOX );
|
|
|
|
int bw = Fl::box_dw( FL_PLASTIC_UP_BOX );
|
|
|
|
int bh = Fl::box_dh( FL_PLASTIC_UP_BOX );
|
2008-02-16 11:30:56 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
Fl_Align align = (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP);
|
|
|
|
fl_draw( _clip->name(), bx + rx + 1, Y + 1 + by, rw - bw, H - bh, align );
|
|
|
|
fl_color( FL_WHITE );
|
|
|
|
fl_draw( _clip->name(), bx + rx, Y + by , rw - bw, H - bh, align );
|
2008-02-16 11:30:56 +01:00
|
|
|
|
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
// fl_draw( _clip->name(), X, Y );
|
2008-02-16 11:30:56 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
//(Fl_Align)FL_ALIGN_LEFT | FL_ALIGN_BOTTOM );
|
2008-02-20 11:45:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
fl_color( FL_RED );
|
|
|
|
fl_line( x(), y(), x(), y() + h() );
|
|
|
|
|
|
|
|
|
2008-02-14 08:40:47 +01:00
|
|
|
}
|