2008-02-14 08:40:47 +01:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Sequence.H"
|
2008-05-05 02:04:20 +02:00
|
|
|
#include "Audio_Region.H"
|
2008-02-16 08:21:15 +01:00
|
|
|
#include "Timeline.H"
|
2008-02-20 06:57:14 +01:00
|
|
|
#include "Waveform.H"
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-04-25 09:07:18 +02:00
|
|
|
#include "Audio_Sequence.H"
|
2008-05-05 07:29:39 +02:00
|
|
|
#include "Track.H"
|
2008-04-25 09:07:18 +02:00
|
|
|
|
2008-04-16 02:47:51 +02:00
|
|
|
#include "dsp.h"
|
|
|
|
|
2008-02-14 08:40:47 +01:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Group.H>
|
2008-02-16 04:50:16 +01:00
|
|
|
#include <FL/Fl_Widget.H>
|
2008-02-20 06:57:14 +01:00
|
|
|
#include <FL/Fl_Box.H>
|
2008-04-15 13:44:03 +02:00
|
|
|
#include <FL/Fl_Menu_Item.H>
|
2008-02-16 04:50:16 +01:00
|
|
|
#include <stdio.h>
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
#include <algorithm>
|
2008-04-14 06:01:08 +02:00
|
|
|
// using std::algorithm;
|
2008-02-20 06:57:14 +01:00
|
|
|
using namespace std;
|
2008-02-16 08:21:15 +01:00
|
|
|
|
2008-03-26 09:33:14 +01:00
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
extern Timeline *timeline;
|
2008-02-17 00:12:23 +01:00
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
bool Audio_Region::inherit_track_color = true;
|
2008-04-14 10:55:22 +02:00
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
Fl_Boxtype Audio_Region::_box = FL_UP_BOX;
|
2008-02-20 13:45:02 +01:00
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
Fl_Color Audio_Region::_selection_color = FL_MAGENTA;
|
2008-02-21 08:38:31 +01:00
|
|
|
|
2008-02-21 10:48:53 +01:00
|
|
|
static Fl_Color fl_invert_color ( Fl_Color c )
|
|
|
|
{
|
|
|
|
unsigned char r, g, b;
|
|
|
|
|
|
|
|
Fl::get_color( c, r, g, b );
|
|
|
|
|
|
|
|
return fl_rgb_color( 255 - r, 255 - g, 255 - b );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
void
|
|
|
|
Audio_Region::get ( Log_Entry &e ) const
|
2008-02-26 02:03:59 +01:00
|
|
|
{
|
2008-05-07 20:43:56 +02:00
|
|
|
e.add( ":source", _clip ? _clip->name() : "" );
|
|
|
|
e.add( ":gain", _scale );
|
|
|
|
e.add( ":fade-in-type", _fade_in.type );
|
|
|
|
e.add( ":fade-in-duration", _fade_in.length );
|
|
|
|
e.add( ":fade-out-type", _fade_out.type );
|
|
|
|
e.add( ":fade-out-duration", _fade_out.length );
|
|
|
|
e.add( ":color", (int)_box_color );
|
2008-02-26 02:03:59 +01:00
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
Sequence_Region::get( e );
|
2008-02-26 02:03:59 +01:00
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
e.add( ":offset", _r->offset );
|
|
|
|
}
|
2008-02-26 02:03:59 +01:00
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
void
|
|
|
|
Audio_Region::set ( Log_Entry &e )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < e.size(); ++i )
|
|
|
|
{
|
|
|
|
const char *s, *v;
|
|
|
|
|
|
|
|
e.get( i, &s, &v );
|
|
|
|
|
|
|
|
if ( ! strcmp( s, ":gain" ) )
|
|
|
|
_scale = atof( v );
|
|
|
|
else if ( ! strcmp( s, ":color" ) )
|
|
|
|
_box_color = (Fl_Color)atoi( v );
|
|
|
|
else if ( ! strcmp( s, ":fade-in-type" ) )
|
|
|
|
_fade_in.type = (Fade::fade_type_e)atoi( v );
|
|
|
|
else if ( ! strcmp( s, ":fade-in-duration" ) )
|
|
|
|
_fade_in.length = atoll( v );
|
|
|
|
else if ( ! strcmp( s, ":fade-out-type" ) )
|
|
|
|
_fade_out.type = (Fade::fade_type_e)atoi( v );
|
|
|
|
else if ( ! strcmp( s, ":fade-out-duration" ) )
|
|
|
|
_fade_out.length = atoll( v );
|
|
|
|
else if ( ! strcmp( s, ":offset" ) )
|
|
|
|
_r->offset = atoll( v );
|
|
|
|
else if ( ! strcmp( s, ":source" ) )
|
|
|
|
{
|
|
|
|
if ( ! ( _clip = Audio_File::from_file( v ) ) )
|
|
|
|
{
|
|
|
|
printf( "Grave error: could not open source \"%s\"\n", v );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-26 02:03:59 +01:00
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
Sequence_Region::set( e );
|
2008-02-26 02:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-17 00:12:23 +01:00
|
|
|
void
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::init ( void )
|
2008-02-14 08:40:47 +01:00
|
|
|
{
|
2008-05-07 18:42:31 +02:00
|
|
|
_sequence = NULL;
|
2008-02-20 06:57:14 +01:00
|
|
|
_scale = 1.0f;
|
|
|
|
_clip = NULL;
|
2008-02-20 08:53:54 +01:00
|
|
|
|
|
|
|
_box_color = FL_CYAN;
|
|
|
|
_color = FL_BLUE;
|
2008-04-15 01:50:01 +02:00
|
|
|
|
|
|
|
_fade_in.length = 256;
|
2008-04-15 03:27:27 +02:00
|
|
|
_fade_in.type = Fade::Sigmoid;
|
2008-04-15 01:50:01 +02:00
|
|
|
|
|
|
|
_fade_out = _fade_in;
|
2008-02-14 08:40:47 +01:00
|
|
|
}
|
|
|
|
|
2008-02-28 13:51:51 +01:00
|
|
|
/* copy constructor */
|
2008-05-08 02:04:47 +02:00
|
|
|
Audio_Region::Audio_Region ( const Audio_Region & rhs ) : Sequence_Region( rhs )
|
2008-02-16 08:46:43 +01:00
|
|
|
{
|
2008-05-08 02:04:47 +02:00
|
|
|
// *((Sequence_Region*)this) = (Sequence_Region &)rhs;
|
2008-04-13 00:55:25 +02:00
|
|
|
|
2008-03-01 16:25:27 +01:00
|
|
|
_clip = rhs._clip;
|
|
|
|
_scale = rhs._scale;
|
2008-02-22 11:22:22 +01:00
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
_fade_in = rhs._fade_in;
|
|
|
|
_fade_out = rhs._fade_out;
|
|
|
|
|
2008-02-22 11:22:22 +01:00
|
|
|
log_create();
|
2008-02-16 08:46:43 +01:00
|
|
|
}
|
|
|
|
|
2008-02-28 13:51:51 +01:00
|
|
|
/* */
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::Audio_Region ( Audio_File *c )
|
2008-02-17 00:12:23 +01:00
|
|
|
{
|
|
|
|
init();
|
2008-02-20 06:57:14 +01:00
|
|
|
_clip = c;
|
2008-05-07 20:43:56 +02:00
|
|
|
_r->length = _clip->length();
|
2008-02-22 11:22:22 +01:00
|
|
|
|
|
|
|
log_create();
|
2008-02-17 00:12:23 +01:00
|
|
|
}
|
|
|
|
|
2008-02-18 02:13:20 +01:00
|
|
|
|
2008-02-28 13:51:51 +01:00
|
|
|
/* used when DND importing */
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::Audio_Region ( Audio_File *c, Sequence *t, nframes_t o )
|
2008-02-28 13:51:51 +01:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
_clip = c;
|
2008-05-07 18:42:31 +02:00
|
|
|
_sequence = t;
|
2008-05-07 20:43:56 +02:00
|
|
|
_r->offset = 0;
|
|
|
|
_r->start = o;
|
|
|
|
_r->length = _clip->length();
|
2008-02-28 13:51:51 +01:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
sequence()->add( this );
|
2008-02-28 13:51:51 +01:00
|
|
|
|
2008-03-01 16:25:27 +01:00
|
|
|
int sum = 0;
|
|
|
|
const char *s = rindex( _clip->name(), '/' );
|
2008-04-16 20:08:00 +02:00
|
|
|
if ( ! s )
|
|
|
|
s = _clip->name();
|
|
|
|
|
2008-03-01 16:25:27 +01:00
|
|
|
for ( int i = strlen( s ); i--; )
|
|
|
|
sum += s[ i ];
|
|
|
|
|
|
|
|
while ( sum >> 8 )
|
|
|
|
sum = (sum & 0xFF) + (sum >> 8);
|
|
|
|
|
|
|
|
_color = (Fl_Color)sum;
|
|
|
|
|
|
|
|
/* _color = fl_color_average( FL_YELLOW, (Fl_Color)sum, 0.80 ); */
|
|
|
|
|
|
|
|
// _color = FL_YELLOW;
|
|
|
|
|
|
|
|
_box_color = FL_WHITE;
|
|
|
|
|
2008-02-28 13:51:51 +01:00
|
|
|
log_create();
|
|
|
|
}
|
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
|
|
|
|
int
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::handle ( int m )
|
2008-02-20 07:35:29 +01:00
|
|
|
{
|
|
|
|
static int ox, oy;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
static bool copied = false;
|
|
|
|
static nframes_t os;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-04-25 09:35:55 +02:00
|
|
|
|
|
|
|
if ( ! active_r() )
|
|
|
|
return 0;
|
|
|
|
|
2008-03-05 03:12:54 +01:00
|
|
|
// int X = Fl::event_x() - _track->x();
|
|
|
|
int X = Fl::event_x();
|
2008-02-20 07:35:29 +01:00
|
|
|
int Y = Fl::event_y();
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-02-21 03:06:39 +01:00
|
|
|
int ret;
|
|
|
|
|
2008-05-05 02:56:07 +02:00
|
|
|
if ( Sequence_Region::handle( m ) )
|
|
|
|
return 1;
|
|
|
|
|
2008-02-24 14:28:55 +01:00
|
|
|
Logger _log( this );
|
2008-04-02 09:19:48 +02:00
|
|
|
//log_r->start();
|
2008-02-21 03:06:39 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
switch ( m )
|
|
|
|
{
|
2008-04-15 09:13:40 +02:00
|
|
|
case FL_KEYBOARD:
|
|
|
|
{
|
|
|
|
if ( Fl::event_key() == FL_F + 3 )
|
|
|
|
{
|
|
|
|
nframes_t offset = x_to_offset( X );
|
|
|
|
|
|
|
|
if ( offset < length() )
|
|
|
|
_fade_in.length = offset;
|
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
DMESSAGE( "setting fade in length to %lu", _fade_in.length );
|
2008-04-28 10:33:22 +02:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
|
|
|
|
return 1;
|
2008-04-15 09:13:40 +02:00
|
|
|
}
|
2008-04-28 10:33:22 +02:00
|
|
|
else if ( Fl::event_key() == FL_F + 4 )
|
|
|
|
{
|
|
|
|
long offset = length() - x_to_offset( X );
|
2008-04-15 09:13:40 +02:00
|
|
|
|
2008-04-28 10:33:22 +02:00
|
|
|
if ( offset > 0 )
|
|
|
|
_fade_out.length = offset;
|
2008-04-15 09:13:40 +02:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
DMESSAGE( "setting fade out length to %lu", _fade_in.length );
|
2008-04-15 09:13:40 +02:00
|
|
|
|
2008-04-28 10:33:22 +02:00
|
|
|
redraw();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-04-15 09:13:40 +02:00
|
|
|
|
|
|
|
}
|
2008-02-20 07:35:29 +01:00
|
|
|
case FL_PUSH:
|
|
|
|
{
|
2008-05-05 02:56:07 +02:00
|
|
|
/* splitting */
|
2008-03-06 20:30:08 +01:00
|
|
|
if ( Fl::event_shift() && ! Fl::event_ctrl() )
|
2008-02-20 07:35:29 +01:00
|
|
|
{
|
|
|
|
switch ( Fl::event_button() )
|
|
|
|
{
|
2008-02-24 08:48:07 +01:00
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
/* split */
|
|
|
|
if ( ! copied )
|
|
|
|
{
|
2008-02-24 11:04:14 +01:00
|
|
|
Loggable::block_start();
|
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region *copy = new Audio_Region( *this );
|
2008-02-24 08:48:07 +01:00
|
|
|
|
|
|
|
trim( RIGHT, X );
|
|
|
|
copy->trim( LEFT, X );
|
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
sequence()->add( copy );
|
2008-02-24 11:04:14 +01:00
|
|
|
|
|
|
|
log_end();
|
|
|
|
|
|
|
|
Loggable::block_end();
|
2008-03-05 23:51:04 +01:00
|
|
|
return 0;
|
2008-02-24 08:48:07 +01:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 07:35:29 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
2008-02-24 08:42:41 +01:00
|
|
|
break;
|
2008-02-20 07:35:29 +01:00
|
|
|
}
|
2008-02-24 08:42:41 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ox = x() - X;
|
|
|
|
oy = y() - Y;
|
2008-03-06 20:30:08 +01:00
|
|
|
/* for panning */
|
2008-05-07 20:43:56 +02:00
|
|
|
os = _r->offset;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-03-06 20:30:08 +01:00
|
|
|
/* normalization and selection */
|
2008-03-05 23:51:04 +01:00
|
|
|
if ( Fl::event_button2() )
|
2008-02-21 03:10:44 +01:00
|
|
|
{
|
2008-03-05 23:51:04 +01:00
|
|
|
if ( Fl::event_ctrl() )
|
2008-02-21 10:51:07 +01:00
|
|
|
normalize();
|
|
|
|
else
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
if ( Sequence_Widget::current() == this )
|
2008-03-04 01:35:40 +01:00
|
|
|
{
|
|
|
|
if ( selected() )
|
|
|
|
deselect();
|
|
|
|
else
|
|
|
|
select();
|
|
|
|
}
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
2008-02-21 10:51:07 +01:00
|
|
|
|
2008-02-22 05:53:39 +01:00
|
|
|
redraw();
|
2008-05-05 02:56:07 +02:00
|
|
|
return 1;
|
2008-02-21 03:10:44 +01:00
|
|
|
}
|
2008-05-07 05:00:32 +02:00
|
|
|
else if ( Fl::test_shortcut( FL_BUTTON3 ) && ! Fl::event_shift() )
|
2008-04-15 13:44:03 +02:00
|
|
|
{
|
|
|
|
/* context menu */
|
|
|
|
|
|
|
|
Fade::fade_type_e it = _fade_in.type;
|
|
|
|
Fade::fade_type_e ot = _fade_out.type;
|
|
|
|
|
|
|
|
Fl_Menu_Item menu[] =
|
|
|
|
{
|
|
|
|
{ "Fade", 0, 0, 0, FL_SUBMENU },
|
|
|
|
{ "In", 0, 0, 0, FL_SUBMENU },
|
|
|
|
{ "Linear", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Linear ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ "Logarithmic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ 0 },
|
|
|
|
{ "Out", 0, 0, 0, FL_SUBMENU },
|
|
|
|
{ "Linear", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Linear ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ "Logarothmic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
|
|
|
|
{ 0 },
|
|
|
|
{ 0 },
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
const Fl_Menu_Item *r = menu->popup( X, Y, "Audio_Region" );
|
2008-04-15 13:44:03 +02:00
|
|
|
|
|
|
|
if ( r )
|
|
|
|
{
|
|
|
|
if ( r > &menu[1] && r < &menu[6] )
|
|
|
|
_fade_in.type = (Fade::fade_type_e)(int)(r - &menu[2]);
|
|
|
|
else if ( r > &menu[7] && r < &menu[12] )
|
|
|
|
_fade_out.type = (Fade::fade_type_e)(int)(r - &menu[8]);
|
2008-04-27 04:45:24 +02:00
|
|
|
|
|
|
|
redraw();
|
2008-04-15 13:44:03 +02:00
|
|
|
}
|
|
|
|
|
2008-05-07 05:00:32 +02:00
|
|
|
return 0;
|
2008-04-15 13:44:03 +02:00
|
|
|
}
|
2008-03-05 23:51:04 +01:00
|
|
|
else
|
2008-05-08 02:25:12 +02:00
|
|
|
return Sequence_Region::handle( m );
|
2008-02-20 07:35:29 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FL_RELEASE:
|
2008-03-05 03:12:54 +01:00
|
|
|
{
|
2008-05-08 02:25:12 +02:00
|
|
|
Sequence_Region::handle( m );
|
2008-03-05 03:12:54 +01:00
|
|
|
|
2008-02-20 07:35:29 +01:00
|
|
|
copied = false;
|
2008-03-05 03:12:54 +01:00
|
|
|
|
2008-05-05 02:56:07 +02:00
|
|
|
return 1;
|
2008-03-05 03:12:54 +01:00
|
|
|
}
|
2008-02-20 07:35:29 +01:00
|
|
|
case FL_DRAG:
|
|
|
|
|
2008-03-05 03:12:54 +01:00
|
|
|
if ( ! _drag )
|
2008-02-24 14:28:55 +01:00
|
|
|
{
|
2008-05-02 07:52:50 +02:00
|
|
|
begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
|
2008-02-24 14:28:55 +01:00
|
|
|
_log.hold();
|
|
|
|
}
|
2008-05-08 02:25:12 +02:00
|
|
|
if ( Fl::event_button1() )
|
2008-02-20 07:35:29 +01:00
|
|
|
{
|
2008-05-08 02:25:12 +02:00
|
|
|
if ( Fl::event_state() & ( FL_SHIFT | FL_CTRL ) )
|
|
|
|
{
|
|
|
|
/* panning */
|
|
|
|
int d = (ox + X) - x();
|
|
|
|
long td = timeline->x_to_ts( d );
|
2008-02-20 12:48:42 +01:00
|
|
|
|
2008-05-08 02:25:12 +02:00
|
|
|
if ( td > 0 && os < (nframes_t)td )
|
|
|
|
_r->offset = 0;
|
|
|
|
else
|
|
|
|
_r->offset = os - td;
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-05-08 02:25:12 +02:00
|
|
|
sequence()->redraw();
|
2008-02-20 07:35:29 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-05-08 02:25:12 +02:00
|
|
|
ret = Sequence_Region::handle( m );
|
2008-02-21 03:06:39 +01:00
|
|
|
return ret | 1;
|
2008-02-20 07:35:29 +01:00
|
|
|
default:
|
2008-05-08 02:25:12 +02:00
|
|
|
return Sequence_Region::handle( m );
|
2008-02-20 07:35:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-05-07 20:43:56 +02:00
|
|
|
|
|
|
|
return 0;
|
2008-02-20 07:35:29 +01:00
|
|
|
}
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
|
|
|
|
/** Draws the curve for a single fade. /X/ and /W/ repersent the
|
2008-04-16 07:50:32 +02:00
|
|
|
portion of the region covered by this draw, which may or may not
|
|
|
|
cover the fade in question. */
|
2008-02-21 07:02:43 +01:00
|
|
|
void
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool line, int X, int W )
|
2008-02-21 07:02:43 +01:00
|
|
|
{
|
2008-04-15 01:50:01 +02:00
|
|
|
const int dy = y() + Fl::box_dy( box() );
|
|
|
|
const int dh = h() - Fl::box_dh( box() );
|
|
|
|
const int height = dh;
|
2008-04-15 03:08:06 +02:00
|
|
|
const int width = timeline->ts_to_x( fade.length );
|
2008-04-02 08:49:24 +02:00
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
fl_color( fl_lighter( FL_BLACK ) );
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-04-15 03:08:06 +02:00
|
|
|
fl_push_matrix();
|
2008-02-21 08:38:31 +01:00
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
if ( dir == Fade::In )
|
2008-04-15 03:08:06 +02:00
|
|
|
fl_translate( line_x(), dy );
|
2008-02-21 08:38:31 +01:00
|
|
|
else
|
2008-04-14 12:00:08 +02:00
|
|
|
{
|
2008-04-15 03:27:27 +02:00
|
|
|
fl_translate( line_x() + abs_w(), dy );
|
2008-04-15 03:08:06 +02:00
|
|
|
/* flip */
|
|
|
|
fl_scale( -1.0, 1.0 );
|
2008-04-15 01:50:01 +02:00
|
|
|
}
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-15 10:53:36 +02:00
|
|
|
fl_scale( width, height );
|
|
|
|
|
|
|
|
if ( line )
|
2008-04-15 03:27:27 +02:00
|
|
|
fl_begin_line();
|
2008-04-15 10:53:36 +02:00
|
|
|
else
|
|
|
|
fl_begin_polygon();
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-15 03:08:06 +02:00
|
|
|
fl_vertex( 0.0, 0.0 );
|
|
|
|
fl_vertex( 0.0, 1.0 );
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-16 07:50:32 +02:00
|
|
|
|
|
|
|
// if ( draw_real_fade_curve )
|
|
|
|
{
|
|
|
|
nframes_t tsx = timeline->x_to_ts( 1 );
|
|
|
|
nframes_t ts = 0;
|
|
|
|
|
|
|
|
for ( int i = 0; i < width; ++i, ts += tsx )
|
|
|
|
fl_vertex( i / (float)width, 1.0f - fade.gain( ts / (float)fade.length ) );
|
|
|
|
|
|
|
|
}
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-15 16:01:21 +02:00
|
|
|
fl_vertex( 1.0, 0.0 );
|
|
|
|
|
2008-04-15 10:53:36 +02:00
|
|
|
if ( line )
|
2008-04-15 03:27:27 +02:00
|
|
|
fl_end_line();
|
2008-04-15 10:53:36 +02:00
|
|
|
else
|
|
|
|
fl_end_polygon();
|
2008-04-15 03:08:06 +02:00
|
|
|
|
|
|
|
fl_pop_matrix();
|
2008-04-15 01:50:01 +02:00
|
|
|
}
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-05-11 19:18:51 +02:00
|
|
|
struct Peaks_Redraw_Request {
|
|
|
|
|
|
|
|
Audio_Region *region;
|
|
|
|
|
|
|
|
nframes_t start;
|
|
|
|
nframes_t end;
|
|
|
|
|
|
|
|
Peaks_Redraw_Request ( Audio_Region *region, nframes_t start, nframes_t end ) : region( region ), start( start), end( end )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* static wrapper */
|
|
|
|
void
|
|
|
|
Audio_Region::peaks_pending_cb ( void *v )
|
|
|
|
{
|
|
|
|
Peaks_Redraw_Request *r = (Peaks_Redraw_Request*)v;
|
|
|
|
|
|
|
|
r->region->peaks_pending_cb( r );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Audio_Region::peaks_pending_cb ( Peaks_Redraw_Request *r )
|
2008-04-30 02:38:28 +02:00
|
|
|
{
|
2008-05-11 19:18:51 +02:00
|
|
|
int npeaks = timeline->ts_to_x( r->end - r->start );
|
2008-04-30 02:38:28 +02:00
|
|
|
|
2008-05-11 19:18:51 +02:00
|
|
|
if ( _clip->peaks()->ready( r->start, npeaks, timeline->fpp() ) )
|
|
|
|
{
|
|
|
|
printf( "damaging from timeout\n" );
|
|
|
|
/* FIXME: only need to damage the affected area! */
|
|
|
|
timeline->damage( FL_DAMAGE_ALL, x(), y(), w(), h() );
|
2008-04-30 02:38:28 +02:00
|
|
|
|
2008-05-11 19:18:51 +02:00
|
|
|
delete r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Fl::repeat_timeout( 0.1f, &Audio_Region::peaks_pending_cb, (void*)r );
|
2008-04-30 02:38:28 +02:00
|
|
|
}
|
2008-04-25 09:35:55 +02:00
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
void
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::draw_box( void )
|
2008-04-15 01:50:01 +02:00
|
|
|
{
|
|
|
|
/* dirty hack to keep the box from flipping to vertical at small sizes */
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-17 17:35:20 +02:00
|
|
|
fl_push_clip( x(), y(), w(), h() );
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-25 08:58:08 +02:00
|
|
|
Fl_Color selection_color = _selection_color;
|
2008-04-26 11:01:54 +02:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
Fl_Color color = Audio_Region::inherit_track_color ? sequence()->track()->color() : _box_color;
|
2008-04-25 08:58:08 +02:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
color = fl_color_average( color, sequence()->color(), 0.75f );
|
2008-04-25 09:35:55 +02:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
if ( this == ((Audio_Sequence*)sequence())->capture() )
|
2008-04-25 09:07:18 +02:00
|
|
|
{
|
|
|
|
color = FL_RED;
|
|
|
|
}
|
|
|
|
else if ( ! active_r() )
|
2008-04-25 08:58:08 +02:00
|
|
|
{
|
|
|
|
color = fl_inactive( color );
|
|
|
|
selection_color = fl_inactive( selection_color );
|
|
|
|
}
|
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
if ( selected() )
|
2008-04-25 08:58:08 +02:00
|
|
|
fl_draw_box( fl_down( box() ), x() - 10, y(), w() + 50, h(), selection_color );
|
2008-04-15 01:50:01 +02:00
|
|
|
else
|
2008-04-25 08:58:08 +02:00
|
|
|
fl_draw_box( box(), x() - 10, y(), w() + 50, h(), color );
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
/* draw fades */
|
2008-04-17 17:35:20 +02:00
|
|
|
draw_fade( _fade_in, Fade::In, false, x(), w() );
|
|
|
|
draw_fade( _fade_out, Fade::Out, false, x(), w() );
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-02-21 07:02:43 +01:00
|
|
|
fl_pop_clip();
|
|
|
|
}
|
2008-02-20 06:57:14 +01:00
|
|
|
|
2008-04-17 15:27:35 +02:00
|
|
|
/** Draw (part of) region. X, Y, W and H are the rectangle we're clipped to. */
|
2008-02-14 08:40:47 +01:00
|
|
|
void
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::draw ( void )
|
2008-02-14 08:40:47 +01:00
|
|
|
{
|
2008-04-17 17:19:04 +02:00
|
|
|
/* intersect clip with region */
|
2008-04-17 17:35:20 +02:00
|
|
|
|
|
|
|
int X, Y, W, H;
|
2008-04-17 17:19:04 +02:00
|
|
|
|
|
|
|
fl_clip_box( x(), y(), w(), h(), X, Y, W, H );
|
|
|
|
|
2008-02-20 11:45:10 +01:00
|
|
|
if ( ! ( W > 0 && H > 0 ) )
|
2008-04-17 17:35:20 +02:00
|
|
|
/* no coverage */
|
2008-02-20 11:45:10 +01:00
|
|
|
return;
|
|
|
|
|
2008-04-30 08:09:50 +02:00
|
|
|
/* account for waveform outlines... */
|
|
|
|
X -= 2;
|
|
|
|
W += 4;
|
|
|
|
|
2008-02-21 01:32:54 +01:00
|
|
|
int OX = scroll_x();
|
2008-05-07 20:43:56 +02:00
|
|
|
int ox = timeline->ts_to_x( _r->start );
|
2008-02-21 01:25:21 +01:00
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
if ( ox > OX + sequence()->w() ||
|
2008-02-21 07:02:43 +01:00
|
|
|
ox < OX && ox + abs_w() < OX )
|
2008-04-17 15:27:35 +02:00
|
|
|
/* not in viewport */
|
2008-02-20 11:45:10 +01:00
|
|
|
return;
|
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
int rw = timeline->ts_to_x( _r->length );
|
2008-02-20 11:45:10 +01:00
|
|
|
|
|
|
|
/* calculate waveform offset due to scrolling */
|
|
|
|
nframes_t offset = 0;
|
2008-02-21 01:25:21 +01:00
|
|
|
if ( ox < OX )
|
2008-02-20 11:45:10 +01:00
|
|
|
{
|
2008-02-21 17:20:36 +01:00
|
|
|
offset = timeline->x_to_ts( OX - ox );
|
2008-02-20 11:45:10 +01:00
|
|
|
|
2008-04-17 17:19:04 +02:00
|
|
|
rw -= OX - ox;
|
2008-02-20 11:45:10 +01:00
|
|
|
}
|
|
|
|
|
2008-05-07 18:42:31 +02:00
|
|
|
rw = min( rw, sequence()->w() );
|
2008-02-20 11:45:10 +01:00
|
|
|
|
|
|
|
int rx = x();
|
|
|
|
|
2008-04-17 17:35:20 +02:00
|
|
|
fl_push_clip( rx, Y, rw, H );
|
2008-02-20 08:53:54 +01:00
|
|
|
|
2008-03-26 09:33:14 +01:00
|
|
|
/* get actual peak data */
|
|
|
|
int channels;
|
|
|
|
int peaks;
|
|
|
|
Peak *pbuf;
|
2008-02-20 13:45:02 +01:00
|
|
|
|
2008-02-14 08:40:47 +01:00
|
|
|
|
2008-04-17 15:27:35 +02:00
|
|
|
// const nframes_t start = _r->start + offset + timeline->x_to_ts( X - rx );
|
2008-05-07 20:43:56 +02:00
|
|
|
// nframes_t start = _r->start + offset;
|
|
|
|
nframes_t start = _r->offset + offset;
|
2008-02-16 05:23:58 +01:00
|
|
|
|
2008-04-17 17:19:04 +02:00
|
|
|
/* compensate for ??? */
|
|
|
|
if ( X - rx > 0 )
|
|
|
|
start += timeline->x_to_ts( X - rx );
|
2008-03-26 09:33:14 +01:00
|
|
|
|
2008-04-30 08:40:33 +02:00
|
|
|
const int peaks_needed = min( timeline->ts_to_x( _clip->length() - start ), W );
|
|
|
|
|
2008-05-11 19:18:51 +02:00
|
|
|
const nframes_t end = start + timeline->x_to_ts( peaks_needed );
|
|
|
|
|
2008-04-17 15:27:35 +02:00
|
|
|
if ( _clip->read_peaks( timeline->fpp(),
|
|
|
|
start,
|
2008-05-11 19:18:51 +02:00
|
|
|
end,
|
2008-04-30 02:38:28 +02:00
|
|
|
&peaks, &pbuf, &channels ) &&
|
|
|
|
peaks )
|
2008-03-26 09:33:14 +01:00
|
|
|
{
|
|
|
|
|
2008-04-17 15:27:35 +02:00
|
|
|
assert( pbuf );
|
|
|
|
|
|
|
|
/* draw fade curve outlines--this is only here because of crossfades */
|
|
|
|
draw_fade( _fade_in, Fade::In, true, X, W );
|
|
|
|
draw_fade( _fade_out, Fade::Out, true, X, W );
|
|
|
|
|
|
|
|
int ch = (h() - Fl::box_dh( box() )) / channels;
|
|
|
|
|
2008-05-19 02:42:27 +02:00
|
|
|
Waveform::scale( pbuf, peaks * channels, _scale );
|
2008-04-17 15:27:35 +02:00
|
|
|
|
2008-04-17 18:12:22 +02:00
|
|
|
|
|
|
|
for ( int i = 0; i < channels; ++i )
|
|
|
|
{
|
|
|
|
// Peak *pb = pbuf + (peaks * i);
|
2008-03-26 09:33:14 +01:00
|
|
|
|
2008-04-15 03:08:06 +02:00
|
|
|
/* int fw = timeline->ts_to_x( fade.length ); */
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-15 03:08:06 +02:00
|
|
|
/* /\* if ( draw_fade_waveform ) *\/ */
|
|
|
|
/* for ( int j = min( fw, peaks ); j--; ) */
|
|
|
|
/* { */
|
|
|
|
/* const float g = fade.gain( j * timeline->fpp() ); */
|
|
|
|
/* pb[ j ].min *= g; */
|
|
|
|
/* pb[ j ].max *= g; */
|
|
|
|
/* } */
|
2008-04-14 12:00:08 +02:00
|
|
|
|
2008-04-17 17:35:20 +02:00
|
|
|
Waveform::draw( X,
|
2008-04-17 17:19:04 +02:00
|
|
|
(y() + Fl::box_dy( box() )) + (i * ch),
|
2008-04-17 17:35:20 +02:00
|
|
|
W,
|
2008-04-17 17:19:04 +02:00
|
|
|
ch,
|
2008-04-17 18:12:22 +02:00
|
|
|
pbuf + i, peaks, channels,
|
2008-04-17 15:27:35 +02:00
|
|
|
selected() ? fl_invert_color( _color ) : _color );
|
|
|
|
}
|
|
|
|
}
|
2008-04-14 10:55:22 +02:00
|
|
|
|
2008-04-30 08:40:33 +02:00
|
|
|
if ( peaks < peaks_needed )
|
2008-04-30 02:38:28 +02:00
|
|
|
{
|
|
|
|
/* couldn't read peaks--perhaps they're being generated. Try again later. */
|
2008-05-11 19:18:51 +02:00
|
|
|
Fl::add_timeout( 0.1f, &Audio_Region::peaks_pending_cb,
|
|
|
|
new Peaks_Redraw_Request( this, start + timeline->x_to_ts( peaks ), end ) );
|
2008-04-30 02:38:28 +02:00
|
|
|
}
|
|
|
|
|
2008-04-30 23:03:58 +02:00
|
|
|
timeline->draw_measure_lines( X, Y, W, H, _box_color );
|
2008-02-20 13:45:02 +01:00
|
|
|
|
2008-04-27 07:11:00 +02:00
|
|
|
/* fl_color( FL_BLACK ); */
|
|
|
|
/* fl_line( rx, Y, rx, Y + H ); */
|
|
|
|
/* fl_line( rx + rw - 1, Y, rx + rw - 1, Y + H ); */
|
2008-02-16 05:23:58 +01:00
|
|
|
|
2008-02-22 09:51:22 +01:00
|
|
|
draw_label( _clip->name(), align() );
|
|
|
|
|
2008-04-28 08:34:33 +02:00
|
|
|
/* if ( current() ) */
|
|
|
|
/* { */
|
|
|
|
/* /\* draw length bubble *\/ */
|
2008-03-26 09:33:14 +01:00
|
|
|
|
2008-04-28 08:34:33 +02:00
|
|
|
/* char pat[40]; */
|
2008-03-06 04:24:31 +01:00
|
|
|
|
2008-04-28 08:34:33 +02:00
|
|
|
/* snprintf( pat, sizeof( pat ), "%dm:%.1fs", (int)(length() / timeline->sample_rate()) / 60, (double)length() / timeline->sample_rate() ); */
|
2008-02-20 11:45:10 +01:00
|
|
|
|
2008-04-28 08:34:33 +02:00
|
|
|
/* draw_label( pat, (Fl_Align)(FL_ALIGN_INSIDE | FL_ALIGN_CENTER), FL_GREEN ); */
|
|
|
|
/* } */
|
2008-02-21 08:38:31 +01:00
|
|
|
|
2008-04-17 17:35:20 +02:00
|
|
|
fl_pop_clip();
|
2008-02-20 11:45:10 +01:00
|
|
|
|
2008-02-14 08:40:47 +01:00
|
|
|
}
|
2008-02-21 03:10:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::normalize ( void )
|
2008-02-21 03:10:44 +01:00
|
|
|
{
|
2008-05-01 09:13:58 +02:00
|
|
|
int peaks, channels;
|
|
|
|
Peak *pbuf;
|
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
if ( _clip->read_peaks( length(), offset(), offset() + length(), &peaks, &pbuf, &channels ) &&
|
2008-05-01 09:13:58 +02:00
|
|
|
peaks )
|
|
|
|
_scale = pbuf->normalization_factor();
|
2008-02-21 13:57:33 +01:00
|
|
|
}
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-14 06:01:08 +02:00
|
|
|
|
2008-04-14 10:55:22 +02:00
|
|
|
|
|
|
|
|
2008-04-14 06:01:08 +02:00
|
|
|
/**********/
|
|
|
|
/* Engine */
|
|
|
|
/**********/
|
|
|
|
|
|
|
|
|
2008-04-21 21:16:12 +02:00
|
|
|
/** Apply a (portion of) fade from /start/ to /end/ assuming a
|
2008-04-14 06:01:08 +02:00
|
|
|
* buffer size of /nframes/. /start/ and /end/ are relative to the
|
|
|
|
* given buffer, and /start/ may be negative. */
|
2008-04-15 01:50:01 +02:00
|
|
|
void
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::Fade::apply ( sample_t *buf, Audio_Region::Fade::fade_dir_e dir, long start, nframes_t end, nframes_t nframes ) const
|
2008-04-14 06:01:08 +02:00
|
|
|
{
|
2008-04-16 07:50:32 +02:00
|
|
|
// printf( "apply fade %s: start=%ld end=%lu\n", dir == Fade::Out ? "out" : "in", start, end );
|
2008-04-14 06:01:08 +02:00
|
|
|
|
2008-04-21 21:16:12 +02:00
|
|
|
if ( ! nframes )
|
|
|
|
return;
|
|
|
|
|
2008-04-16 07:50:32 +02:00
|
|
|
const nframes_t i = start > 0 ? start : 0;
|
|
|
|
const nframes_t e = end > nframes ? nframes : end;
|
|
|
|
|
2008-04-21 21:16:12 +02:00
|
|
|
assert( i < nframes );
|
|
|
|
|
2008-04-16 07:50:32 +02:00
|
|
|
const float inc = increment();
|
|
|
|
float fi = ( i - start ) / (float)length;
|
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
// buf += i;
|
|
|
|
buf = &buf[ i ];
|
2008-04-16 07:50:32 +02:00
|
|
|
|
|
|
|
nframes_t n = e - i;
|
2008-04-14 06:01:08 +02:00
|
|
|
|
2008-04-16 20:08:00 +02:00
|
|
|
assert( i + n <= nframes );
|
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
if ( dir == Fade::Out )
|
2008-04-16 07:50:32 +02:00
|
|
|
{
|
|
|
|
fi = 1.0f - fi;
|
|
|
|
for ( ; n--; fi -= inc )
|
|
|
|
*(buf++) *= gain( fi );
|
|
|
|
}
|
2008-04-14 06:01:08 +02:00
|
|
|
else
|
2008-04-16 07:50:32 +02:00
|
|
|
for ( ; n--; fi += inc )
|
|
|
|
*(buf++) *= gain( fi );
|
2008-04-14 06:01:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* THREAD: IO */
|
2008-04-07 09:29:30 +02:00
|
|
|
/** read the overlapping part of /channel/ at /pos/ for /nframes/ of
|
|
|
|
this region into /buf/, where /pos/ is in timeline frames */
|
|
|
|
/* this runs in the diskstream thread. */
|
|
|
|
/* FIXME: it is far more efficient to read all the channels from a
|
2008-04-16 07:50:32 +02:00
|
|
|
multichannel source at once... But how should we handle the case of a
|
|
|
|
mismatch between the number of channels in this region's source and
|
|
|
|
the number of channels on the track/buffer this data is being read
|
|
|
|
for? Would it not be better to simply buffer and deinterlace the
|
|
|
|
frames in the Audio_File class instead, so that sequential requests
|
|
|
|
for different channels at the same position avoid hitting the disk
|
|
|
|
again? */
|
2008-04-07 09:29:30 +02:00
|
|
|
nframes_t
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) const
|
2008-04-07 09:29:30 +02:00
|
|
|
{
|
2008-04-13 00:55:25 +02:00
|
|
|
const Range r = _range;
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-09 02:05:15 +02:00
|
|
|
/* do nothing if we aren't covered by this frame range */
|
2008-05-07 20:43:56 +02:00
|
|
|
if ( pos > r.start + r.length || pos + nframes < r.start )
|
2008-04-07 09:29:30 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* calculate offsets into file and sample buffer */
|
|
|
|
|
|
|
|
nframes_t sofs, ofs, cnt;
|
|
|
|
|
2008-04-09 04:20:44 +02:00
|
|
|
cnt = nframes;
|
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
if ( pos < r.start )
|
2008-04-07 09:29:30 +02:00
|
|
|
{
|
|
|
|
sofs = 0;
|
2008-05-07 20:43:56 +02:00
|
|
|
ofs = r.start - pos;
|
2008-04-09 04:20:44 +02:00
|
|
|
cnt -= ofs;
|
2008-04-07 09:29:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ofs = 0;
|
2008-05-07 20:43:56 +02:00
|
|
|
sofs = pos - r.start;
|
2008-04-07 09:29:30 +02:00
|
|
|
}
|
|
|
|
|
2008-04-09 04:20:44 +02:00
|
|
|
if ( ofs >= nframes )
|
2008-04-07 09:29:30 +02:00
|
|
|
return 0;
|
|
|
|
|
2008-04-09 04:20:44 +02:00
|
|
|
// const nframes_t start = ofs + r.start + sofs;
|
2008-05-07 20:43:56 +02:00
|
|
|
const nframes_t start = r.offset + sofs;
|
2008-04-09 02:05:15 +02:00
|
|
|
const nframes_t len = min( cnt, nframes - ofs );
|
2008-04-07 09:29:30 +02:00
|
|
|
const nframes_t end = start + len;
|
|
|
|
|
|
|
|
if ( len == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* now that we know how much and where to read, get on with it */
|
|
|
|
|
2008-04-09 04:20:44 +02:00
|
|
|
// printf( "reading region ofs = %lu, sofs = %lu, %lu-%lu\n", ofs, sofs, start, end );
|
|
|
|
|
2008-04-07 09:29:30 +02:00
|
|
|
cnt = _clip->read( buf + ofs, channel, start, end );
|
|
|
|
|
|
|
|
/* apply gain */
|
|
|
|
|
2008-04-27 07:21:19 +02:00
|
|
|
buffer_apply_gain( buf + ofs, cnt, _scale );
|
2008-04-09 04:20:44 +02:00
|
|
|
|
2008-04-14 06:01:08 +02:00
|
|
|
/* perform declicking if necessary */
|
|
|
|
|
2008-04-14 07:12:05 +02:00
|
|
|
/* FIXME: keep the declick defults someplace else */
|
|
|
|
Fade declick;
|
|
|
|
|
|
|
|
declick.length = 256;
|
2008-04-15 01:50:01 +02:00
|
|
|
declick.type = Fade::Linear;
|
2008-04-14 06:01:08 +02:00
|
|
|
|
|
|
|
{
|
2008-04-14 07:12:05 +02:00
|
|
|
Fade fade;
|
2008-04-14 06:01:08 +02:00
|
|
|
|
2008-04-14 07:12:05 +02:00
|
|
|
fade = declick < _fade_in ? _fade_in : declick;
|
2008-04-14 06:01:08 +02:00
|
|
|
|
2008-04-14 07:12:05 +02:00
|
|
|
/* do fade in if necessary */
|
|
|
|
if ( sofs < fade.length )
|
|
|
|
{
|
|
|
|
const long d = 0 - sofs;
|
2008-04-14 06:01:08 +02:00
|
|
|
|
2008-04-27 07:21:19 +02:00
|
|
|
assert( cnt <= nframes );
|
|
|
|
|
|
|
|
fade.apply( buf + ofs, Fade::In, d, d + fade.length, cnt );
|
2008-04-14 07:12:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fade = declick < _fade_out ? _fade_out : declick;
|
2008-04-14 06:01:08 +02:00
|
|
|
|
2008-04-14 07:12:05 +02:00
|
|
|
/* do fade out if necessary */
|
2008-04-21 21:16:12 +02:00
|
|
|
// if ( start + cnt + fade.length > r.end )
|
2008-05-07 20:43:56 +02:00
|
|
|
if ( start + fade.length > ( r.offset + r.length ) )
|
2008-04-14 07:12:05 +02:00
|
|
|
{
|
2008-05-07 20:43:56 +02:00
|
|
|
const nframes_t d = ( r.offset + r.length ) - start;
|
2008-04-14 07:12:05 +02:00
|
|
|
|
2008-04-27 07:21:19 +02:00
|
|
|
assert( cnt <= nframes );
|
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
fade.apply( buf, Fade::Out, cnt + (long)d - fade.length, cnt + d, cnt );
|
2008-04-14 07:12:05 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-09 04:20:44 +02:00
|
|
|
// printf( "read %lu frames\n", cnt );
|
2008-04-07 09:29:30 +02:00
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
2008-04-18 05:44:19 +02:00
|
|
|
|
|
|
|
|
2008-05-11 03:10:16 +02:00
|
|
|
/** prepare for capturing */
|
|
|
|
void
|
|
|
|
Audio_Region::prepare ( void )
|
|
|
|
{
|
|
|
|
log_start();
|
|
|
|
}
|
|
|
|
|
2008-04-18 05:44:19 +02:00
|
|
|
/* THREAD: IO */
|
|
|
|
/** write /nframes/ from /buf/ to source. /buf/ is interleaved and
|
|
|
|
must match the channel layout of the write source! */
|
|
|
|
nframes_t
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::write ( nframes_t nframes )
|
2008-04-18 05:44:19 +02:00
|
|
|
{
|
2008-05-07 20:43:56 +02:00
|
|
|
_range.length += nframes;
|
2008-04-18 05:44:19 +02:00
|
|
|
|
|
|
|
/* FIXME: too much? */
|
|
|
|
// _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), 10/* FIXME: guess */, h() );
|
2008-04-25 10:14:13 +02:00
|
|
|
|
2008-05-07 20:43:56 +02:00
|
|
|
if ( 0 == ( timeline->ts_to_x( _range.length ) % 20 ) )
|
2008-04-26 08:33:44 +02:00
|
|
|
{
|
2008-04-30 01:48:11 +02:00
|
|
|
nframes_t oldl = _clip->length();
|
|
|
|
|
2008-05-12 00:48:19 +02:00
|
|
|
/* get the new size. Remember, this is a read-only handle on the source--not the same
|
|
|
|
one being written to */
|
2008-04-26 08:33:44 +02:00
|
|
|
_clip->close();
|
|
|
|
_clip->open();
|
|
|
|
|
2008-04-30 01:48:11 +02:00
|
|
|
int W = timeline->ts_to_x( _clip->length() - oldl );
|
|
|
|
|
|
|
|
/* why - 1? */
|
|
|
|
|
|
|
|
if ( W )
|
|
|
|
{
|
|
|
|
++W;
|
2008-05-19 07:07:42 +02:00
|
|
|
Fl::lock();
|
2008-05-07 18:42:31 +02:00
|
|
|
sequence()->damage( FL_DAMAGE_ALL, x() + w() - W, y(), W, h() );
|
2008-05-19 07:07:42 +02:00
|
|
|
Fl::awake();
|
|
|
|
Fl::unlock();
|
2008-04-30 01:48:11 +02:00
|
|
|
}
|
2008-04-26 08:33:44 +02:00
|
|
|
}
|
2008-04-18 05:44:19 +02:00
|
|
|
|
2008-04-26 08:33:44 +02:00
|
|
|
return nframes;
|
2008-04-18 05:44:19 +02:00
|
|
|
}
|
2008-04-19 21:21:49 +02:00
|
|
|
|
2008-05-12 00:48:19 +02:00
|
|
|
/* THREAD: IO */
|
2008-04-19 21:21:49 +02:00
|
|
|
/** finalize region capture. Assumes that this *is* a captured region
|
|
|
|
and that no other regions refer to the same source */
|
|
|
|
bool
|
2008-05-05 02:04:20 +02:00
|
|
|
Audio_Region::finalize ( nframes_t frame )
|
2008-04-19 21:21:49 +02:00
|
|
|
{
|
2008-05-17 07:14:26 +02:00
|
|
|
_range.length = frame - _range.start;
|
|
|
|
|
2008-04-25 09:35:55 +02:00
|
|
|
log_end();
|
|
|
|
|
2008-04-19 21:21:49 +02:00
|
|
|
_clip->close();
|
|
|
|
_clip->open();
|
|
|
|
|
2008-05-02 01:35:46 +02:00
|
|
|
/* FIXME: should we attempt to truncate the file? */
|
|
|
|
|
|
|
|
redraw();
|
2008-04-30 01:48:11 +02:00
|
|
|
|
2008-04-19 21:21:49 +02:00
|
|
|
return true;
|
|
|
|
}
|