Begin moving to custom track scrolling with 'virtual' region widgets.
This commit is contained in:
parent
80ec2b6e35
commit
76afaa5792
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ CXXFLAGS=-ggdb -Wall -O0
|
||||||
LIBS=-lsndfile `fltk-config --ldflags`
|
LIBS=-lsndfile `fltk-config --ldflags`
|
||||||
# CXXFLAGS=`fltk-config -cxxflags`
|
# CXXFLAGS=`fltk-config -cxxflags`
|
||||||
|
|
||||||
SRCS= Clip.C Waveform.C Region.C Peaks.C main.C
|
SRCS= Clip.C Waveform.C Region.C Peaks.C main.C Track.C
|
||||||
|
|
||||||
OBJS=$(SRCS:.C=.o)
|
OBJS=$(SRCS:.C=.o)
|
||||||
|
|
||||||
|
|
406
Region.C
406
Region.C
|
@ -20,256 +20,263 @@
|
||||||
#include "Track.H"
|
#include "Track.H"
|
||||||
#include "Region.H"
|
#include "Region.H"
|
||||||
#include "Timeline.H"
|
#include "Timeline.H"
|
||||||
|
#include "Waveform.H"
|
||||||
|
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/Fl_Group.H>
|
#include <FL/Fl_Group.H>
|
||||||
#include <FL/Fl_Widget.H>
|
#include <FL/Fl_Widget.H>
|
||||||
|
#include <FL/Fl_Box.H>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern Timeline timeline;
|
#include <algorithm>
|
||||||
|
//using std::algorithm;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
Region::Region ( int X, int Y, int W, int H, const char *L ) : Waveform( X, Y, W, H, L )
|
extern Timeline timeline;
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Region::init ( void )
|
Region::init ( void )
|
||||||
{
|
{
|
||||||
align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP );
|
|
||||||
labeltype( FL_SHADOW_LABEL );
|
/* align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP ); */
|
||||||
labelcolor( FL_WHITE );
|
/* labeltype( FL_SHADOW_LABEL ); */
|
||||||
box( FL_PLASTIC_UP_BOX );
|
/* labelcolor( FL_WHITE ); */
|
||||||
|
/* box( FL_PLASTIC_UP_BOX ); */
|
||||||
|
|
||||||
_track = NULL;
|
_track = NULL;
|
||||||
// _offset = 0;
|
_offset = 0;
|
||||||
_offset = timeline.x_to_ts( x() );
|
_start = 0;
|
||||||
|
_end = 0;
|
||||||
|
_scale = 1.0f;
|
||||||
|
_clip = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Region::Region ( const Region & rhs ) : Waveform( rhs )
|
Region::Region ( const Region & rhs )
|
||||||
{
|
{
|
||||||
box( rhs.box() );
|
|
||||||
align( rhs.align() );
|
|
||||||
color( rhs.color() );
|
|
||||||
selection_color( rhs.selection_color() );
|
|
||||||
labelcolor( rhs.labelcolor() );
|
|
||||||
labeltype( rhs.labeltype() );
|
|
||||||
|
|
||||||
_offset = rhs._offset;
|
_offset = rhs._offset;
|
||||||
_track = rhs._track;
|
_track = rhs._track;
|
||||||
|
_clip = rhs._clip;
|
||||||
|
_start = rhs._start;
|
||||||
|
_end = rhs._end;
|
||||||
|
_scale = rhs._scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
Region::Region ( Clip *c ) : Waveform( c )
|
Region::Region ( Clip *c )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
_clip = c;
|
||||||
|
_end = _clip->length();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Region::trim ( enum trim_e t, int X )
|
|
||||||
{
|
|
||||||
switch ( t )
|
|
||||||
{
|
|
||||||
case LEFT:
|
|
||||||
{
|
|
||||||
int d = X - x();
|
|
||||||
|
|
||||||
long td = timeline.x_to_ts( d );
|
|
||||||
|
|
||||||
if ( td < 0 && _start < 0 - td )
|
/* void */
|
||||||
td = 0 - _start;
|
/* Region::trim ( enum trim_e t, int X ) */
|
||||||
|
/* { */
|
||||||
|
/* switch ( t ) */
|
||||||
|
/* { */
|
||||||
|
/* case LEFT: */
|
||||||
|
/* { */
|
||||||
|
/* int d = X - x(); */
|
||||||
|
|
||||||
_start += td;
|
/* long td = timeline.x_to_ts( d ); */
|
||||||
|
|
||||||
_offset += td;
|
/* if ( td < 0 && _start < 0 - td ) */
|
||||||
|
/* td = 0 - _start; */
|
||||||
|
|
||||||
resize();
|
/* _start += td; */
|
||||||
// Fl_Widget::resize( x() + d, y(), w() - d, h() );
|
|
||||||
|
|
||||||
// _offset = timeline.x_to_ts( x() );
|
/* _offset += td; */
|
||||||
|
|
||||||
break;
|
/* resize(); */
|
||||||
}
|
/* // Fl_Widget::resize( x() + d, y(), w() - d, h() ); */
|
||||||
case RIGHT:
|
|
||||||
{
|
|
||||||
int d = (x() + w()) - X;
|
|
||||||
long td = timeline.x_to_ts( d );
|
|
||||||
|
|
||||||
_end -= td;
|
/* // _offset = timeline.x_to_ts( x() ); */
|
||||||
|
|
||||||
resize();
|
/* break; */
|
||||||
|
/* } */
|
||||||
|
/* case RIGHT: */
|
||||||
|
/* { */
|
||||||
|
/* int d = (x() + w()) - X; */
|
||||||
|
/* long td = timeline.x_to_ts( d ); */
|
||||||
|
|
||||||
// _end = _start + timeline.x_to_ts( w() - d );
|
/* _end -= td; */
|
||||||
|
|
||||||
// Fl_Widget::resize( x(), y(), w() - d, h() );
|
/* resize(); */
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
/* // _end = _start + timeline.x_to_ts( w() - d ); */
|
||||||
|
|
||||||
redraw();
|
/* // Fl_Widget::resize( x(), y(), w() - d, h() ); */
|
||||||
parent()->redraw();
|
/* break; */
|
||||||
|
/* } */
|
||||||
|
/* default: */
|
||||||
|
/* return; */
|
||||||
|
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
|
/* redraw(); */
|
||||||
|
/* parent()->redraw(); */
|
||||||
|
|
||||||
|
/* } */
|
||||||
|
|
||||||
int
|
int
|
||||||
Region::handle ( int m )
|
Region::handle ( int m ) { return 0; }
|
||||||
{
|
|
||||||
|
|
||||||
if ( Fl_Widget::handle( m ) )
|
/* { */
|
||||||
return 1;
|
|
||||||
|
|
||||||
static int ox, oy;
|
/* /\* if ( Fl_Widget::handle( m ) ) *\/ */
|
||||||
static enum trim_e trimming;
|
/* /\* return 1; *\/ */
|
||||||
|
|
||||||
static bool copied = false;
|
/* static int ox, oy; */
|
||||||
static nframes_t os;
|
/* static enum trim_e trimming; */
|
||||||
|
|
||||||
int X = Fl::event_x();
|
/* static bool copied = false; */
|
||||||
int Y = Fl::event_y();
|
/* static nframes_t os; */
|
||||||
|
|
||||||
switch ( m )
|
/* int X = Fl::event_x(); */
|
||||||
{
|
/* int Y = Fl::event_y(); */
|
||||||
case FL_PUSH:
|
|
||||||
{
|
|
||||||
|
|
||||||
if ( Fl::event_state() & FL_SHIFT &&
|
/* switch ( m ) */
|
||||||
! ( Fl::event_state() & FL_CTRL ))
|
/* { */
|
||||||
{
|
/* case FL_PUSH: */
|
||||||
switch ( Fl::event_button() )
|
/* { */
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
trim( trimming = LEFT, X );
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
trim( trimming = RIGHT, X );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
fl_cursor( FL_CURSOR_WE );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ox = x() - X;
|
|
||||||
oy = y() - Y;
|
|
||||||
|
|
||||||
if ( Fl::event_state() && FL_CTRL )
|
/* if ( Fl::event_state() & FL_SHIFT && */
|
||||||
{
|
/* ! ( Fl::event_state() & FL_CTRL )) */
|
||||||
os = _start;
|
/* { */
|
||||||
// Fl::local_grab( this );
|
/* switch ( Fl::event_button() ) */
|
||||||
}
|
/* { */
|
||||||
|
/* case 1: */
|
||||||
|
/* trim( trimming = LEFT, X ); */
|
||||||
|
/* break; */
|
||||||
|
/* case 3: */
|
||||||
|
/* trim( trimming = RIGHT, X ); */
|
||||||
|
/* break; */
|
||||||
|
/* default: */
|
||||||
|
/* return 0; */
|
||||||
|
/* } */
|
||||||
|
/* fl_cursor( FL_CURSOR_WE ); */
|
||||||
|
/* return 1; */
|
||||||
|
/* } */
|
||||||
|
/* else */
|
||||||
|
/* { */
|
||||||
|
/* ox = x() - X; */
|
||||||
|
/* oy = y() - Y; */
|
||||||
|
|
||||||
if ( Fl::event_button() == 2 )
|
/* if ( Fl::event_state() && FL_CTRL ) */
|
||||||
normalize();
|
/* { */
|
||||||
|
/* os = _start; */
|
||||||
|
/* // Fl::local_grab( this ); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* if ( Fl::event_button() == 2 ) */
|
||||||
|
/* normalize(); */
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
/* return 1; */
|
||||||
}
|
/* } */
|
||||||
return 0;
|
/* return 0; */
|
||||||
break;
|
/* break; */
|
||||||
}
|
/* } */
|
||||||
case FL_RELEASE:
|
/* case FL_RELEASE: */
|
||||||
fl_cursor( FL_CURSOR_DEFAULT );
|
/* fl_cursor( FL_CURSOR_DEFAULT ); */
|
||||||
copied = false;
|
/* copied = false; */
|
||||||
trimming = NO;
|
/* trimming = NO; */
|
||||||
// Fl::release();
|
/* // Fl::release(); */
|
||||||
return 1;
|
/* return 1; */
|
||||||
case FL_DRAG:
|
/* case FL_DRAG: */
|
||||||
|
|
||||||
if ( Fl::event_state() & FL_SHIFT &&
|
/* if ( Fl::event_state() & FL_SHIFT && */
|
||||||
Fl::event_state() & FL_CTRL )
|
/* Fl::event_state() & FL_CTRL ) */
|
||||||
{
|
/* { */
|
||||||
int d = (ox + X) - x();
|
/* int d = (ox + X) - x(); */
|
||||||
long td = timeline.x_to_ts( d );
|
/* long td = timeline.x_to_ts( d ); */
|
||||||
|
|
||||||
if ( td > 0 && os < td )
|
/* if ( td > 0 && os < td ) */
|
||||||
_start = 0;
|
/* _start = 0; */
|
||||||
else
|
/* else */
|
||||||
_start = os - td;
|
/* _start = os - td; */
|
||||||
|
|
||||||
redraw();
|
/* redraw(); */
|
||||||
return 1;
|
/* return 1; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if ( Fl::event_state() & FL_SHIFT )
|
/* if ( Fl::event_state() & FL_SHIFT ) */
|
||||||
if ( trimming )
|
/* if ( trimming ) */
|
||||||
{
|
/* { */
|
||||||
trim( trimming, X );
|
/* trim( trimming, X ); */
|
||||||
return 1;
|
/* return 1; */
|
||||||
}
|
/* } */
|
||||||
else
|
/* else */
|
||||||
return 0;
|
/* return 0; */
|
||||||
|
|
||||||
if ( Fl::event_state() & FL_CTRL )
|
/* if ( Fl::event_state() & FL_CTRL ) */
|
||||||
{
|
/* { */
|
||||||
if ( ! copied )
|
/* if ( ! copied ) */
|
||||||
{
|
/* { */
|
||||||
_track->add( new Region( *this ) );
|
/* _track->add( new Region( *this ) ); */
|
||||||
copied = true;
|
/* copied = true; */
|
||||||
return 1;
|
/* return 1; */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if ( ox + X >= _track->x() )
|
/* if ( ox + X >= _track->x() ) */
|
||||||
{
|
/* { */
|
||||||
int nx = ox + X;
|
/* int nx = ox + X; */
|
||||||
|
|
||||||
// nx = _track->snap( this, nx );
|
/* // nx = _track->snap( this, nx ); */
|
||||||
|
|
||||||
// _offset = timeline.x_to_ts( nx );
|
/* // _offset = timeline.x_to_ts( nx ); */
|
||||||
|
|
||||||
position( nx, y() );
|
/* position( nx, y() ); */
|
||||||
|
|
||||||
_track->snap( this );
|
/* _track->snap( this ); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if ( Y > y() + h() )
|
/* if ( Y > y() + h() ) */
|
||||||
{
|
/* { */
|
||||||
if ( _track->next() )
|
/* if ( _track->next() ) */
|
||||||
_track->next()->add( this );
|
/* _track->next()->add( this ); */
|
||||||
}
|
/* } */
|
||||||
else
|
/* else */
|
||||||
if ( Y < y() )
|
/* if ( Y < y() ) */
|
||||||
{
|
/* { */
|
||||||
if ( _track->prev() )
|
/* if ( _track->prev() ) */
|
||||||
_track->prev()->add( this );
|
/* _track->prev()->add( this ); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
parent()->redraw();
|
/* parent()->redraw(); */
|
||||||
|
|
||||||
fl_cursor( FL_CURSOR_MOVE );
|
/* fl_cursor( FL_CURSOR_MOVE ); */
|
||||||
|
|
||||||
if ( X >= timeline.scroll->x() + timeline.scroll->w() ||
|
/* if ( X >= timeline.scroll->x() + timeline.scroll->w() || */
|
||||||
X <= timeline.scroll->x() )
|
/* X <= timeline.scroll->x() ) */
|
||||||
{
|
/* { */
|
||||||
/* this drag needs to scroll */
|
/* /\* this drag needs to scroll *\/ */
|
||||||
|
|
||||||
long pos = timeline.scroll->xposition();
|
/* long pos = timeline.scroll->xposition(); */
|
||||||
|
|
||||||
if ( X <= timeline.scroll->x() )
|
/* if ( X <= timeline.scroll->x() ) */
|
||||||
pos -= 100;
|
/* pos -= 100; */
|
||||||
else
|
/* else */
|
||||||
pos += 100;
|
/* pos += 100; */
|
||||||
|
|
||||||
if ( pos < 0 )
|
/* if ( pos < 0 ) */
|
||||||
pos = 0;
|
/* pos = 0; */
|
||||||
|
|
||||||
timeline.scroll->position( pos, timeline.scroll->yposition() );
|
/* timeline.scroll->position( pos, timeline.scroll->yposition() ); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
// _offset = timeline.x_to_ts( x() );
|
/* // _offset = timeline.x_to_ts( x() ); */
|
||||||
|
|
||||||
return 1;
|
/* return 1; */
|
||||||
default:
|
/* default: */
|
||||||
return 0;
|
/* return 0; */
|
||||||
break;
|
/* break; */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
/** must be called whenever zoom is adjusted */
|
/** must be called whenever zoom is adjusted */
|
||||||
|
@ -284,39 +291,42 @@ Region::resize ( void )
|
||||||
|
|
||||||
printf( "%dx%d\n", X, W );
|
printf( "%dx%d\n", X, W );
|
||||||
|
|
||||||
if ( W > 5000 )
|
// if ( W )
|
||||||
W = 5000;
|
// Fl_Widget::resize( X, y(), W, h() );
|
||||||
|
|
||||||
if ( W )
|
|
||||||
Fl_Widget::resize( X, y(), W, h() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Region::draw ( void )
|
|
||||||
{
|
|
||||||
|
|
||||||
draw_box();
|
/* X is the timeline offset, W is the width of the track */
|
||||||
|
void
|
||||||
|
Region::draw ( int X, int Y, int W, int H )
|
||||||
|
{
|
||||||
|
int rx = timeline.ts_to_x( _offset ) - X;
|
||||||
|
int rw = min( timeline.ts_to_x( _end - _start ), W );
|
||||||
|
|
||||||
|
fl_draw_box( FL_PLASTIC_UP_BOX, rx, Y, rw, H, FL_CYAN );
|
||||||
|
|
||||||
// fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
|
// fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
|
||||||
|
|
||||||
|
draw_waveform( rx, Y, rw, H, _clip, _start, _end, _scale, FL_GREEN );
|
||||||
Waveform::draw();
|
|
||||||
|
|
||||||
// fl_pop_clip();
|
// fl_pop_clip();
|
||||||
|
|
||||||
|
|
||||||
/* fl_color( FL_RED ); */
|
fl_font( FL_HELVETICA, 14 );
|
||||||
/* int sx = x() - timeline.ts_to_x( _start ); */
|
fl_color( FL_BLACK );
|
||||||
/* fl_line( sx, y(), sx, y() + h() ); */
|
|
||||||
/* int ex = x() + timeline.ts_to_x( _end - _start ); */
|
|
||||||
/* fl_line( ex, y(), ex, y() + h() ); */
|
|
||||||
|
|
||||||
draw_label();
|
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 );
|
||||||
|
|
||||||
/* static char pat[200]; */
|
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 );
|
||||||
|
|
||||||
/* sprintf( pat, "start %lu, end %lu", _start, _end ); */
|
|
||||||
|
|
||||||
/* fl_draw( pat, x(), y() + h() / 2 ); */
|
// fl_draw( _clip->name(), X, Y );
|
||||||
|
|
||||||
|
//(Fl_Align)FL_ALIGN_LEFT | FL_ALIGN_BOTTOM );
|
||||||
}
|
}
|
||||||
|
|
25
Region.H
25
Region.H
|
@ -21,36 +21,41 @@
|
||||||
|
|
||||||
class Track;
|
class Track;
|
||||||
|
|
||||||
#include "Waveform.H"
|
// #include "Waveform.H"
|
||||||
|
|
||||||
class Region : public Waveform
|
#include "Clip.H"
|
||||||
|
|
||||||
|
class Region
|
||||||
{
|
{
|
||||||
|
|
||||||
Track *_track;
|
Track *_track; /* track this region belongs to */
|
||||||
|
|
||||||
nframes_t _offset;
|
Clip *_clip; /* clip this region represents */
|
||||||
|
|
||||||
|
nframes_t _offset; /* where on the timeline */
|
||||||
|
nframes_t _start; /* first sample from clip */
|
||||||
|
nframes_t _end; /* last sample from clip */
|
||||||
|
|
||||||
|
float _scale; /* amplitude adjustment */
|
||||||
|
|
||||||
enum trim_e { NO, LEFT, RIGHT };
|
enum trim_e { NO, LEFT, RIGHT };
|
||||||
|
|
||||||
void trim ( enum trim_e t, int X );
|
void trim ( enum trim_e t, int X );
|
||||||
|
|
||||||
void init ( void );
|
void init ( void );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Region ( int X, int Y, int W, int H, const char *L=0 );
|
|
||||||
|
|
||||||
Region ( const Region & rhs );
|
Region ( const Region & rhs );
|
||||||
Region ( Clip *c );
|
Region ( Clip *c );
|
||||||
|
|
||||||
int handle ( int m );
|
int handle ( int m );
|
||||||
void draw ( void );
|
void draw ( int X, int Y, int W, int H );
|
||||||
void resize ( void );
|
void resize ( void );
|
||||||
|
|
||||||
|
|
||||||
Track * track ( void ) const { return _track; }
|
Track * track ( void ) const { return _track; }
|
||||||
void track ( Track *t ) { _track = t; }
|
void track ( Track *t ) { _track = t; }
|
||||||
|
|
||||||
nframes_t offset ( void ) const { return _offset; }
|
nframes_t offset ( void ) const { return _offset; }
|
||||||
void offset ( nframes_t o ) { _offset = o; }
|
void offset ( nframes_t o ) { _offset = o; }
|
||||||
|
|
||||||
|
void end ( nframes_t v ) { _end = v; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,151 @@
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
/* 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. */
|
||||||
|
/*******************************************************************************/
|
||||||
|
|
||||||
|
#include "Track.H"
|
||||||
|
#include "Timeline.H"
|
||||||
|
|
||||||
|
void
|
||||||
|
Track::draw ( void )
|
||||||
|
{
|
||||||
|
for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
|
||||||
|
{
|
||||||
|
(*r)->draw( x(), y(), w(), h() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Track::remove_region ( Region *r )
|
||||||
|
{
|
||||||
|
_regions.remove( r );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Track::add ( Region *r )
|
||||||
|
{
|
||||||
|
if ( r->track() )
|
||||||
|
{
|
||||||
|
r->track()->remove_region( r );
|
||||||
|
r->track()->redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
_regions.push_back( r );
|
||||||
|
|
||||||
|
r->track( this );
|
||||||
|
|
||||||
|
// Fl_Group::add( r );
|
||||||
|
// add( r );
|
||||||
|
|
||||||
|
// r->position( r->x(), y() );
|
||||||
|
// r->redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** snap /r/ to nearest edge */
|
||||||
|
/* void */
|
||||||
|
/* Track::snap ( Region *r ) */
|
||||||
|
/* { */
|
||||||
|
/* const int snap_pixels = 10; */
|
||||||
|
|
||||||
|
/* int rx1 = r->x(); */
|
||||||
|
/* int rx2 = r->x() + r->w(); */
|
||||||
|
|
||||||
|
/* for ( int i = children(); i-- ; ) */
|
||||||
|
/* { */
|
||||||
|
/* const Region *w = (Region*)child( i ); */
|
||||||
|
|
||||||
|
/* if ( w == r ) */
|
||||||
|
/* continue; */
|
||||||
|
|
||||||
|
/* int wx1 = w->x(); */
|
||||||
|
/* int wx2 = w->x() + w->w(); */
|
||||||
|
|
||||||
|
/* if ( abs( rx1 - wx2 ) < snap_pixels ) */
|
||||||
|
/* { */
|
||||||
|
/* r->offset( w->offset() + w->length() + 1 ); */
|
||||||
|
|
||||||
|
/* printf( "snap: %lu | %lu\n", w->offset() + w->length(), r->offset() ); */
|
||||||
|
|
||||||
|
/* goto done; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* if ( abs( rx2 - wx1 ) < snap_pixels ) */
|
||||||
|
/* { */
|
||||||
|
/* r->offset( ( w->offset() - r->length() ) - 1 ); */
|
||||||
|
|
||||||
|
/* printf( "snap: %lu | %lu\n", r->offset() + r->length(), w->offset() ); */
|
||||||
|
|
||||||
|
/* goto done; */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* r->offset( timeline.x_to_ts( r->x() ) ); */
|
||||||
|
|
||||||
|
/* done: */
|
||||||
|
|
||||||
|
/* r->resize(); */
|
||||||
|
/* // r->position( rx1, y() ); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
int
|
||||||
|
Track::handle ( int m )
|
||||||
|
{
|
||||||
|
switch ( m )
|
||||||
|
{
|
||||||
|
case FL_DND_DRAG:
|
||||||
|
case FL_DND_ENTER:
|
||||||
|
case FL_ENTER:
|
||||||
|
return 1;
|
||||||
|
case FL_DND_LEAVE:
|
||||||
|
case FL_DND_RELEASE:
|
||||||
|
return 1;
|
||||||
|
case FL_PASTE:
|
||||||
|
{
|
||||||
|
const char *text = Fl::event_text();
|
||||||
|
|
||||||
|
char *file;
|
||||||
|
|
||||||
|
if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
|
||||||
|
{
|
||||||
|
printf( "invalid drop \"%s\"\n", text );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( "pasted file \"%s\"\n", file );
|
||||||
|
|
||||||
|
Clip *c = Clip::from_file( file );
|
||||||
|
|
||||||
|
if ( ! c )
|
||||||
|
{
|
||||||
|
free( file );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Region *r = new Region( c );
|
||||||
|
|
||||||
|
r->offset( timeline.x_to_ts( Fl::event_x() ) );
|
||||||
|
// r->position( Fl::event_x(), r->y() );
|
||||||
|
|
||||||
|
this->add( r );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return Fl_Group::handle( m );
|
||||||
|
}
|
||||||
|
}
|
121
Track.H
121
Track.H
|
@ -56,121 +56,10 @@ public:
|
||||||
void prev ( Track *t ) { _prev = t; }
|
void prev ( Track *t ) { _prev = t; }
|
||||||
void next ( Track *t ) { _next = t; }
|
void next ( Track *t ) { _next = t; }
|
||||||
|
|
||||||
void remove_region ( Region *r )
|
void draw ( void );
|
||||||
{
|
void remove_region ( Region *r );
|
||||||
_regions.remove( r );
|
void add ( Region *r );
|
||||||
}
|
void snap ( Region *r );
|
||||||
|
int handle ( int m );
|
||||||
|
|
||||||
void add ( Region *r )
|
|
||||||
{
|
|
||||||
if ( r->track() )
|
|
||||||
{
|
|
||||||
r->track()->remove_region( r );
|
|
||||||
r->track()->redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
_regions.push_back( r );
|
|
||||||
|
|
||||||
r->track( this );
|
|
||||||
|
|
||||||
Fl_Group::add( r );
|
|
||||||
// add( r );
|
|
||||||
|
|
||||||
r->position( r->x(), y() );
|
|
||||||
r->redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** snap /r/ to nearest edge */
|
|
||||||
void
|
|
||||||
snap ( Region *r )
|
|
||||||
{
|
|
||||||
const int snap_pixels = 10;
|
|
||||||
|
|
||||||
int rx1 = r->x();
|
|
||||||
int rx2 = r->x() + r->w();
|
|
||||||
|
|
||||||
for ( int i = children(); i-- ; )
|
|
||||||
{
|
|
||||||
const Region *w = (Region*)child( i );
|
|
||||||
|
|
||||||
if ( w == r )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int wx1 = w->x();
|
|
||||||
int wx2 = w->x() + w->w();
|
|
||||||
|
|
||||||
if ( abs( rx1 - wx2 ) < snap_pixels )
|
|
||||||
{
|
|
||||||
r->offset( w->offset() + w->length() + 1 );
|
|
||||||
|
|
||||||
printf( "snap: %lu | %lu\n", w->offset() + w->length(), r->offset() );
|
|
||||||
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( abs( rx2 - wx1 ) < snap_pixels )
|
|
||||||
{
|
|
||||||
r->offset( ( w->offset() - r->length() ) - 1 );
|
|
||||||
|
|
||||||
printf( "snap: %lu | %lu\n", r->offset() + r->length(), w->offset() );
|
|
||||||
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r->offset( timeline.x_to_ts( r->x() ) );
|
|
||||||
|
|
||||||
done:
|
|
||||||
|
|
||||||
r->resize();
|
|
||||||
// r->position( rx1, y() );
|
|
||||||
}
|
|
||||||
|
|
||||||
int handle ( int m )
|
|
||||||
{
|
|
||||||
switch ( m )
|
|
||||||
{
|
|
||||||
case FL_DND_DRAG:
|
|
||||||
case FL_DND_ENTER:
|
|
||||||
case FL_ENTER:
|
|
||||||
return 1;
|
|
||||||
case FL_DND_LEAVE:
|
|
||||||
case FL_DND_RELEASE:
|
|
||||||
return 1;
|
|
||||||
case FL_PASTE:
|
|
||||||
{
|
|
||||||
const char *text = Fl::event_text();
|
|
||||||
|
|
||||||
char *file;
|
|
||||||
|
|
||||||
if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
|
|
||||||
{
|
|
||||||
printf( "invalid drop \"%s\"\n", text );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf( "pasted file \"%s\"\n", file );
|
|
||||||
|
|
||||||
Clip *c = Clip::from_file( file );
|
|
||||||
|
|
||||||
if ( ! c )
|
|
||||||
{
|
|
||||||
free( file );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Region *r = new Region( c );
|
|
||||||
|
|
||||||
r->offset( timeline.x_to_ts( Fl::event_x() ) );
|
|
||||||
r->position( Fl::event_x(), r->y() );
|
|
||||||
|
|
||||||
this->add( r );
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return Fl_Group::handle( m );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
74
Waveform.C
74
Waveform.C
|
@ -21,8 +21,10 @@
|
||||||
|
|
||||||
#include <FL/Enumerations.H>
|
#include <FL/Enumerations.H>
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
|
#include <FL/fl_draw.H>
|
||||||
|
|
||||||
#include "Waveform.H"
|
#include "Timeline.H"
|
||||||
|
// #include "Waveform.H"
|
||||||
#include "Clip.H"
|
#include "Clip.H"
|
||||||
|
|
||||||
// extern Timeline timeline;
|
// extern Timeline timeline;
|
||||||
|
@ -30,66 +32,40 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
extern Fl_Color velocity_colors[];
|
/* void */
|
||||||
|
/* Waveform::draw ( void ) */
|
||||||
|
/* { */
|
||||||
|
/* int X, Y, W, H; */
|
||||||
|
|
||||||
Waveform::Waveform ( int X, int Y, int W, int H, const char *L ) : Fl_Widget( X, Y, W, H, L )
|
/* fl_clip_box( x(), y(), w(), h(), X, Y, W, H ); */
|
||||||
{
|
|
||||||
_scale = 1;
|
|
||||||
_clip = NULL;
|
|
||||||
|
|
||||||
_start = _end = 0;
|
/* draw( X, y(), W, h() ); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int measure = 50;
|
|
||||||
|
|
||||||
|
/** draw a portion of /clip/'s waveform. coordinates are the portion to draw */
|
||||||
void
|
void
|
||||||
Waveform::draw ( void )
|
draw_waveform ( int X, int Y, int W, int H, Clip *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color )
|
||||||
{
|
|
||||||
// draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() );
|
|
||||||
|
|
||||||
/* fl_color( fl_lighter( color() ) ); */
|
|
||||||
|
|
||||||
/* for ( int nx = x(); nx < x() + w(); ++nx ) */
|
|
||||||
/* if ( ! (nx % measure) ) */
|
|
||||||
/* fl_line( nx, y(), nx, y() + h() ); */
|
|
||||||
|
|
||||||
int X, Y, W, H;
|
|
||||||
|
|
||||||
fl_clip_box( x(), y(), w(), h(), X, Y, W, H );
|
|
||||||
|
|
||||||
draw( X, y(), W, h() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Waveform::draw ( int X, int Y, int W, int H )
|
|
||||||
{
|
{
|
||||||
fl_push_clip( X, Y, W, H );
|
fl_push_clip( X, Y, W, H );
|
||||||
|
|
||||||
// fl_push_matrix();
|
|
||||||
|
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
// int start = (_start + (X - x())) * 2;
|
int start = timeline.ts_to_x( _start );
|
||||||
|
|
||||||
int start = timeline.ts_to_x( _start ) + (X - x() );
|
|
||||||
|
|
||||||
{
|
{
|
||||||
nframes_t start = timeline.x_to_ts( X - x() ) + _start;
|
_clip->peaks()->fill_buffer( _start,
|
||||||
_clip->peaks()->fill_buffer( start,
|
_start + timeline.x_to_ts( W ) );
|
||||||
start + timeline.x_to_ts( W ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
j = start;
|
j = start;
|
||||||
for ( int x = X; x < X + W; ++x, ++j )
|
for ( int x = X; x < X + W; ++x, ++j )
|
||||||
{
|
{
|
||||||
// read_peaks( x, &hi, &lo );
|
|
||||||
Peak p = (*_clip->peaks())[ j ];
|
Peak p = (*_clip->peaks())[ j ];
|
||||||
|
|
||||||
int mid = Y + (H / 2);
|
int mid = Y + (H / 2);
|
||||||
|
|
||||||
// FIXME: cache this stuff.
|
// FIXME: cache this stuff.
|
||||||
// fl_color( fl_color_average( selection_color(), fl_contrast( fl_darker( FL_BLUE ), selection_color() ), fabs( hi - lo ) ) );
|
fl_color( fl_color_average( FL_RED, color, fabs( p.max - p.min ) ) );
|
||||||
fl_color( fl_color_average( FL_RED, selection_color(), fabs( p.max - p.min ) ) );
|
|
||||||
|
|
||||||
p.max *= _scale;
|
p.max *= _scale;
|
||||||
p.min *= _scale;
|
p.min *= _scale;
|
||||||
|
@ -101,7 +77,7 @@ Waveform::draw ( int X, int Y, int W, int H )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fl_color( fl_darker( fl_darker( selection_color() ) ) );
|
fl_color( fl_darker( fl_darker( color ) ) );
|
||||||
|
|
||||||
|
|
||||||
fl_line_style( FL_SOLID, 2 );
|
fl_line_style( FL_SOLID, 2 );
|
||||||
|
@ -136,17 +112,15 @@ Waveform::draw ( int X, int Y, int W, int H )
|
||||||
|
|
||||||
fl_line_style( FL_SOLID, 0 );
|
fl_line_style( FL_SOLID, 0 );
|
||||||
|
|
||||||
// fl_pop_matrix();
|
|
||||||
|
|
||||||
fl_pop_clip();
|
fl_pop_clip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/* void */
|
||||||
Waveform::normalize ( void )
|
/* Waveform::normalize ( void ) */
|
||||||
{
|
/* { */
|
||||||
printf( "normalize: start=%lu end=%lu\n", _start, _end );
|
/* printf( "normalize: start=%lu end=%lu\n", _start, _end ); */
|
||||||
|
|
||||||
_scale = _clip->peaks()->normalization_factor( _start, _end );
|
/* _scale = _clip->peaks()->normalization_factor( _start, _end ); */
|
||||||
|
|
||||||
redraw();
|
/* redraw(); */
|
||||||
}
|
/* } */
|
||||||
|
|
56
Waveform.H
56
Waveform.H
|
@ -26,58 +26,4 @@
|
||||||
|
|
||||||
#include "Clip.H"
|
#include "Clip.H"
|
||||||
|
|
||||||
class Waveform : public Fl_Widget
|
void draw_waveform ( int X, int Y, int W, int H, Clip *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color );
|
||||||
{
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
Clip *_clip; /* clip this waveform represents */
|
|
||||||
|
|
||||||
nframes_t _start;
|
|
||||||
nframes_t _end;
|
|
||||||
|
|
||||||
float _scale; /* vertical scaling */
|
|
||||||
float _zoom; /* horizontal zoom */
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Waveform ( int X, int Y, int W, int H, const char *L=0 );
|
|
||||||
|
|
||||||
Waveform ( Clip *c ) : Fl_Widget( 0, 0, 500, 100, "" )
|
|
||||||
{
|
|
||||||
_clip = c;
|
|
||||||
_scale = 1;
|
|
||||||
label( _clip->name() );
|
|
||||||
|
|
||||||
_start = 0;
|
|
||||||
_end = _clip->length();
|
|
||||||
|
|
||||||
size( timeline.ts_to_x( _end ), h() );
|
|
||||||
}
|
|
||||||
|
|
||||||
Waveform ( const Waveform & rhs ) : Fl_Widget( rhs.x(), rhs.y(), rhs.w(), rhs.h(), rhs.label() )
|
|
||||||
{
|
|
||||||
_clip = rhs._clip;
|
|
||||||
_start = rhs._start;
|
|
||||||
_end = rhs._end;
|
|
||||||
_scale = rhs._scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void draw ( void );
|
|
||||||
void draw ( int X, int Y, int W, int H );
|
|
||||||
|
|
||||||
void start ( nframes_t s ) { _start = s; }
|
|
||||||
nframes_t start ( void ) const { return _start; }
|
|
||||||
void end ( nframes_t e ) { _end = e; }
|
|
||||||
nframes_t end ( void ) const { return _end; }
|
|
||||||
nframes_t length ( void ) const { return _end - _start; }
|
|
||||||
void scale ( float s ) { _scale = s; }
|
|
||||||
float scale ( void ) const { return _scale; }
|
|
||||||
|
|
||||||
// void peaks ( float *p ) { _peaks = p; }
|
|
||||||
void normalize ( void );
|
|
||||||
|
|
||||||
void read_peaks ( int X, float *hi, float *lo );
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
32
main.C
32
main.C
|
@ -26,7 +26,7 @@
|
||||||
#include <FL/Fl_Group.H>
|
#include <FL/Fl_Group.H>
|
||||||
#include <FL/Fl_Slider.H>
|
#include <FL/Fl_Slider.H>
|
||||||
|
|
||||||
#include "Waveform.H"
|
// #include "Waveform.H"
|
||||||
#include "Region.H"
|
#include "Region.H"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -57,12 +57,12 @@ cb_zoom ( Fl_Widget *w, void *v )
|
||||||
timeline.fpp = ((Fl_Slider*)w)->value();
|
timeline.fpp = ((Fl_Slider*)w)->value();
|
||||||
|
|
||||||
|
|
||||||
for ( int i = timeline.tracks->children(); i-- ; )
|
/* for ( int i = timeline.tracks->children(); i-- ; ) */
|
||||||
{
|
/* { */
|
||||||
Fl_Group *track = (Fl_Group*)timeline.tracks->child( i );
|
/* Fl_Group *track = (Fl_Group*)timeline.tracks->child( i ); */
|
||||||
for ( int j = track->children(); j-- ; )
|
/* for ( int j = track->children(); j-- ; ) */
|
||||||
((Region*)(track->child( j )))->resize();
|
/* ((Region*)(track->child( j )))->resize(); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
timeline.scroll->redraw();
|
timeline.scroll->redraw();
|
||||||
|
|
||||||
|
@ -83,12 +83,13 @@ main ( int argc, char **argv )
|
||||||
Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 );
|
Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 );
|
||||||
|
|
||||||
timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - 24 );
|
timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - 24 );
|
||||||
|
timeline.scroll->type( Fl_Scroll::VERTICAL );
|
||||||
timeline.fpp = 256;
|
timeline.fpp = 256;
|
||||||
|
|
||||||
|
|
||||||
timeline.sample_rate = 44100;
|
timeline.sample_rate = 44100;
|
||||||
|
|
||||||
timeline.tracks = new Fl_Pack( 0, 0, 32767, 5000 );
|
timeline.tracks = new Fl_Pack( 0, 0, 800, 5000 );
|
||||||
timeline.tracks->type( Fl_Pack::VERTICAL );
|
timeline.tracks->type( Fl_Pack::VERTICAL );
|
||||||
timeline.tracks->spacing( 20 );
|
timeline.tracks->spacing( 20 );
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ main ( int argc, char **argv )
|
||||||
|
|
||||||
// Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 );
|
// Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 );
|
||||||
|
|
||||||
Track *track1 = new Track( 40, 0, 32768, 100 );
|
Track *track1 = new Track( 40, 0, 800, 100 );
|
||||||
|
|
||||||
// pack->type( Fl_Pack::VERTICAL );
|
// pack->type( Fl_Pack::VERTICAL );
|
||||||
// pack->box( FL_DOWN_BOX );
|
// pack->box( FL_DOWN_BOX );
|
||||||
|
@ -109,13 +110,18 @@ main ( int argc, char **argv )
|
||||||
// wave->resize( 0, 0, 500, 100 );
|
// wave->resize( 0, 0, 500, 100 );
|
||||||
|
|
||||||
wave->offset( 1024 );
|
wave->offset( 1024 );
|
||||||
|
wave->end( 3000 );
|
||||||
|
|
||||||
wave->color( FL_CYAN );
|
/* wave->color( FL_CYAN ); */
|
||||||
wave->selection_color( fl_darker( FL_GRAY ) );
|
/* wave->selection_color( fl_darker( FL_GRAY ) ); */
|
||||||
wave->selection_color( FL_GREEN );
|
/* wave->selection_color( FL_GREEN ); */
|
||||||
|
|
||||||
track1->add( wave );
|
track1->add( wave );
|
||||||
|
|
||||||
|
Region *wave3 = new Region( *wave );
|
||||||
|
wave3->offset( 4000 );
|
||||||
|
track1->add( wave3 );
|
||||||
|
|
||||||
track1->end();
|
track1->end();
|
||||||
|
|
||||||
Track *track2 = new Track( 40, 0, 5000, 100 );
|
Track *track2 = new Track( 40, 0, 5000, 100 );
|
||||||
|
@ -148,7 +154,7 @@ main ( int argc, char **argv )
|
||||||
main_window->end();
|
main_window->end();
|
||||||
main_window->show();
|
main_window->show();
|
||||||
|
|
||||||
wave->redraw();
|
/* wave->redraw(); */
|
||||||
|
|
||||||
Fl::run();
|
Fl::run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue