Browse Source

Begin handlig region events again.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
900c49aeae
4 changed files with 145 additions and 102 deletions
  1. +100
    -99
      Region.C
  2. +9
    -1
      Region.H
  3. +30
    -1
      Track.C
  4. +6
    -1
      Track.H

+ 100
- 99
Region.C View File

@@ -122,86 +122,85 @@ Region::Region ( Clip *c )
/* } */ /* } */


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

/* { */
Region::handle ( int m )
{


/* /\* if ( Fl_Widget::handle( m ) ) *\/ */
/* /\* return 1; *\/ */
static int ox, oy;
static enum trim_e trimming;


/* static int ox, oy; */
/* static enum trim_e trimming; */
static bool copied = false;
static nframes_t os;


/* static bool copied = false; */
/* static nframes_t os; */
int X = Fl::event_x();
int Y = Fl::event_y();


/* int X = Fl::event_x(); */
/* int Y = Fl::event_y(); */
switch ( m )
{
case FL_PUSH:
{


/* switch ( m ) */
/* { */
/* case FL_PUSH: */
/* { */
if ( Fl::event_state() & FL_SHIFT &&
! ( Fl::event_state() & FL_CTRL ))
{
switch ( Fl::event_button() )
{


/* if ( Fl::event_state() & FL_SHIFT && */
/* ! ( Fl::event_state() & FL_CTRL )) */
/* { */
/* switch ( Fl::event_button() ) */
/* { */
/* case 1: */ /* case 1: */
/* trim( trimming = LEFT, X ); */ /* trim( trimming = LEFT, X ); */
/* break; */ /* break; */
/* case 3: */ /* case 3: */
/* trim( trimming = RIGHT, X ); */ /* trim( trimming = RIGHT, X ); */
/* break; */ /* 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 ); */
/* } */
default:
return 0;


/* if ( Fl::event_button() == 2 ) */
/* normalize(); */
}
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 );
}


/* 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 ( Fl::event_button() == 2 ) */
/* normalize(); */


/* if ( td > 0 && os < td ) */
/* _start = 0; */
/* else */
/* _start = os - td; */


/* redraw(); */
/* return 1; */
/* } */
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 ( Fl::event_state() & FL_SHIFT ) */
/* if ( trimming ) */ /* if ( trimming ) */
@@ -212,44 +211,46 @@ Region::handle ( int m ) { return 0; }
/* else */ /* else */
/* return 0; */ /* return 0; */


/* if ( Fl::event_state() & FL_CTRL ) */
/* { */
/* if ( ! copied ) */
/* { */
/* _track->add( new Region( *this ) ); */
/* copied = true; */
/* return 1; */
/* } */
/* } */
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; */
if ( ox + X >= _track->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 ); */
/* } */
_offset = timeline.x_to_ts( nx ) + timeline.xoffset;


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


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


/* fl_cursor( FL_CURSOR_MOVE ); */
_track->redraw();

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() ) */
@@ -269,14 +270,14 @@ Region::handle ( int m ) { return 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; */
/* default: */
/* return 0; */
/* break; */
/* } */
/* } */
return 1;
default:
return 0;
break;
}
}




/** must be called whenever zoom is adjusted */ /** must be called whenever zoom is adjusted */


+ 9
- 1
Region.H View File

@@ -19,11 +19,13 @@


#pragma once #pragma once


class Track;
// class Track;


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


#include "Clip.H" #include "Clip.H"
#include "Track.H"
#include "Timeline.H"


class Region class Region
{ {
@@ -47,6 +49,10 @@ public:
Region ( const Region & rhs ); Region ( const Region & rhs );
Region ( Clip *c ); Region ( Clip *c );


int y ( void ) { return _track->y(); }
int h ( void ) { return _track->h(); }
int x ( void ) { return timeline.ts_to_x( _offset ) - timeline.xoffset; }

int handle ( int m ); int handle ( int m );
void draw ( int X, int Y, int W, int H ); void draw ( int X, int Y, int W, int H );
void resize ( void ); void resize ( void );
@@ -57,5 +63,7 @@ public:
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; }


nframes_t length ( void ) const { return _end - _start; }

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

+ 30
- 1
Track.C View File

@@ -20,6 +20,8 @@
#include "Track.H" #include "Track.H"
#include "Timeline.H" #include "Timeline.H"


#include "Region.H"

void void
Track::draw ( void ) Track::draw ( void )
{ {
@@ -36,6 +38,24 @@ Track::remove_region ( Region *r )
_regions.remove( r ); _regions.remove( r );
} }



Region *
Track::event_region ( void )
{
// FIXME: doesn't handle overlap!

for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
{
int X = timeline.ts_to_x( (*r)->offset() ) - timeline.xoffset;
int W = timeline.ts_to_x( (*r)->length() );

if ( Fl::event_x() > X && Fl::event_x() < X + W )
return (*r);
}

return NULL;
}

void void
Track::add ( Region *r ) Track::add ( Region *r )
{ {
@@ -146,7 +166,16 @@ Track::handle ( int m )


return 1; return 1;
} }
case FL_MOVE:
/* these aren't used, so don't bother doing lookups for them */
return 1;
default: default:
return Fl_Group::handle( m );
{
Region *r = event_region();
if ( r )
return r->handle( m );
else
return Fl_Group::handle( m );
}
} }
} }

+ 6
- 1
Track.H View File

@@ -21,7 +21,7 @@


#include <FL/Fl_Group.H> #include <FL/Fl_Group.H>
#include <FL/Fl.H> #include <FL/Fl.H>
#include "Region.H"
// #include "Region.H"


#include <stdio.h> #include <stdio.h>


@@ -31,6 +31,8 @@
#include <list> #include <list>
using std::list; using std::list;


class Region;

class Track : public Fl_Group class Track : public Fl_Group
{ {
Track *_next; Track *_next;
@@ -40,6 +42,8 @@ class Track : public Fl_Group


char *_name; char *_name;


Region *event_region ( void );

public: public:


Track ( int X, int Y, int W, int H ) : Fl_Group( X, Y, W, H ) Track ( int X, int Y, int W, int H ) : Fl_Group( X, Y, W, H )
@@ -56,6 +60,7 @@ 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 draw ( void ); void draw ( void );
void remove_region ( Region *r ); void remove_region ( Region *r );
void add ( Region *r ); void add ( Region *r );


Loading…
Cancel
Save