From 875ff62c8a56909a2b7d733518493e9015cb28a6 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 4 May 2008 19:56:07 -0500 Subject: [PATCH] Split Region into Audio_Region and Sequence_Region base class. --- Timeline/Audio_Region.C | 120 ++------------------ Timeline/Audio_Region.H | 13 +-- Timeline/Sequence_Region.C | 217 +++++++++++++++++++++++++++++++++++++ Timeline/Sequence_Region.H | 78 +++++++++++++ Timeline/makefile.inc | 2 + 5 files changed, 309 insertions(+), 121 deletions(-) create mode 100644 Timeline/Sequence_Region.C create mode 100644 Timeline/Sequence_Region.H diff --git a/Timeline/Audio_Region.C b/Timeline/Audio_Region.C index a769a6c..45b0b36 100644 --- a/Timeline/Audio_Region.C +++ b/Timeline/Audio_Region.C @@ -105,7 +105,7 @@ Audio_Region::init ( void ) /* copy constructor */ Audio_Region::Audio_Region ( const Audio_Region & rhs ) { - *((Sequence_Widget*)this) = (Sequence_Widget &)rhs; + *((Sequence_Region*)this) = (Sequence_Region &)rhs; _clip = rhs._clip; _scale = rhs._scale; @@ -166,59 +166,6 @@ Audio_Region::Audio_Region ( Audio_File *c, Sequence *t, nframes_t o ) log_create(); } -void -Audio_Region::trim ( enum trim_e t, int X ) -{ - - X -= _track->x(); - redraw(); - - switch ( t ) - { - case LEFT: - { -/* if ( d < 0 ) */ -/* // _track->damage( FL_DAMAGE_EXPOSE, x() + d, y(), 1 - d, h() ); */ -/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() ); */ -/* else */ -/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), d, h() ); */ - - int d = X - ( abs_x() - scroll_x() ); - - long td = timeline->x_to_ts( d ); - - if ( td < 0 && _r->start < 0 - td ) - td = 0 - _r->start; - - if ( _r->start + td >= _r->end ) - td = (_r->end - _r->start) - timeline->x_to_ts( 1 ); - - _r->start += td; - _r->offset += td; - break; - } - case RIGHT: - { - int d = (( abs_x() - scroll_x() ) + abs_w() ) - X; - -/* _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), d, h() ); */ - - long td = timeline->x_to_ts( d ); - -// printf( "%li %li\n", td, _r->end - _r->start ); - - if ( td >= 0 && _r->end - _r->start < td ) - _r->end = _r->start + timeline->x_to_ts( 1 ); - else - _r->end -= td; - - break; - } - default: - return; - - } -} int Audio_Region::handle ( int m ) @@ -239,19 +186,14 @@ Audio_Region::handle ( int m ) int ret; + if ( Sequence_Region::handle( m ) ) + return 1; + Logger _log( this ); //log_r->start(); switch ( m ) { - case FL_ENTER: - Sequence_Widget::handle( m ); -// redraw(); - break; - case FL_LEAVE: - Sequence_Widget::handle( m ); -// redraw(); - break; case FL_KEYBOARD: { if ( Fl::event_key() == FL_F + 3 ) @@ -286,22 +228,11 @@ Audio_Region::handle ( int m ) } case FL_PUSH: { - - /* trimming / splitting */ + /* splitting */ if ( Fl::event_shift() && ! Fl::event_ctrl() ) { switch ( Fl::event_button() ) { - case 1: - trim( trimming = LEFT, X ); - begin_drag( Drag( x() - X, y() - Y ) ); - _log.hold(); - break; - case 3: - trim( trimming = RIGHT, X ); - begin_drag( Drag( x() - X, y() - Y ) ); - _log.hold(); - break; case 2: { /* split */ @@ -327,7 +258,6 @@ Audio_Region::handle ( int m ) break; } - fl_cursor( FL_CURSOR_WE ); return 1; } else @@ -354,7 +284,7 @@ Audio_Region::handle ( int m ) } redraw(); - goto changed; + return 1; } else if ( Fl::event_button1() && Fl::event_ctrl() ) { @@ -411,10 +341,8 @@ Audio_Region::handle ( int m ) Sequence_Widget::handle( m ); copied = false; - if ( trimming != NO ) - trimming = NO; - goto changed; + return 1; } case FL_DRAG: @@ -444,16 +372,6 @@ Audio_Region::handle ( int m ) return 1; } - /* trimming */ - if ( Fl::event_state() & FL_SHIFT ) - if ( trimming ) - { - trim( trimming, X ); - return 1; - } - else - return 0; - /* duplication */ if ( Fl::event_state() & FL_CTRL ) { @@ -465,36 +383,12 @@ Audio_Region::handle ( int m ) } } - - /* track jumping */ - if ( ! selected() ) - { - if ( Y > y() + h() || Y < y() ) - { - printf( "wants to jump tracks\n" ); - - Track *t = timeline->track_under( Y ); - - fl_cursor( (Fl_Cursor)1 ); - - if ( t ) - t->handle( FL_ENTER ); - - return 0; - } - } - ret = Sequence_Widget::handle( m ); return ret | 1; default: return Sequence_Widget::handle( m ); break; } - -changed: - - return 1; - } diff --git a/Timeline/Audio_Region.H b/Timeline/Audio_Region.H index 5c31e23..7026261 100644 --- a/Timeline/Audio_Region.H +++ b/Timeline/Audio_Region.H @@ -16,21 +16,20 @@ /* 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. */ /*******************************************************************************/ + #pragma once #include "Audio_File.H" -#include "Sequence.H" #include "Timeline.H" /* Audio_Regions are "virtual" FLTK widgets; this is necessary because the * dimensions of real FLTK widgets are limited to 16-bits, which is * far too little for our purposes */ -#include "Sequence_Widget.H" -#include "Loggable.H" +#include "Sequence_Region.H" -class Audio_Region : public Sequence_Widget +class Audio_Region : public Sequence_Region { public: @@ -158,8 +157,6 @@ public: Fl_Color selection_color ( void ) const { return _selection_color; } void selection_color ( Fl_Color v ) { _selection_color = v; } - enum trim_e { NO, LEFT, RIGHT }; - void trim ( enum trim_e t, int X ); void init ( void ); Audio_Region ( ) @@ -171,7 +168,6 @@ public: public: - const char *source_name ( void ) const { return _clip->name(); } LOG_CREATE_FUNC( Audio_Region ); @@ -190,9 +186,10 @@ public: Audio_Region ( Audio_File *c ); Audio_Region ( Audio_File *c, Sequence *t, nframes_t o ); - int handle ( int m ); void draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool filled, int X, int W ); + + int handle ( int m ); void draw_box( void ); void draw ( void ); void resize ( void ); diff --git a/Timeline/Sequence_Region.C b/Timeline/Sequence_Region.C new file mode 100644 index 0000000..cc9994e --- /dev/null +++ b/Timeline/Sequence_Region.C @@ -0,0 +1,217 @@ + +/*******************************************************************************/ +/* 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 "Sequence_Region.H" +#include "Track.H" + + +void +Sequence_Region::draw_box ( void ) +{ + fl_draw_box( box(), x(), y(), w(), h(), color() ); +} + +void +Sequence_Region::draw ( void ) +{ + + +} + +void +Sequence_Region::trim ( enum trim_e t, int X ) +{ + + X -= _track->x(); + redraw(); + + switch ( t ) + { + case LEFT: + { +/* if ( d < 0 ) */ +/* // _track->damage( FL_DAMAGE_EXPOSE, x() + d, y(), 1 - d, h() ); */ +/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() ); */ +/* else */ +/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), d, h() ); */ + + int d = X - ( abs_x() - scroll_x() ); + + long td = timeline->x_to_ts( d ); + + if ( td < 0 && _r->start < 0 - td ) + td = 0 - _r->start; + + if ( _r->start + td >= _r->end ) + td = (_r->end - _r->start) - timeline->x_to_ts( 1 ); + + _r->start += td; + _r->offset += td; + break; + } + case RIGHT: + { + int d = (( abs_x() - scroll_x() ) + abs_w() ) - X; + +/* _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), d, h() ); */ + + long td = timeline->x_to_ts( d ); + +// printf( "%li %li\n", td, _r->end - _r->start ); + + if ( td >= 0 && _r->end - _r->start < td ) + _r->end = _r->start + timeline->x_to_ts( 1 ); + else + _r->end -= td; + + break; + } + default: + return; + + } +} + + + +int +Sequence_Region::handle ( int m ) +{ + static int ox, oy; + static enum trim_e trimming; + + static bool copied = false; + static nframes_t os; + + +/* if ( ! active_r() ) */ +/* return 0; */ + +// int X = Fl::event_x() - _track->x(); + int X = Fl::event_x(); + int Y = Fl::event_y(); + + int ret; + + Logger _log( this ); +//log_r->start(); + + switch ( m ) + { + case FL_PUSH: + { + /* trimming */ + if ( Fl::event_shift() && ! Fl::event_ctrl() ) + { + switch ( Fl::event_button() ) + { + case 1: + trim( trimming = LEFT, X ); + begin_drag( Drag( x() - X, y() - Y ) ); + _log.hold(); + break; + case 3: + trim( trimming = RIGHT, X ); + begin_drag( Drag( x() - X, y() - Y ) ); + _log.hold(); + break; + default: + return 0; + break; + } + + fl_cursor( FL_CURSOR_WE ); + return 1; + } + else if ( Fl::test_shortcut( FL_BUTTON3 ) ) + { + if ( Sequence_Widget::current() == this ) + { + if ( selected() ) + deselect(); + else + select(); + } + + redraw(); + return 1; + } + else if ( Fl::test_shortcut( FL_CTRL + FL_BUTTON1 ) ) + { + /* duplication */ + return 1; + } + else + return Sequence_Widget::handle( m ); + break; + } + case FL_RELEASE: + { + Sequence_Widget::handle( m ); + + copied = false; + if ( trimming != NO ) + trimming = NO; + + return 1; + } + case FL_DRAG: + { + if ( ! _drag ) + { + begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) ); + _log.hold(); + } + + /* trimming */ + if ( Fl::event_state() & FL_SHIFT ) + if ( trimming ) + { + trim( trimming, X ); + return 1; + } + else + return 0; + + /* track jumping */ + if ( ! selected() ) + { + if ( Y > y() + h() || Y < y() ) + { + printf( "wants to jump tracks\n" ); + + Track *t = timeline->track_under( Y ); + + fl_cursor( (Fl_Cursor)1 ); + + if ( t ) + t->handle( FL_ENTER ); + + return 0; + } + } + + ret = Sequence_Widget::handle( m ); + return ret | 1; + } + default: + return Sequence_Widget::handle( m ); + break; + } +} diff --git a/Timeline/Sequence_Region.H b/Timeline/Sequence_Region.H new file mode 100644 index 0000000..bf8cb58 --- /dev/null +++ b/Timeline/Sequence_Region.H @@ -0,0 +1,78 @@ + +/*******************************************************************************/ +/* 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. */ +/*******************************************************************************/ + +#pragma once + +#include "Sequence.H" +#include "Sequence_Widget.H" + +/* Base class representing a /region/ of time on a /sequence/, with + controls for the start and end points. */ + +class Sequence_Region : public Sequence_Widget +{ + +protected: + + virtual void get ( Log_Entry &e ) const + { + e.add( ":color", (int)_box_color ); + + Sequence_Widget::get( e ); + } + + + void + set ( Log_Entry &e ) + { + for ( int i = 0; i < e.size(); ++i ) + { + const char *s, *v; + + e.get( i, &s, &v ); + + if ( ! strcmp( s, ":color" ) ) + _box_color = (Fl_Color)atoll( v ); + } + + Sequence_Widget::set( e ); + } + + Sequence_Region ( ) + { + + } + + virtual ~Sequence_Region ( ) + { + + } + +public: + + LOG_NAME_FUNC( Region ); + + enum trim_e { NO, LEFT, RIGHT }; + void trim ( enum trim_e t, int X ); + + int handle ( int m ); + void draw_box( void ); + void draw ( void ); + +}; diff --git a/Timeline/makefile.inc b/Timeline/makefile.inc index 0e616d9..03919aa 100644 --- a/Timeline/makefile.inc +++ b/Timeline/makefile.inc @@ -1,3 +1,4 @@ +# -*- mode: makefile; -*- Timeline_VERSION := 0.5.0 @@ -19,6 +20,7 @@ Timeline/Audio_Region.C \ Timeline/Sequence.C \ Timeline/Sequence_Point.C \ Timeline/Sequence_Widget.C \ +Timeline/Sequence_Region.C \ Timeline/TLE.C \ Timeline/Tempo_Point.C \ Timeline/Time_Point.C \