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-06-21 06:38:29 +02:00
|
|
|
|
/* An Audio_Sequence is a sequence of Audio_Regions. Takes and 'track
|
|
|
|
|
* contents' consist of these objects */
|
|
|
|
|
|
2012-04-03 06:30:56 +02:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2008-12-02 07:14:25 +01:00
|
|
|
|
#include <sys/time.h>
|
2012-02-26 03:01:35 +01:00
|
|
|
|
#include <FL/fl_ask.H>
|
2012-04-27 19:14:53 +02:00
|
|
|
|
#include <FL/Fl.H>
|
2008-04-19 06:16:21 +02:00
|
|
|
|
#include "Audio_Sequence.H"
|
2008-05-01 08:07:10 +02:00
|
|
|
|
#include "Waveform.H"
|
2008-06-18 06:01:22 +02:00
|
|
|
|
|
2008-05-22 22:58:36 +02:00
|
|
|
|
#include <list>
|
|
|
|
|
using namespace std;
|
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-22 22:34:21 +02:00
|
|
|
|
#include "Transport.H" // for locate()
|
2012-12-11 06:47:44 +01:00
|
|
|
|
#include "Track_Header.H"
|
2012-04-03 06:30:56 +02:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
2012-05-31 06:22:48 +02:00
|
|
|
|
#include <unistd.h> // for symlink()
|
|
|
|
|
|
2012-06-05 07:58:57 +02:00
|
|
|
|
#include "string_util.h"
|
|
|
|
|
|
2008-05-22 22:58:36 +02:00
|
|
|
|
|
|
|
|
|
|
2012-12-11 06:47:44 +01:00
|
|
|
|
const char *
|
|
|
|
|
Audio_Sequence::name ( void ) const
|
|
|
|
|
{
|
|
|
|
|
return Sequence::name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Audio_Sequence::name ( const char *s )
|
|
|
|
|
{
|
|
|
|
|
Sequence::name( s );
|
|
|
|
|
header()->name_input->value( s );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Audio_Sequence::cb_button ( Fl_Widget *w, void *v )
|
|
|
|
|
{
|
|
|
|
|
((Audio_Sequence*)v)->cb_button( w );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Audio_Sequence::cb_button ( Fl_Widget *w )
|
|
|
|
|
{
|
|
|
|
|
Logger log(this);
|
|
|
|
|
|
|
|
|
|
if ( w == header()->name_input )
|
|
|
|
|
{
|
|
|
|
|
Sequence::name( header()->name_input->value() );
|
|
|
|
|
}
|
|
|
|
|
else if ( w == header()->delete_button )
|
|
|
|
|
{
|
|
|
|
|
track()->remove( this );
|
|
|
|
|
}
|
|
|
|
|
else if ( w == header()->promote_button )
|
|
|
|
|
{
|
|
|
|
|
track()->sequence( this );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Audio_Sequence::init ( void )
|
|
|
|
|
{
|
|
|
|
|
labeltype( FL_NO_LABEL );
|
|
|
|
|
{
|
|
|
|
|
Audio_Sequence_Header *o = new Audio_Sequence_Header( x(), y(), Track::width(), 52 );
|
|
|
|
|
|
|
|
|
|
o->name_input->callback( cb_button, this );
|
|
|
|
|
o->delete_button->callback( cb_button, this );
|
|
|
|
|
o->promote_button->callback( cb_button, this );
|
|
|
|
|
|
|
|
|
|
Fl_Group::add( o );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resizable(0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 07:14:25 +01:00
|
|
|
|
Audio_Sequence::Audio_Sequence ( Track *track, const char *name ) : Sequence( track )
|
2008-05-05 07:29:39 +02:00
|
|
|
|
{
|
|
|
|
|
_track = track;
|
|
|
|
|
|
2012-12-11 06:47:44 +01:00
|
|
|
|
init();
|
|
|
|
|
|
2008-12-02 07:14:25 +01:00
|
|
|
|
if ( name )
|
|
|
|
|
Audio_Sequence::name( name );
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
|
|
gettimeofday( &tv, NULL );
|
|
|
|
|
|
|
|
|
|
time_t t = tv.tv_sec;
|
|
|
|
|
|
|
|
|
|
char s[40];
|
|
|
|
|
|
|
|
|
|
ctime_r( &t, s );
|
|
|
|
|
|
|
|
|
|
s[ strlen( s ) - 1 ] = 0;
|
|
|
|
|
|
|
|
|
|
Audio_Sequence::name( s );
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-05 07:29:39 +02:00
|
|
|
|
if ( track )
|
|
|
|
|
track->add( this );
|
|
|
|
|
|
|
|
|
|
log_create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Audio_Sequence::~Audio_Sequence ( )
|
|
|
|
|
{
|
2008-06-06 06:14:00 +02:00
|
|
|
|
Loggable::block_start();
|
|
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
2008-05-05 07:29:39 +02:00
|
|
|
|
log_destroy();
|
2008-05-28 02:36:17 +02:00
|
|
|
|
|
|
|
|
|
track()->remove( this );
|
2008-06-06 06:14:00 +02:00
|
|
|
|
|
|
|
|
|
Loggable::block_end();
|
2008-05-05 07:29:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
|
2008-05-05 07:29:39 +02:00
|
|
|
|
|
2008-06-19 06:14:14 +02:00
|
|
|
|
/** return a pointer to the current capture region for this sequence */
|
2008-05-05 07:29:39 +02:00
|
|
|
|
const Audio_Region *
|
2008-05-23 04:23:41 +02:00
|
|
|
|
Audio_Sequence::capture_region ( void ) const
|
2008-05-05 07:29:39 +02:00
|
|
|
|
{
|
2008-05-23 04:23:41 +02:00
|
|
|
|
return track()->capture_region();
|
2008-05-05 07:29:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Audio_Sequence::get ( Log_Entry &e ) const
|
2008-08-04 05:54:22 +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-05-22 22:34:21 +02:00
|
|
|
|
void
|
|
|
|
|
Audio_Sequence::handle_widget_change ( nframes_t start, nframes_t length )
|
|
|
|
|
{
|
2008-05-28 01:47:47 +02:00
|
|
|
|
Sequence::handle_widget_change( start, length );
|
|
|
|
|
|
2008-05-22 22:34:21 +02:00
|
|
|
|
/* a region has changed. we may need to rebuffer... */
|
|
|
|
|
|
|
|
|
|
/* trigger rebuffer */
|
|
|
|
|
/* FIXME: we really only need to rebuffer *this* sequence! */
|
|
|
|
|
/* FIXME: how does this fit into the selection? */
|
2008-05-26 04:51:55 +02:00
|
|
|
|
|
|
|
|
|
if ( transport->rolling && ( start > transport->frame || start + length > transport->frame ) )
|
2008-05-22 22:34:21 +02:00
|
|
|
|
transport->locate( transport->frame );
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-01 08:07:10 +02:00
|
|
|
|
void
|
|
|
|
|
Audio_Sequence::draw ( void )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Sequence::draw();
|
|
|
|
|
|
|
|
|
|
int xfades = 0;
|
|
|
|
|
|
2012-12-11 06:47:44 +01:00
|
|
|
|
fl_push_clip( drawable_x(), y(), drawable_w(), h() );
|
2012-06-14 08:04:42 +02:00
|
|
|
|
|
2008-05-01 08:07:10 +02:00
|
|
|
|
/* 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" ); */
|
|
|
|
|
|
2008-05-29 18:38:06 +02:00
|
|
|
|
if ( o->contains( *r ) )
|
2008-05-01 08:07:10 +02:00
|
|
|
|
/* completely inside */
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
++xfades;
|
|
|
|
|
|
|
|
|
|
Rectangle b( (*r)->x(),
|
2008-08-04 05:54:22 +02:00
|
|
|
|
o->y(),
|
|
|
|
|
(o->x() + o->w()) - (*r)->x(),
|
|
|
|
|
o->h() );
|
2008-05-01 08:07:10 +02:00
|
|
|
|
|
2013-05-02 03:01:53 +02:00
|
|
|
|
cairo_t *cc = Fl::cairo_cc();
|
|
|
|
|
|
|
|
|
|
cairo_set_operator( cc, CAIRO_OPERATOR_HSL_COLOR );
|
|
|
|
|
cairo_set_source_rgba( cc, 1, 1, 0, 0.80 );
|
|
|
|
|
cairo_rectangle( cc, b.x, b.y, b.w, b.h );
|
|
|
|
|
|
|
|
|
|
cairo_fill( cc );
|
|
|
|
|
|
|
|
|
|
cairo_set_operator( cc, CAIRO_OPERATOR_OVER );
|
2008-05-01 08:07:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-14 08:04:42 +02:00
|
|
|
|
fl_pop_clip();
|
2008-05-01 08:07:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
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:
|
|
|
|
|
{
|
2013-04-22 08:14:52 +02:00
|
|
|
|
if ( ! Fl::event_inside( this ) )
|
|
|
|
|
return 0;
|
2008-02-22 20:30:49 +01:00
|
|
|
|
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 ) )
|
|
|
|
|
{
|
2013-04-22 08:14:52 +02:00
|
|
|
|
WARNING( "invalid drop \"%s\"\n", text );
|
2008-02-22 20:30:49 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-05 07:58:57 +02:00
|
|
|
|
unescape_url( file );
|
2008-02-22 20:30:49 +01:00
|
|
|
|
|
|
|
|
|
printf( "pasted file \"%s\"\n", file );
|
|
|
|
|
|
2008-03-06 19:46:40 +01:00
|
|
|
|
fl_cursor( FL_CURSOR_WAIT );
|
|
|
|
|
Fl::check();
|
|
|
|
|
|
2012-04-03 06:30:56 +02:00
|
|
|
|
char *t = strdup( file );
|
|
|
|
|
|
|
|
|
|
char *filebase = strdup( basename( t ) );
|
|
|
|
|
|
|
|
|
|
free( t );
|
|
|
|
|
|
|
|
|
|
char *s = 0;
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
for ( ; ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( i )
|
|
|
|
|
{
|
|
|
|
|
free( s );
|
|
|
|
|
asprintf( &s, "sources/%s-%i", filebase, i );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
asprintf( &s, "sources/%s", filebase );
|
|
|
|
|
|
|
|
|
|
DMESSAGE( "Symlink %s -> %s", file, s );
|
|
|
|
|
if ( symlink( file, s ) == 0 )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if ( errno != EEXIST )
|
|
|
|
|
{
|
|
|
|
|
WARNING( "Failed to create symlink: %s", strerror( errno ) );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Audio_File *c = Audio_File::from_file( basename( s ) );
|
|
|
|
|
|
|
|
|
|
free( s );
|
|
|
|
|
free( filebase );
|
2008-02-22 20:30:49 +01:00
|
|
|
|
|
2008-03-06 19:46:40 +01:00
|
|
|
|
fl_cursor( FL_CURSOR_DEFAULT );
|
2012-04-03 06:30:56 +02:00
|
|
|
|
Fl::check();
|
2008-03-06 19:46:40 +01:00
|
|
|
|
|
2012-04-03 06:30:56 +02:00
|
|
|
|
if ( ! c || c->dummy() )
|
2008-02-22 20:30:49 +01:00
|
|
|
|
{
|
2012-04-03 06:30:56 +02:00
|
|
|
|
fl_alert( "Could not import file \"%s\"", file );
|
2008-02-22 20:30:49 +01:00
|
|
|
|
free( file );
|
2012-04-03 06:30:56 +02:00
|
|
|
|
|
|
|
|
|
if ( c )
|
|
|
|
|
{
|
|
|
|
|
delete c;
|
|
|
|
|
c = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-07 04:32:37 +02:00
|
|
|
|
free( file );
|
|
|
|
|
|
2013-03-14 02:00:03 +01:00
|
|
|
|
Audio_Region *r =
|
2013-04-22 07:59:34 +02:00
|
|
|
|
new Audio_Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - drawable_x() ) );
|
2013-03-14 02:00:03 +01:00
|
|
|
|
|
|
|
|
|
r->log_create();
|
2008-02-22 20:30:49 +01:00
|
|
|
|
|
|
|
|
|
redraw();
|
2012-04-03 06:30:56 +02:00
|
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2008-04-19 06:16:21 +02:00
|
|
|
|
return Sequence::handle( m );
|
2008-02-22 20:30:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|