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. */
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
#include <FL/Fl.H>
|
2008-02-16 04:50:16 +01:00
|
|
|
|
#include <FL/Fl_Widget.H>
|
2008-04-15 13:44:03 +02:00
|
|
|
|
#include <FL/Fl_Menu_Item.H>
|
2008-05-29 08:11:35 +02:00
|
|
|
|
#include <FL/fl_show_colormap.H>
|
2008-02-14 08:40:47 +01:00
|
|
|
|
|
2008-05-22 09:05:49 +02:00
|
|
|
|
#include "Sequence.H"
|
|
|
|
|
#include "Audio_Region.H"
|
|
|
|
|
#include "Timeline.H"
|
|
|
|
|
#include "Waveform.H"
|
|
|
|
|
#include "Audio_Sequence.H"
|
|
|
|
|
#include "Track.H"
|
|
|
|
|
|
|
|
|
|
#include "Engine/Audio_File.H"
|
2012-03-18 21:21:57 +01:00
|
|
|
|
#include "Transport.H"
|
2008-07-30 04:30:45 +02:00
|
|
|
|
#include "const.h"
|
2010-02-01 07:25:16 +01:00
|
|
|
|
#include "debug.h"
|
2008-07-30 04:30:45 +02:00
|
|
|
|
|
2008-02-20 06:57:14 +01:00
|
|
|
|
#include <algorithm>
|
2008-05-22 22:58:36 +02:00
|
|
|
|
using std::min;
|
|
|
|
|
using std::max;
|
2008-03-26 09:33:14 +01:00
|
|
|
|
|
2008-05-26 07:46:37 +02:00
|
|
|
|
|
|
|
|
|
|
2012-03-02 09:53:10 +01:00
|
|
|
|
/* defined in timeline.C */
|
|
|
|
|
extern void draw_full_arrow_symbol ( Fl_Color color );
|
|
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
|
extern Timeline *timeline;
|
2012-03-18 21:21:57 +01:00
|
|
|
|
extern Transport *transport;
|
2008-02-17 00:12:23 +01:00
|
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
|
bool Audio_Region::inherit_track_color = true;
|
2012-04-26 05:31:55 +02:00
|
|
|
|
bool Audio_Region::show_box = true;
|
2008-04-14 10:55:22 +02:00
|
|
|
|
|
2012-05-01 12:03:48 +02:00
|
|
|
|
Fl_Boxtype Audio_Region::_box = FL_FLAT_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-05-26 07:46:37 +02: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-06-19 06:14:14 +02:00
|
|
|
|
|
2008-02-21 10:48:53 +01:00
|
|
|
|
|
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 );
|
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-05-31 20:31:06 +02:00
|
|
|
|
e.add( ":loop", _loop );
|
2008-05-07 20:43:56 +02:00
|
|
|
|
}
|
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, ":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 );
|
2008-05-31 20:31:06 +02:00
|
|
|
|
else if ( ! strcmp( s, ":loop" ) )
|
|
|
|
|
_loop = atoll( v );
|
2008-05-07 20:43:56 +02:00
|
|
|
|
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
|
|
|
|
{
|
2012-06-05 02:24:57 +02:00
|
|
|
|
_adjusting_gain = 0;
|
2008-05-31 20:31:06 +02:00
|
|
|
|
_loop = 0;
|
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
|
|
|
|
|
2012-06-07 08:45:07 +02:00
|
|
|
|
_color = FL_FOREGROUND_COLOR;
|
|
|
|
|
_box_color = FL_GRAY;
|
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-07-15 06:29:47 +02:00
|
|
|
|
_clip = rhs._clip->duplicate();
|
2008-03-01 16:25:27 +01:00
|
|
|
|
_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-05-31 20:31:06 +02:00
|
|
|
|
_loop = rhs._loop;
|
|
|
|
|
|
2012-06-05 02:24:57 +02:00
|
|
|
|
_box_color = rhs._box_color;
|
|
|
|
|
_color = rhs._color;
|
|
|
|
|
|
|
|
|
|
_adjusting_gain = false;
|
|
|
|
|
|
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-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);
|
|
|
|
|
|
2012-06-07 08:45:07 +02:00
|
|
|
|
_box_color = (Fl_Color)sum;
|
2008-03-01 16:25:27 +01:00
|
|
|
|
|
2008-02-28 13:51:51 +01:00
|
|
|
|
log_create();
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
Audio_Region::~Audio_Region ( )
|
2008-05-22 09:05:49 +02:00
|
|
|
|
{
|
2008-06-19 06:14:14 +02:00
|
|
|
|
log_destroy();
|
2008-07-15 06:29:47 +02:00
|
|
|
|
|
|
|
|
|
_clip->release();
|
2008-05-22 09:05:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
|
|
|
|
|
|
2008-05-29 08:11:35 +02:00
|
|
|
|
void
|
|
|
|
|
Audio_Region::menu_cb ( Fl_Widget *w, void *v )
|
|
|
|
|
{
|
|
|
|
|
((Audio_Region*)v)->menu_cb( (Fl_Menu_*) w );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Audio_Region::menu_cb ( const Fl_Menu_ *m )
|
|
|
|
|
{
|
|
|
|
|
char picked[256];
|
|
|
|
|
|
|
|
|
|
m->item_pathname( picked, sizeof( picked ) );
|
|
|
|
|
|
|
|
|
|
Logger log( this );
|
|
|
|
|
|
|
|
|
|
if ( ! strcmp( picked, "Fade/In/Linear" ) )
|
|
|
|
|
_fade_in.type = Fade::Linear;
|
|
|
|
|
else if ( ! strcmp( picked, "Fade/In/Sigmoid" ) )
|
|
|
|
|
_fade_in.type = Fade::Sigmoid;
|
|
|
|
|
else if ( ! strcmp( picked, "Fade/In/Logarithmic" ) )
|
|
|
|
|
_fade_in.type = Fade::Logarithmic;
|
|
|
|
|
else if ( ! strcmp( picked, "Fade/In/Parabolic" ) )
|
|
|
|
|
_fade_in.type = Fade::Parabolic;
|
|
|
|
|
else if ( ! strcmp( picked, "Fade/Out/Linear" ) )
|
|
|
|
|
_fade_out.type = Fade::Linear;
|
|
|
|
|
else if ( ! strcmp( picked, "Fade/Out/Sigmoid" ) )
|
|
|
|
|
_fade_out.type = Fade::Sigmoid;
|
|
|
|
|
else if ( ! strcmp( picked, "Fade/Out/Logarithmic" ) )
|
|
|
|
|
_fade_out.type = Fade::Logarithmic;
|
|
|
|
|
else if ( ! strcmp( picked, "Fade/Out/Parabolic" ) )
|
|
|
|
|
_fade_out.type = Fade::Parabolic;
|
|
|
|
|
else if ( ! strcmp( picked, "/Color" ) )
|
|
|
|
|
box_color( fl_show_colormap( box_color() ) );
|
2012-03-18 21:21:57 +01:00
|
|
|
|
else if ( ! strcmp( picked, "/Split at mouse" ) )
|
|
|
|
|
{
|
|
|
|
|
Loggable::block_start();
|
|
|
|
|
|
|
|
|
|
split( timeline->x_to_offset( Fl::event_x() ) );
|
|
|
|
|
|
|
|
|
|
log_end();
|
|
|
|
|
|
|
|
|
|
Loggable::block_end();
|
|
|
|
|
|
|
|
|
|
log_start();
|
|
|
|
|
}
|
|
|
|
|
else if ( ! strcmp( picked, "/Crop to range" ) )
|
|
|
|
|
{
|
|
|
|
|
trim_left( timeline->range_start() );
|
|
|
|
|
trim_right( timeline->range_end() );
|
|
|
|
|
}
|
2008-05-29 08:11:35 +02:00
|
|
|
|
else if ( ! strcmp( picked, "/Fade in to mouse" ) )
|
|
|
|
|
{
|
|
|
|
|
nframes_t offset = x_to_offset( Fl::event_x() );
|
|
|
|
|
|
|
|
|
|
if ( offset < length() )
|
|
|
|
|
_fade_in.length = offset;
|
|
|
|
|
|
|
|
|
|
DMESSAGE( "set fade in duration" );
|
|
|
|
|
}
|
|
|
|
|
else if ( ! strcmp( picked, "/Fade out to mouse" ) )
|
|
|
|
|
{
|
|
|
|
|
long offset = length() - x_to_offset( Fl::event_x() );
|
|
|
|
|
|
|
|
|
|
if ( offset > 0 )
|
|
|
|
|
_fade_out.length = offset;
|
|
|
|
|
}
|
2012-06-05 02:24:57 +02:00
|
|
|
|
else if ( ! strcmp( picked, "/Gain with mouse vertical drag" ) )
|
|
|
|
|
{
|
|
|
|
|
/* float g = h() / (y() - Fl::event_y() ); */
|
|
|
|
|
|
|
|
|
|
/* _scale = g; */
|
|
|
|
|
}
|
2008-05-31 23:12:21 +02:00
|
|
|
|
else if ( ! strcmp( picked, "/Loop point to mouse" ) )
|
2008-05-31 20:31:06 +02:00
|
|
|
|
{
|
|
|
|
|
nframes_t offset = x_to_offset( Fl::event_x() );
|
|
|
|
|
|
2008-05-31 22:29:01 +02:00
|
|
|
|
if ( offset > 0 )
|
2008-05-31 23:12:21 +02:00
|
|
|
|
{
|
|
|
|
|
nframes_t f = offset + _r->start;
|
|
|
|
|
|
2008-07-02 05:19:31 +02:00
|
|
|
|
if ( timeline->nearest_line( &f, false ) )
|
2008-05-31 23:12:21 +02:00
|
|
|
|
_loop = f - _r->start;
|
|
|
|
|
else
|
|
|
|
|
_loop = offset;
|
|
|
|
|
}
|
2008-05-31 20:31:06 +02:00
|
|
|
|
}
|
2008-05-31 23:12:21 +02:00
|
|
|
|
else if ( ! strcmp( picked, "/Clear loop point" ) )
|
|
|
|
|
_loop = 0;
|
2008-06-23 03:03:22 +02:00
|
|
|
|
else if ( ! strcmp( picked, "/Normalize" ) )
|
|
|
|
|
normalize();
|
2008-12-27 23:35:22 +01:00
|
|
|
|
else if ( ! strcmp( picked, "/Denormalize" ) )
|
|
|
|
|
_scale = 1.0;
|
2008-07-22 05:20:38 +02:00
|
|
|
|
else if ( ! strcmp( picked, "/Range from" ) )
|
|
|
|
|
timeline->range( start(), length() );
|
2008-06-23 03:03:22 +02:00
|
|
|
|
else if ( ! strcmp( picked, "/Remove" ) )
|
|
|
|
|
remove();
|
2008-05-29 08:11:35 +02:00
|
|
|
|
else
|
|
|
|
|
FATAL( "Unknown menu choice \"%s\"", picked );
|
|
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-27 02:03:31 +02:00
|
|
|
|
#include "FL/test_press.H"
|
2008-05-31 01:48:44 +02:00
|
|
|
|
#include "FL/menu_popup.H"
|
2008-02-20 06:57:14 +01:00
|
|
|
|
|
2008-05-29 08:11:35 +02:00
|
|
|
|
/** build the context menu for this region */
|
2008-05-30 05:34:42 +02:00
|
|
|
|
Fl_Menu_Button &
|
|
|
|
|
Audio_Region::menu ( void )
|
2008-05-29 08:11:35 +02:00
|
|
|
|
{
|
2008-05-30 05:34:42 +02:00
|
|
|
|
static Fl_Menu_Button m( 0, 0, 0, 0, "Region" );
|
2008-05-29 08:11:35 +02:00
|
|
|
|
|
|
|
|
|
Fade::fade_type_e it = _fade_in.type;
|
|
|
|
|
Fade::fade_type_e ot = _fade_out.type;
|
|
|
|
|
|
|
|
|
|
Fl_Menu_Item items[] =
|
|
|
|
|
{
|
2008-05-31 01:48:44 +02:00
|
|
|
|
{ "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 ) },
|
2008-05-29 08:11:35 +02:00
|
|
|
|
{ 0 },
|
2008-05-31 01:48:44 +02:00
|
|
|
|
{ "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 ) },
|
2008-06-24 05:47:53 +02:00
|
|
|
|
{ "Logarithmic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
|
2008-05-31 01:48:44 +02:00
|
|
|
|
{ "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
|
2008-05-29 08:11:35 +02:00
|
|
|
|
{ 0 },
|
|
|
|
|
{ 0 },
|
2008-05-31 01:48:44 +02:00
|
|
|
|
{ "Color", 0, 0, 0, inherit_track_color ? FL_MENU_INACTIVE : 0 },
|
2012-03-18 21:21:57 +01:00
|
|
|
|
{ "Split at mouse", 's', 0, 0 },
|
|
|
|
|
{ "Crop to range", 'c', 0, 0 },
|
2012-06-05 02:24:57 +02:00
|
|
|
|
{ "Gain with mouse vertical drag", 'g', 0, 0 },
|
2008-05-31 01:48:44 +02:00
|
|
|
|
{ "Fade in to mouse", FL_F + 3, 0, 0 },
|
|
|
|
|
{ "Fade out to mouse", FL_F + 4, 0, 0 },
|
2008-05-31 23:12:21 +02:00
|
|
|
|
{ "Loop point to mouse", 'l', 0, 0 },
|
2008-12-28 07:11:52 +01:00
|
|
|
|
{ "Clear loop point", FL_SHIFT + 'l', 0, 0, 0 == _loop ? FL_MENU_INACTIVE : 0 },
|
2008-06-23 03:03:22 +02:00
|
|
|
|
{ "Normalize", 'n', 0, 0 },
|
2008-12-28 07:11:52 +01:00
|
|
|
|
{ "Denormalize", FL_SHIFT + 'n', 0, 0, 1.0 == _scale ? FL_MENU_INACTIVE : 0 },
|
2008-07-22 05:20:38 +02:00
|
|
|
|
{ "Range from", FL_CTRL + 'r', 0, 0 },
|
2008-06-23 03:03:22 +02:00
|
|
|
|
{ "Remove", 0, 0, 0 },
|
2008-05-29 08:11:35 +02:00
|
|
|
|
{ 0 },
|
|
|
|
|
};
|
|
|
|
|
|
2008-05-31 01:48:44 +02:00
|
|
|
|
menu_set_callback( items, &Audio_Region::menu_cb, (void*)this );
|
|
|
|
|
|
2008-05-30 05:34:42 +02:00
|
|
|
|
m.copy( items, (void*)this );
|
|
|
|
|
|
|
|
|
|
return m;
|
2008-05-29 08:11:35 +02: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
|
|
|
|
|
2012-06-05 02:24:57 +02:00
|
|
|
|
if ( width < 4 )
|
2012-05-21 05:59:13 +02:00
|
|
|
|
/* too small to draw */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int fx;
|
|
|
|
|
|
2008-04-15 01:50:01 +02:00
|
|
|
|
if ( dir == Fade::In )
|
2012-05-21 05:59:13 +02:00
|
|
|
|
{
|
|
|
|
|
fx = line_x();
|
|
|
|
|
|
|
|
|
|
if ( fx + width < X ||
|
2012-06-05 02:24:57 +02:00
|
|
|
|
fx > X + W )
|
2012-05-21 05:59:13 +02:00
|
|
|
|
/* clipped */
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-02-21 08:38:31 +01:00
|
|
|
|
else
|
2008-04-14 12:00:08 +02:00
|
|
|
|
{
|
2012-05-21 05:59:13 +02:00
|
|
|
|
fx = line_x() + abs_w();
|
|
|
|
|
|
|
|
|
|
if ( fx - width > X + W ||
|
|
|
|
|
fx < X )
|
|
|
|
|
/* clipped */
|
|
|
|
|
return;
|
2008-04-15 01:50:01 +02:00
|
|
|
|
}
|
2008-04-15 10:53:36 +02:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-06-05 02:25:21 +02:00
|
|
|
|
fl_vertex( fx, dy );
|
|
|
|
|
fl_vertex( fx, dy + height );
|
2008-04-16 07:50:32 +02:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
nframes_t tsx = timeline->x_to_ts( 1 );
|
|
|
|
|
|
2012-06-05 02:25:21 +02:00
|
|
|
|
if ( dir == Fade::In )
|
|
|
|
|
{
|
|
|
|
|
nframes_t ts = 0;
|
2008-04-16 07:50:32 +02:00
|
|
|
|
|
2012-06-05 02:25:21 +02:00
|
|
|
|
for ( int i = 0; i < width; ++i, ts += tsx )
|
|
|
|
|
fl_vertex( fx + i, dy + height - ( height * fade.gain( ts / (double)fade.length ) ));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nframes_t ts = tsx * width;
|
2008-04-14 12:00:08 +02:00
|
|
|
|
|
2012-06-05 02:25:21 +02:00
|
|
|
|
for ( int i = 0; i < width; ++i, ts -= tsx )
|
|
|
|
|
fl_vertex( fx - i, dy + ( height * fade.gain( ts / (double)fade.length ) ));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( dir == Fade::In )
|
|
|
|
|
fl_vertex( fx + width, dy );
|
|
|
|
|
else
|
|
|
|
|
fl_vertex( fx - width, dy );
|
2008-04-15 16:01:21 +02:00
|
|
|
|
|
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 01:50:01 +02:00
|
|
|
|
}
|
2008-04-14 12:00:08 +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
|
|
|
|
{
|
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
|
|
|
|
|
2012-06-19 06:27:59 +02:00
|
|
|
|
if ( recording() )
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-26 05:31:55 +02:00
|
|
|
|
Fl_Boxtype b;
|
2012-06-07 09:29:54 +02:00
|
|
|
|
Fl_Color c = selected() ? selection_color : color;
|
2012-04-26 05:31:55 +02:00
|
|
|
|
|
|
|
|
|
if ( Audio_Region::show_box )
|
|
|
|
|
{
|
|
|
|
|
b = box();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
b = FL_DOWN_FRAME;
|
|
|
|
|
}
|
2008-04-14 12:00:08 +02:00
|
|
|
|
|
2012-06-07 09:29:54 +02:00
|
|
|
|
fl_draw_box( b, x(), y(), w(), h(), c );
|
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
|
|
|
|
|
2012-06-05 02:14:37 +02:00
|
|
|
|
void
|
|
|
|
|
Audio_Region::peaks_ready_callback ( void *v )
|
|
|
|
|
{
|
2012-06-07 08:45:07 +02:00
|
|
|
|
DMESSAGE("Damaging region from peaks ready callback");
|
2012-06-05 02:14:37 +02:00
|
|
|
|
Fl::lock();
|
|
|
|
|
((Audio_Region*)v)->redraw();
|
|
|
|
|
Fl::unlock();
|
|
|
|
|
Fl::awake();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-19 06:27:59 +02:00
|
|
|
|
bool
|
|
|
|
|
Audio_Region::recording ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return this == sequence()->track()->capture_region();
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
|
2008-07-06 05:33:25 +02:00
|
|
|
|
if ( start() > timeline->xoffset + timeline->x_to_ts( sequence()->w() ) ||
|
|
|
|
|
start() + length() < timeline->xoffset )
|
2008-04-17 15:27:35 +02:00
|
|
|
|
/* not in viewport */
|
2008-02-20 11:45:10 +01:00
|
|
|
|
return;
|
|
|
|
|
|
2008-07-06 05:33:25 +02:00
|
|
|
|
fl_push_clip( X, Y, W, H );
|
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
/* overdraw a little to avoid artifacts when scrolling */
|
|
|
|
|
W += 2;
|
2008-06-30 06:33:37 +02:00
|
|
|
|
|
2012-04-02 03:27:27 +02:00
|
|
|
|
Fl_Color c = selected() ? fl_invert_color( _color ) : _color;
|
|
|
|
|
|
2012-06-19 06:27:59 +02:00
|
|
|
|
if ( sequence()->damage() & FL_DAMAGE_USER1 &&
|
|
|
|
|
recording() )
|
2008-02-20 11:45:10 +01:00
|
|
|
|
{
|
2012-06-19 06:27:59 +02:00
|
|
|
|
/* TODO: limit drawing. */
|
2008-02-20 11:45:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
/* calculate waveform offset due to scrolling */
|
|
|
|
|
/* offset is the number of frames into the waveform the value of X translates to */
|
|
|
|
|
nframes_t x_frame = timeline->xoffset + timeline->x_to_ts( X - _sequence->x() );
|
2012-06-14 06:02:25 +02:00
|
|
|
|
nframes_t offset = 0;
|
|
|
|
|
|
|
|
|
|
if ( x_frame < start() )
|
|
|
|
|
/* sometimes X is one pixel too soon... */
|
|
|
|
|
offset = 0;
|
|
|
|
|
else
|
|
|
|
|
offset = x_frame - start();
|
2008-02-20 11:45:10 +01:00
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
nframes_t fo = 0;
|
|
|
|
|
nframes_t ostart = 0, oend = 0;
|
|
|
|
|
const int total_peaks_needed = W;
|
|
|
|
|
nframes_t total_frames_needed = timeline->x_to_ts( total_peaks_needed );
|
2008-02-20 08:53:54 +01:00
|
|
|
|
|
2012-04-26 05:31:55 +02:00
|
|
|
|
{
|
|
|
|
|
Fl_Color c = fl_color_average( FL_DARK1,
|
2012-06-05 02:24:57 +02:00
|
|
|
|
Audio_Region::inherit_track_color ? sequence()->track()->color() : _box_color,
|
|
|
|
|
0.75f );
|
2012-04-26 05:31:55 +02:00
|
|
|
|
|
|
|
|
|
fl_color( fl_color_add_alpha( c, 127 ) );
|
|
|
|
|
|
2012-05-21 05:59:13 +02:00
|
|
|
|
draw_fade( _fade_in, Fade::In, false, X, W );
|
2012-04-26 05:31:55 +02:00
|
|
|
|
draw_fade( _fade_out, Fade::Out, false, X, W );
|
|
|
|
|
}
|
2008-02-20 13:45:02 +01:00
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
int channels = 0;
|
|
|
|
|
int peaks = 0;
|
|
|
|
|
Peak *pbuf = NULL;
|
2008-07-06 05:33:25 +02:00
|
|
|
|
|
2008-06-30 06:33:37 +02:00
|
|
|
|
do {
|
|
|
|
|
nframes_t start = _r->offset;
|
2008-04-30 08:40:33 +02:00
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
nframes_t loop_frames_needed = _loop ? _loop : total_frames_needed;
|
|
|
|
|
int loop_peaks_needed = timeline->ts_to_x( loop_frames_needed );
|
|
|
|
|
|
|
|
|
|
Fl_Color c = Fl::get_color( _color );
|
2008-06-30 06:33:37 +02:00
|
|
|
|
|
2012-06-19 06:27:59 +02:00
|
|
|
|
if ( recording() )
|
2012-04-02 03:27:27 +02:00
|
|
|
|
{
|
2012-06-13 05:53:21 +02:00
|
|
|
|
// loop_peaks_needed = timeline->ts_to_x( _range.length );
|
2012-04-02 03:27:27 +02:00
|
|
|
|
c = FL_BLACK;
|
|
|
|
|
}
|
2012-06-13 05:53:21 +02:00
|
|
|
|
|
|
|
|
|
c = fl_color_add_alpha( c, 220 );
|
2012-04-02 03:27:27 +02:00
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
if ( ! fo ) /* first loop... */
|
2008-06-30 06:33:37 +02:00
|
|
|
|
{
|
|
|
|
|
if ( _loop )
|
|
|
|
|
start += offset % _loop;
|
|
|
|
|
else
|
|
|
|
|
start += offset;
|
|
|
|
|
|
2008-07-06 05:33:25 +02:00
|
|
|
|
/* DMESSAGE( "offset = %lu", (unsigned long) offset ); */
|
|
|
|
|
/* DMESSAGE( "loop peaks needed = %d", loop_peaks_needed ); */
|
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
if ( _loop )
|
|
|
|
|
{
|
|
|
|
|
loop_frames_needed -= offset % loop_frames_needed;
|
|
|
|
|
loop_peaks_needed = timeline->ts_to_x( loop_frames_needed );
|
|
|
|
|
}
|
2008-07-06 05:33:25 +02:00
|
|
|
|
/* DMESSAGE( "loop peaks needed = %d", loop_peaks_needed ); */
|
2008-04-17 15:27:35 +02:00
|
|
|
|
|
2008-07-06 05:33:25 +02:00
|
|
|
|
assert( loop_peaks_needed >= 0 );
|
|
|
|
|
}
|
2008-04-17 15:27:35 +02:00
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
if ( fo + loop_frames_needed > total_frames_needed )
|
2008-07-06 05:33:25 +02:00
|
|
|
|
{
|
2012-06-13 05:53:21 +02:00
|
|
|
|
loop_frames_needed -= ( fo + loop_frames_needed ) - total_frames_needed;
|
|
|
|
|
loop_peaks_needed = timeline->ts_to_x( loop_frames_needed );
|
2008-06-30 06:33:37 +02:00
|
|
|
|
}
|
2008-04-17 15:27:35 +02:00
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
if ( !loop_peaks_needed )
|
2008-07-06 05:33:25 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
const nframes_t end = start + loop_frames_needed;
|
2008-04-17 18:12:22 +02:00
|
|
|
|
|
2008-07-02 06:10:47 +02:00
|
|
|
|
if ( start != ostart || end != oend )
|
|
|
|
|
{
|
2012-06-05 02:14:37 +02:00
|
|
|
|
if ( _clip->peaks()->peakfile_ready() )
|
2008-07-02 06:10:47 +02:00
|
|
|
|
{
|
2012-06-05 02:14:37 +02:00
|
|
|
|
if ( _clip->read_peaks( timeline->fpp(),
|
2012-06-13 05:53:21 +02:00
|
|
|
|
start,
|
|
|
|
|
end,
|
2012-06-05 02:14:37 +02:00
|
|
|
|
&peaks, &pbuf, &channels ) )
|
|
|
|
|
{
|
|
|
|
|
Waveform::scale( pbuf, peaks * channels, _scale );
|
2012-06-13 05:53:21 +02:00
|
|
|
|
|
2012-06-05 02:14:37 +02:00
|
|
|
|
ostart = start;
|
|
|
|
|
oend = end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( ! transport->rolling )
|
|
|
|
|
{
|
|
|
|
|
/* create a thread to make the peaks */
|
|
|
|
|
_clip->peaks()->make_peaks_asynchronously( Audio_Region::peaks_ready_callback, this );
|
|
|
|
|
}
|
2008-07-02 06:10:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// DMESSAGE( "using cached peaks" );
|
|
|
|
|
}
|
2012-06-13 05:53:21 +02:00
|
|
|
|
|
2008-12-27 22:42:27 +01:00
|
|
|
|
if ( peaks && pbuf )
|
2008-04-17 18:12:22 +02:00
|
|
|
|
{
|
2008-06-30 06:33:37 +02:00
|
|
|
|
int ch = (h() - Fl::box_dh( box() )) / channels;
|
2012-06-13 05:53:21 +02:00
|
|
|
|
int xo = timeline->ts_to_x( fo );
|
2008-06-30 06:33:37 +02:00
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < channels; ++i )
|
|
|
|
|
{
|
|
|
|
|
Waveform::draw( X + xo,
|
|
|
|
|
(y() + Fl::box_dy( box() )) + (i * ch),
|
|
|
|
|
loop_peaks_needed,
|
|
|
|
|
ch,
|
|
|
|
|
pbuf + i, peaks, channels,
|
2012-06-05 02:14:37 +02:00
|
|
|
|
c );
|
2008-06-30 06:33:37 +02:00
|
|
|
|
}
|
2008-04-17 15:27:35 +02:00
|
|
|
|
}
|
2012-06-13 05:53:21 +02:00
|
|
|
|
else
|
|
|
|
|
WARNING( "Pbuf == %p, peaks = %lu", pbuf, (unsigned long)peaks );
|
|
|
|
|
|
2008-06-30 06:33:37 +02:00
|
|
|
|
if ( peaks < loop_peaks_needed )
|
|
|
|
|
{
|
2012-06-13 05:53:21 +02:00
|
|
|
|
DMESSAGE( "Peak read came up %lu peaks short", (unsigned long)loop_peaks_needed - peaks );
|
2008-06-30 06:33:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
fo += loop_frames_needed;
|
2008-05-31 20:31:06 +02:00
|
|
|
|
}
|
2012-06-13 05:53:21 +02:00
|
|
|
|
while ( _loop && fo < total_frames_needed );
|
2008-05-31 20:31:06 +02:00
|
|
|
|
|
2012-06-13 05:53:21 +02:00
|
|
|
|
|
2012-06-06 02:31:23 +02:00
|
|
|
|
if ( _loop && offset < _loop )
|
|
|
|
|
{
|
2012-06-13 05:53:21 +02:00
|
|
|
|
const int lx = get_x( start() + _loop );
|
2012-06-06 02:31:23 +02:00
|
|
|
|
|
|
|
|
|
if ( lx < X + W )
|
|
|
|
|
{
|
|
|
|
|
fl_color( FL_RED );
|
|
|
|
|
fl_line_style( FL_DASH, 0 );
|
2012-06-13 05:53:21 +02:00
|
|
|
|
fl_line( lx, y(), lx, y() + h() );
|
2012-06-06 02:31:23 +02:00
|
|
|
|
fl_line_style( FL_SOLID, 0 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-05 02:24:57 +02:00
|
|
|
|
if ( _adjusting_gain )
|
|
|
|
|
{
|
|
|
|
|
fl_color( fl_color_add_alpha( FL_DARK1, 127 ) );
|
|
|
|
|
|
|
|
|
|
fl_rectf( X, ( y() + h() ) - ( h() * ( _scale * 0.25 ) ), X + W, y() + h() );
|
|
|
|
|
|
|
|
|
|
fl_line_style( FL_DASH, 1 );
|
|
|
|
|
|
|
|
|
|
fl_color( fl_color_add_alpha( FL_GREEN, 200 ) );
|
|
|
|
|
|
|
|
|
|
float j = 5;
|
|
|
|
|
|
|
|
|
|
for ( int i = y() + h(); i > y(); i -= j, j *= 1.2 )
|
|
|
|
|
{
|
|
|
|
|
fl_line( X, i, X + W, i );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fl_line_style( FL_SOLID, 0 );
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2012-06-07 09:29:54 +02:00
|
|
|
|
void
|
|
|
|
|
Audio_Region::draw_label ( void )
|
|
|
|
|
{
|
|
|
|
|
if ( _clip->dummy() )
|
|
|
|
|
{
|
|
|
|
|
char pat[256];
|
|
|
|
|
snprintf( pat, sizeof( pat ), "Missing Source!: %s", _clip->name() );
|
|
|
|
|
draw_label( pat, align() );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
draw_label( _clip->name(), align() );
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-23 05:48:08 +01:00
|
|
|
|
/** split region at absolute frame /where/ */
|
|
|
|
|
void
|
|
|
|
|
Audio_Region::split ( nframes_t where )
|
|
|
|
|
{
|
|
|
|
|
nframes_t old_fade_in = _fade_in.length;
|
|
|
|
|
|
|
|
|
|
_fade_in.length = 256;
|
|
|
|
|
|
|
|
|
|
Audio_Region *copy = new Audio_Region( *this );
|
|
|
|
|
|
2012-03-18 21:21:57 +01:00
|
|
|
|
Logger _log( copy );
|
|
|
|
|
|
2009-01-23 05:48:08 +01:00
|
|
|
|
_fade_in.length = old_fade_in;
|
|
|
|
|
_fade_out.length = 256;
|
|
|
|
|
|
|
|
|
|
Sequence_Region::split( copy, where );
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
int
|
|
|
|
|
Audio_Region::handle ( int m )
|
|
|
|
|
{
|
|
|
|
|
static int ox, oy;
|
|
|
|
|
|
|
|
|
|
static bool copied = false;
|
|
|
|
|
static nframes_t os;
|
|
|
|
|
|
|
|
|
|
int X = Fl::event_x();
|
|
|
|
|
int Y = Fl::event_y();
|
|
|
|
|
|
|
|
|
|
Logger _log( this );
|
|
|
|
|
|
|
|
|
|
switch ( m )
|
|
|
|
|
{
|
|
|
|
|
case FL_FOCUS:
|
|
|
|
|
case FL_UNFOCUS:
|
|
|
|
|
return 1;
|
2012-06-05 02:24:57 +02:00
|
|
|
|
case FL_KEYUP:
|
|
|
|
|
if ( Fl::event_key() == 'g' )
|
|
|
|
|
{
|
|
|
|
|
_adjusting_gain = false;
|
|
|
|
|
redraw();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-06-19 06:14:14 +02:00
|
|
|
|
case FL_KEYBOARD:
|
2012-06-05 02:24:57 +02:00
|
|
|
|
if ( Fl::event_key() == 'g' )
|
|
|
|
|
{
|
|
|
|
|
_adjusting_gain = true;
|
|
|
|
|
redraw();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2008-06-19 06:14:14 +02:00
|
|
|
|
return menu().test_shortcut() != 0;
|
|
|
|
|
case FL_ENTER:
|
|
|
|
|
return Sequence_Region::handle( m );
|
|
|
|
|
case FL_LEAVE:
|
|
|
|
|
return Sequence_Region::handle( m );
|
|
|
|
|
case FL_PUSH:
|
|
|
|
|
{
|
2012-06-05 02:24:57 +02:00
|
|
|
|
if ( Fl::event_key() == 'g' )
|
|
|
|
|
return 1;
|
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
/* splitting */
|
|
|
|
|
if ( test_press( FL_BUTTON2 | FL_SHIFT ) )
|
|
|
|
|
{
|
|
|
|
|
/* split */
|
|
|
|
|
if ( ! copied )
|
|
|
|
|
{
|
|
|
|
|
Loggable::block_start();
|
|
|
|
|
|
2009-01-23 05:48:08 +01:00
|
|
|
|
split( timeline->x_to_offset( X ) );
|
2008-06-19 06:14:14 +02:00
|
|
|
|
|
|
|
|
|
log_end();
|
|
|
|
|
|
|
|
|
|
Loggable::block_end();
|
2008-07-31 06:03:16 +02:00
|
|
|
|
|
|
|
|
|
log_start();
|
2008-06-19 06:14:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ox = x() - X;
|
|
|
|
|
oy = y() - Y;
|
|
|
|
|
/* for panning */
|
|
|
|
|
os = _r->offset;
|
|
|
|
|
|
|
|
|
|
if ( test_press( FL_BUTTON2 | FL_CTRL ) )
|
|
|
|
|
{
|
|
|
|
|
normalize();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else if ( test_press( FL_BUTTON3 ) )
|
|
|
|
|
{
|
|
|
|
|
/* context menu */
|
|
|
|
|
menu_popup( &menu() );
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return Sequence_Region::handle( m );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case FL_RELEASE:
|
|
|
|
|
{
|
|
|
|
|
Sequence_Region::handle( m );
|
|
|
|
|
|
|
|
|
|
copied = false;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
case FL_DRAG:
|
2012-06-05 02:24:57 +02:00
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
if ( ! _drag )
|
|
|
|
|
{
|
|
|
|
|
begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
|
|
|
|
|
_log.hold();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-05 02:24:57 +02:00
|
|
|
|
if ( Fl::event_key() == 'g' )
|
|
|
|
|
{
|
|
|
|
|
float d = (float)h() / ( y() - Fl::event_y() );
|
|
|
|
|
|
|
|
|
|
_scale = -0.5f * d;
|
|
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
if ( test_press( FL_BUTTON1 | FL_SHIFT | FL_CTRL ) )
|
|
|
|
|
{
|
|
|
|
|
/* panning */
|
|
|
|
|
int d = (ox + X) - x();
|
|
|
|
|
|
2012-06-10 04:08:49 +02:00
|
|
|
|
bool negative = d < 0;
|
|
|
|
|
|
|
|
|
|
if ( d < 0 )
|
|
|
|
|
_r->offset = os + timeline->x_to_ts( 0 - d );
|
2008-06-19 06:14:14 +02:00
|
|
|
|
else
|
2012-06-10 04:08:49 +02:00
|
|
|
|
{
|
|
|
|
|
if ( os < timeline->x_to_ts( d ) )
|
|
|
|
|
_r->offset = 0;
|
|
|
|
|
else
|
|
|
|
|
_r->offset = os - timeline->x_to_ts( d );
|
|
|
|
|
}
|
2008-06-19 06:14:14 +02:00
|
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Sequence_Region::handle( m );
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return Sequence_Region::handle( m );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********/
|
|
|
|
|
/* Public */
|
|
|
|
|
/**********/
|
|
|
|
|
|
|
|
|
|
/** return the name of the audio source this region represents */
|
|
|
|
|
const char *
|
|
|
|
|
Audio_Region::source_name ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return _clip->name();
|
|
|
|
|
}
|
2008-02-21 03:10:44 +01:00
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
/** set the amplitude scaling for this region from the normalization
|
|
|
|
|
* factor for the range of samples represented by this region */
|
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-07-24 06:33:32 +02:00
|
|
|
|
const nframes_t npeaks = _loop ? _loop : length();
|
|
|
|
|
|
|
|
|
|
if ( _clip->read_peaks( npeaks, offset(), offset() + npeaks, &peaks, &pbuf, &channels ) &&
|
2008-05-01 09:13:58 +02:00
|
|
|
|
peaks )
|
|
|
|
|
_scale = pbuf->normalization_factor();
|
2008-06-23 03:03:22 +02:00
|
|
|
|
|
|
|
|
|
/* FIXME: wrong place for this? */
|
|
|
|
|
sequence()->handle_widget_change( start(), length() );
|
|
|
|
|
redraw();
|
2008-02-21 13:57:33 +01:00
|
|
|
|
}
|