Browse Source

Begin moving to custom track scrolling with 'virtual' region widgets.

tags/non-daw-v1.1.0
Jonathan Moore Liles 16 years ago
parent
commit
76afaa5792
8 changed files with 453 additions and 472 deletions
  1. +1
    -1
      Makefile
  2. +237
    -227
      Region.C
  3. +15
    -10
      Region.H
  4. +151
    -0
      Track.C
  5. +5
    -116
      Track.H
  6. +24
    -50
      Waveform.C
  7. +1
    -55
      Waveform.H
  8. +19
    -13
      main.C

+ 1
- 1
Makefile View File

@@ -5,7 +5,7 @@ CXXFLAGS=-ggdb -Wall -O0
LIBS=-lsndfile `fltk-config --ldflags`
# 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)



+ 237
- 227
Region.C View File

@@ -20,256 +20,263 @@
#include "Track.H"
#include "Region.H"
#include "Timeline.H"
#include "Waveform.H"

#include <FL/fl_draw.H>
#include <FL/Fl.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Box.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 )
{
init();
}
extern Timeline timeline;

void
Region::init ( void )
{
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 );

/* 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 ); */

_track = NULL;
// _offset = 0;
_offset = timeline.x_to_ts( x() );
_offset = 0;
_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;
_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();
_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 )
td = 0 - _start;
/* void */
/* 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();
// Fl_Widget::resize( x() + d, y(), w() - d, h() );
/* _start += td; */

// _offset = timeline.x_to_ts( x() );
/* _offset += td; */

break;
}
case RIGHT:
{
int d = (x() + w()) - X;
long td = timeline.x_to_ts( d );
/* resize(); */
/* // Fl_Widget::resize( x() + d, y(), w() - d, h() ); */

_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() );
break;
}
default:
return;
/* resize(); */

}
/* // _end = _start + timeline.x_to_ts( w() - d ); */

redraw();
parent()->redraw();
/* // Fl_Widget::resize( x(), y(), w() - d, h() ); */
/* break; */
/* } */
/* default: */
/* return; */

}
/* } */

int
Region::handle ( int m )
{
/* redraw(); */
/* parent()->redraw(); */

if ( Fl_Widget::handle( m ) )
return 1;

static int ox, oy;
static enum trim_e trimming;

static bool copied = false;
static nframes_t os;

int X = Fl::event_x();
int Y = Fl::event_y();

switch ( m )
{
case FL_PUSH:
{

if ( Fl::event_state() & FL_SHIFT &&
! ( Fl::event_state() & FL_CTRL ))
{
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 )
{
os = _start;
// Fl::local_grab( this );
}

if ( Fl::event_button() == 2 )
normalize();


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;
}

if ( Fl::event_state() & FL_SHIFT )
if ( trimming )
{
trim( trimming, X );
return 1;
}
else
return 0;

if ( Fl::event_state() & FL_CTRL )
{
if ( ! copied )
{
_track->add( new Region( *this ) );
copied = true;
return 1;
}
}

if ( ox + X >= _track->x() )
{
int nx = ox + X;

// nx = _track->snap( this, nx );

// _offset = timeline.x_to_ts( nx );

position( nx, y() );

_track->snap( this );
}

if ( Y > y() + h() )
{
if ( _track->next() )
_track->next()->add( this );
}
else
if ( Y < y() )
{
if ( _track->prev() )
_track->prev()->add( this );
}

parent()->redraw();

fl_cursor( FL_CURSOR_MOVE );

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() );
}

// _offset = timeline.x_to_ts( x() );

return 1;
default:
return 0;
break;
}
}
/* } */

int
Region::handle ( int m ) { return 0; }

/* { */

/* /\* if ( Fl_Widget::handle( m ) ) *\/ */
/* /\* return 1; *\/ */

/* static int ox, oy; */
/* static enum trim_e trimming; */

/* static bool copied = false; */
/* static nframes_t os; */

/* int X = Fl::event_x(); */
/* int Y = Fl::event_y(); */

/* switch ( m ) */
/* { */
/* case FL_PUSH: */
/* { */

/* if ( Fl::event_state() & FL_SHIFT && */
/* ! ( Fl::event_state() & FL_CTRL )) */
/* { */
/* 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 ) */
/* { */
/* os = _start; */
/* // Fl::local_grab( this ); */
/* } */

/* if ( Fl::event_button() == 2 ) */
/* normalize(); */


/* 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; */
/* } */

/* if ( Fl::event_state() & FL_SHIFT ) */
/* if ( trimming ) */
/* { */
/* trim( trimming, X ); */
/* return 1; */
/* } */
/* else */
/* return 0; */

/* if ( Fl::event_state() & FL_CTRL ) */
/* { */
/* if ( ! copied ) */
/* { */
/* _track->add( new Region( *this ) ); */
/* copied = true; */
/* return 1; */
/* } */
/* } */

/* if ( ox + X >= _track->x() ) */
/* { */
/* int nx = ox + X; */

/* // nx = _track->snap( this, nx ); */

/* // _offset = timeline.x_to_ts( nx ); */

/* position( nx, y() ); */

/* _track->snap( this ); */
/* } */

/* if ( Y > y() + h() ) */
/* { */
/* if ( _track->next() ) */
/* _track->next()->add( this ); */
/* } */
/* else */
/* if ( Y < y() ) */
/* { */
/* if ( _track->prev() ) */
/* _track->prev()->add( this ); */
/* } */

/* parent()->redraw(); */

/* fl_cursor( FL_CURSOR_MOVE ); */

/* 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() ); */
/* } */

/* // _offset = timeline.x_to_ts( x() ); */

/* return 1; */
/* default: */
/* return 0; */
/* break; */
/* } */
/* } */


/** must be called whenever zoom is adjusted */
@@ -284,39 +291,42 @@ Region::resize ( void )

printf( "%dx%d\n", X, W );

if ( W > 5000 )
W = 5000;

if ( W )
Fl_Widget::resize( X, y(), W, h() );
// if ( W )
// Fl_Widget::resize( X, y(), W, h() );
}


/* X is the timeline offset, W is the width of the track */
void
Region::draw ( 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 );

draw_box();
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() );


Waveform::draw();
draw_waveform( rx, Y, rw, H, _clip, _start, _end, _scale, FL_GREEN );

// fl_pop_clip();


/* fl_color( FL_RED ); */
/* int sx = x() - timeline.ts_to_x( _start ); */
/* fl_line( sx, y(), sx, y() + h() ); */
/* int ex = x() + timeline.ts_to_x( _end - _start ); */
/* fl_line( ex, y(), ex, y() + h() ); */
fl_font( FL_HELVETICA, 14 );
fl_color( FL_BLACK );

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 );
}

+ 15
- 10
Region.H View File

@@ -21,36 +21,41 @@

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 */

enum trim_e { NO, LEFT, RIGHT };
nframes_t _offset; /* where on the timeline */
nframes_t _start; /* first sample from clip */
nframes_t _end; /* last sample from clip */

void trim ( enum trim_e t, int X );
float _scale; /* amplitude adjustment */

enum trim_e { NO, LEFT, RIGHT };
void trim ( enum trim_e t, int X );
void init ( void );

public:

Region ( int X, int Y, int W, int H, const char *L=0 );

Region ( const Region & rhs );
Region ( Clip *c );

int handle ( int m );
void draw ( void );
void draw ( int X, int Y, int W, int H );
void resize ( void );


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; }

void end ( nframes_t v ) { _end = v; }
};

+ 151
- 0
Track.C View File

@@ -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 );
}
}

+ 5
- 116
Track.H View File

@@ -56,121 +56,10 @@ public:
void prev ( Track *t ) { _prev = t; }
void next ( Track *t ) { _next = t; }

void remove_region ( Region *r )
{
_regions.remove( r );
}

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;
void draw ( void );
void remove_region ( Region *r );
void add ( Region *r );
void snap ( Region *r );
int handle ( int m );

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 );
}
}
};

+ 24
- 50
Waveform.C View File

@@ -21,8 +21,10 @@

#include <FL/Enumerations.H>
#include <FL/Fl.H>
#include <FL/fl_draw.H>

#include "Waveform.H"
#include "Timeline.H"
// #include "Waveform.H"
#include "Clip.H"

// extern Timeline timeline;
@@ -30,66 +32,40 @@

#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 )
{
_scale = 1;
_clip = NULL;

_start = _end = 0;
}

int measure = 50;

void
Waveform::draw ( void )
{
// 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() ); */
/* fl_clip_box( x(), y(), w(), h(), X, Y, W, H ); */

int X, Y, W, H;

fl_clip_box( x(), y(), w(), h(), X, Y, W, H );

draw( X, y(), W, h() );
}
/* draw( X, y(), W, h() ); */
/* } */

/** draw a portion of /clip/'s waveform. coordinates are the portion to draw */
void
Waveform::draw ( int X, int Y, int W, int H )
draw_waveform ( int X, int Y, int W, int H, Clip *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color )
{
fl_push_clip( X, Y, W, H );

// fl_push_matrix();

int j;

// int start = (_start + (X - x())) * 2;

int start = timeline.ts_to_x( _start ) + (X - x() );
int start = timeline.ts_to_x( _start );

{
nframes_t start = timeline.x_to_ts( X - x() ) + _start;
_clip->peaks()->fill_buffer( start,
start + timeline.x_to_ts( W ) );
_clip->peaks()->fill_buffer( _start,
_start + timeline.x_to_ts( W ) );
}

j = start;
for ( int x = X; x < X + W; ++x, ++j )
{
// read_peaks( x, &hi, &lo );
Peak p = (*_clip->peaks())[ j ];

int mid = Y + (H / 2);

// 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, selection_color(), fabs( p.max - p.min ) ) );
fl_color( fl_color_average( FL_RED, color, fabs( p.max - p.min ) ) );

p.max *= _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 );
@@ -136,17 +112,15 @@ Waveform::draw ( int X, int Y, int W, int H )

fl_line_style( FL_SOLID, 0 );

// fl_pop_matrix();

fl_pop_clip();
}

void
Waveform::normalize ( void )
{
printf( "normalize: start=%lu end=%lu\n", _start, _end );
/* void */
/* Waveform::normalize ( void ) */
/* { */
/* 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(); */
/* } */

+ 1
- 55
Waveform.H View File

@@ -26,58 +26,4 @@

#include "Clip.H"

class Waveform : public Fl_Widget
{

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 );

};
void draw_waveform ( int X, int Y, int W, int H, Clip *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color );

+ 19
- 13
main.C View File

@@ -26,7 +26,7 @@
#include <FL/Fl_Group.H>
#include <FL/Fl_Slider.H>

#include "Waveform.H"
// #include "Waveform.H"
#include "Region.H"

#include <stdio.h>
@@ -57,12 +57,12 @@ cb_zoom ( Fl_Widget *w, void *v )
timeline.fpp = ((Fl_Slider*)w)->value();


for ( int i = timeline.tracks->children(); i-- ; )
{
Fl_Group *track = (Fl_Group*)timeline.tracks->child( i );
for ( int j = track->children(); j-- ; )
((Region*)(track->child( j )))->resize();
}
/* for ( int i = timeline.tracks->children(); i-- ; ) */
/* { */
/* Fl_Group *track = (Fl_Group*)timeline.tracks->child( i ); */
/* for ( int j = track->children(); j-- ; ) */
/* ((Region*)(track->child( j )))->resize(); */
/* } */

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 );

timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - 24 );
timeline.scroll->type( Fl_Scroll::VERTICAL );
timeline.fpp = 256;


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->spacing( 20 );

@@ -97,7 +98,7 @@ main ( int argc, char **argv )

// 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->box( FL_DOWN_BOX );
@@ -109,13 +110,18 @@ main ( int argc, char **argv )
// wave->resize( 0, 0, 500, 100 );

wave->offset( 1024 );
wave->end( 3000 );

wave->color( FL_CYAN );
wave->selection_color( fl_darker( FL_GRAY ) );
wave->selection_color( FL_GREEN );
/* wave->color( FL_CYAN ); */
/* wave->selection_color( fl_darker( FL_GRAY ) ); */
/* wave->selection_color( FL_GREEN ); */

track1->add( wave );

Region *wave3 = new Region( *wave );
wave3->offset( 4000 );
track1->add( wave3 );

track1->end();

Track *track2 = new Track( 40, 0, 5000, 100 );
@@ -148,7 +154,7 @@ main ( int argc, char **argv )
main_window->end();
main_window->show();

wave->redraw();
/* wave->redraw(); */

Fl::run();
}

Loading…
Cancel
Save