From 331078c3b2193e49502911c0d8e63e830194cba3 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Mon, 26 May 2008 14:39:50 -0500 Subject: [PATCH] Move Engine portion of Control_Sequence into Engine/. --- Timeline/Control_Sequence.C | 82 ++--------------------- Timeline/Engine/Control_Sequence.C | 100 +++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 75 deletions(-) create mode 100644 Timeline/Engine/Control_Sequence.C diff --git a/Timeline/Control_Sequence.C b/Timeline/Control_Sequence.C index e32fe29..f54bccb 100644 --- a/Timeline/Control_Sequence.C +++ b/Timeline/Control_Sequence.C @@ -19,19 +19,22 @@ #include #include -using namespace std; +using std::list; #include "Control_Sequence.H" #include "Track.H" #include "Engine/Port.H" #include "Engine/Engine.H" // for lock() -#include "Transport.H" // for transport->frame + + bool Control_Sequence::draw_with_gradient = true; bool Control_Sequence::draw_with_polygon = true; bool Control_Sequence::draw_with_grid = true; + + Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0 ) { init(); @@ -76,6 +79,8 @@ Control_Sequence::init ( void ) color( fl_darker( FL_YELLOW ) ); } + + void Control_Sequence::get ( Log_Entry &e ) const { @@ -333,76 +338,3 @@ Control_Sequence::handle ( int m ) return 0; } } - - -/**********/ -/* Engine */ -/**********/ - - -static inline float -linear_interpolate ( float y1, float y2, float mu ) -{ -// return y1 + mu * ( y2 - y1 ); - return y1 * ( 1.0f - mu ) + y2 * mu; -} - -static inline float -sigmoid_interpolate ( float y1, float y2, float mu ) -{ - return linear_interpolate( y1, y2, ( 1 - cos( mu * M_PI ) ) / 2 ); -} - -/* THREAD: ?? */ -/** fill buf with /nframes/ of interpolated control curve values - * starting at /frame/ */ -nframes_t -Control_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes ) -{ - Control_Point *p2, *p1 = (Control_Point*)&_widgets.front(); - - nframes_t n = nframes; - - for ( list ::const_iterator i = _widgets.begin(); - i != _widgets.end(); ++i, p1 = p2 ) - { - p2 = (Control_Point*)(*i); - - if ( p2->when() < frame ) - continue; - - /* do incremental linear interpolation */ - - const nframes_t len = p2->when() - p1->when(); - - /* scale to -1.0 to 1.0 */ - const float y1 = 1.0f - ( 2.0f * p1->control() ); - const float y2 = 1.0f - ( 2.0f * p2->control() ); - - const nframes_t start = frame - p1->when(); - const float incr = ( y2 - y1 ) / (float)len; - - float v = y1 + start * incr; - - for ( nframes_t i = start; i < len && n--; ++i, v += incr ) - *(buf++) = v; - - } - - return nframes - n; -} - - -/* THREAD: RT */ -nframes_t -Control_Sequence::process ( nframes_t nframes ) -{ - if ( _output->connected() ) /* don't waste CPU on disconnected ports */ - { - void *buf = _output->buffer( nframes ); - - return play( (sample_t*)buf, transport->frame, nframes ); - } - else - return nframes; -} diff --git a/Timeline/Engine/Control_Sequence.C b/Timeline/Engine/Control_Sequence.C new file mode 100644 index 0000000..d515167 --- /dev/null +++ b/Timeline/Engine/Control_Sequence.C @@ -0,0 +1,100 @@ + +/*******************************************************************************/ +/* 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 "../Control_Sequence.H" + +#include "../Transport.H" // for ->frame + +#include +using std::list; + + + +/**********/ +/* Engine */ +/**********/ + +static inline float +linear_interpolate ( float y1, float y2, float mu ) +{ +// return y1 + mu * ( y2 - y1 ); + return y1 * ( 1.0f - mu ) + y2 * mu; +} + +static inline float +sigmoid_interpolate ( float y1, float y2, float mu ) +{ + return linear_interpolate( y1, y2, ( 1 - cos( mu * M_PI ) ) / 2 ); +} + + + +/* THREAD: RT */ +/** fill buf with /nframes/ of interpolated control curve values + * starting at /frame/ */ +nframes_t +Control_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes ) +{ + Control_Point *p2, *p1 = (Control_Point*)&_widgets.front(); + + nframes_t n = nframes; + + for ( list ::const_iterator i = _widgets.begin(); + i != _widgets.end(); ++i, p1 = p2 ) + { + p2 = (Control_Point*)(*i); + + if ( p2->when() < frame ) + continue; + + /* do incremental linear interpolation */ + + const nframes_t len = p2->when() - p1->when(); + + /* scale to -1.0 to 1.0 */ + const float y1 = 1.0f - ( 2.0f * p1->control() ); + const float y2 = 1.0f - ( 2.0f * p2->control() ); + + const nframes_t start = frame - p1->when(); + const float incr = ( y2 - y1 ) / (float)len; + + float v = y1 + start * incr; + + for ( nframes_t i = start; i < len && n--; ++i, v += incr ) + *(buf++) = v; + + } + + return nframes - n; +} + + +/* THREAD: RT */ +nframes_t +Control_Sequence::process ( nframes_t nframes ) +{ + if ( _output->connected() ) /* don't waste CPU on disconnected ports */ + { + void *buf = _output->buffer( nframes ); + + return play( (sample_t*)buf, transport->frame, nframes ); + } + else + return nframes; +}