2008-02-22 20:30:49 +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 "Audio_Sequence.H"
|
2008-05-01 08:07:10 +02:00
|
|
|
#include "Waveform.H"
|
2008-02-22 20:30:49 +01:00
|
|
|
|
2008-04-15 04:06:35 +02:00
|
|
|
#include <Fl/fl_ask.H>
|
2008-02-22 20:30:49 +01:00
|
|
|
|
2008-05-05 07:29:39 +02:00
|
|
|
#include "Track.H"
|
|
|
|
|
2008-05-22 09:05:49 +02:00
|
|
|
#include "Engine/Audio_File.H" // for ::from_file()
|
|
|
|
|
2008-05-05 07:29:39 +02:00
|
|
|
Audio_Sequence::Audio_Sequence ( Track *track ) : Sequence( track )
|
|
|
|
{
|
|
|
|
|
|
|
|
_track = track;
|
|
|
|
|
|
|
|
if ( track )
|
|
|
|
track->add( this );
|
|
|
|
|
|
|
|
log_create();
|
|
|
|
|
|
|
|
/* FIXME: temporary */
|
|
|
|
labeltype( FL_NO_LABEL );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Audio_Sequence::~Audio_Sequence ( )
|
|
|
|
{
|
|
|
|
log_destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Audio_Region *
|
|
|
|
Audio_Sequence::capture ( void ) const
|
|
|
|
{
|
|
|
|
return track()->capture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Audio_Sequence::get ( Log_Entry &e ) const
|
|
|
|
{
|
2008-05-07 17:28:57 +02:00
|
|
|
e.add( ":track", _track );
|
|
|
|
e.add( ":name", name() );
|
2008-05-05 07:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Audio_Sequence::set ( Log_Entry &e )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < e.size(); ++i )
|
|
|
|
{
|
|
|
|
const char *s, *v;
|
|
|
|
|
|
|
|
e.get( i, &s, &v );
|
|
|
|
|
2008-05-07 17:28:57 +02:00
|
|
|
if ( ! strcmp( ":track", s ) )
|
2008-05-05 07:29:39 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
sscanf( v, "%X", &i );
|
|
|
|
Track *t = (Track*)Loggable::find( i );
|
|
|
|
|
|
|
|
assert( t );
|
|
|
|
|
2008-05-07 18:18:57 +02:00
|
|
|
t->sequence( this );
|
2008-05-05 07:29:39 +02:00
|
|
|
}
|
2008-05-07 17:28:57 +02:00
|
|
|
else if ( ! strcmp( ":name", s ) )
|
2008-05-07 04:32:37 +02:00
|
|
|
name( v );
|
2008-05-05 07:29:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
static
|
|
|
|
void
|
|
|
|
deurlify ( char *url )
|
|
|
|
{
|
|
|
|
char *r, *w;
|
|
|
|
|
|
|
|
r = w = url;
|
|
|
|
|
|
|
|
for ( ; *r; r++, w++ )
|
|
|
|
{
|
|
|
|
if ( *r == '%' )
|
|
|
|
{
|
|
|
|
char data[3] = { *(r + 1), *(r + 2), 0 };
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
sscanf( data, "%2X", &c );
|
|
|
|
|
|
|
|
*w = c;
|
|
|
|
|
|
|
|
r += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*w = *r;
|
|
|
|
}
|
|
|
|
|
|
|
|
*w = NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-01 08:07:10 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
Audio_Sequence::draw ( void )
|
|
|
|
{
|
|
|
|
|
|
|
|
Sequence::draw();
|
|
|
|
|
|
|
|
int xfades = 0;
|
|
|
|
|
|
|
|
/* draw crossfades */
|
|
|
|
for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
|
|
|
|
{
|
|
|
|
Sequence_Widget *o = overlaps( *r );
|
|
|
|
|
|
|
|
if ( o )
|
|
|
|
{
|
|
|
|
if ( *o <= **r )
|
|
|
|
{
|
|
|
|
|
|
|
|
/* if ( o->x() == (*r)->x() && o->w() == (*r)->w() ) */
|
|
|
|
/* printf( "complete superposition\n" ); */
|
|
|
|
|
|
|
|
if ( (*r)->x() >= o->x() && (*r)->x() + (*r)->w() <= o->x() + o->w() )
|
|
|
|
/* completely inside */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
++xfades;
|
|
|
|
|
|
|
|
Rectangle b( (*r)->x(),
|
|
|
|
o->y(),
|
|
|
|
(o->x() + o->w()) - (*r)->x(),
|
|
|
|
o->h() );
|
|
|
|
|
|
|
|
Fl_Color c = fl_color_average( o->box_color(), (*r)->box_color(), 0.50f );
|
|
|
|
c = fl_color_average( c, FL_YELLOW, 0.30f );
|
|
|
|
|
|
|
|
fl_push_clip( b.x, b.y, b.w, b.h );
|
|
|
|
|
|
|
|
draw_box( FL_FLAT_BOX, b.x - 100, b.y, b.w + 200, b.h, c );
|
|
|
|
draw_box( FL_UP_FRAME, b.x - 100, b.y, b.w + 200, b.h, c );
|
|
|
|
|
|
|
|
|
|
|
|
fl_pop_clip();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
|
|
|
|
{
|
|
|
|
Sequence_Widget *o = overlaps( *r );
|
|
|
|
|
|
|
|
if ( o )
|
|
|
|
{
|
|
|
|
if ( *o <= **r )
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( (*r)->x() >= o->x() && (*r)->x() + (*r)->w() <= o->x() + o->w() )
|
|
|
|
/* completely inside */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Rectangle b( (*r)->x(), o->y(), (o->x() + o->w()) - (*r)->x(), o->h() );
|
|
|
|
|
|
|
|
/* draw overlapping waveforms in X-ray style. */
|
|
|
|
bool t = Waveform::fill;
|
|
|
|
|
|
|
|
Waveform::fill = false;
|
|
|
|
|
|
|
|
fl_push_clip( b.x, b.y, b.w, b.h );
|
|
|
|
|
|
|
|
o->draw();
|
|
|
|
(*r)->draw();
|
|
|
|
|
|
|
|
fl_pop_clip();
|
|
|
|
|
|
|
|
Waveform::fill = t;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
/** event handler that supports DND of audio clips */
|
|
|
|
int
|
2008-04-19 06:16:21 +02:00
|
|
|
Audio_Sequence::handle ( int m )
|
2008-02-22 20:30:49 +01:00
|
|
|
{
|
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
case FL_PASTE:
|
|
|
|
{
|
|
|
|
const char *text = Fl::event_text();
|
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
if ( ! strcmp( text, "Audio_Region" ) )
|
2008-03-09 05:19:05 +01:00
|
|
|
return 1;
|
2008-03-09 01:38:34 +01:00
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
char *file;
|
|
|
|
|
|
|
|
if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
|
|
|
|
{
|
|
|
|
printf( "invalid drop \"%s\"\n", text );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
deurlify( file );
|
|
|
|
|
|
|
|
printf( "pasted file \"%s\"\n", file );
|
|
|
|
|
2008-03-06 19:46:40 +01:00
|
|
|
fl_cursor( FL_CURSOR_WAIT );
|
|
|
|
Fl::check();
|
|
|
|
|
2008-03-28 06:19:26 +01:00
|
|
|
Audio_File *c = Audio_File::from_file( file );
|
2008-02-22 20:30:49 +01:00
|
|
|
|
2008-03-06 19:46:40 +01:00
|
|
|
fl_cursor( FL_CURSOR_DEFAULT );
|
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
if ( ! c )
|
|
|
|
{
|
2008-04-15 04:06:35 +02:00
|
|
|
fl_alert( "Could not import file \"%s\": Unsupported file type.", file );
|
2008-03-26 09:33:14 +01:00
|
|
|
printf( "could not open file\n" );
|
2008-02-22 20:30:49 +01:00
|
|
|
free( file );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-07 04:32:37 +02:00
|
|
|
free( file );
|
|
|
|
|
2008-05-05 02:04:20 +02:00
|
|
|
// Audio_Region *r =
|
|
|
|
new Audio_Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ) );
|
2008-02-22 20:30:49 +01:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
default:
|
2008-04-19 06:16:21 +02:00
|
|
|
return Sequence::handle( m );
|
2008-02-22 20:30:49 +01:00
|
|
|
}
|
|
|
|
}
|