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-02-22 20:30:49 +01:00
|
|
|
|
2008-04-16 02:47:51 +02:00
|
|
|
#include "dsp.h"
|
|
|
|
|
2008-04-15 04:06:35 +02:00
|
|
|
#include <Fl/fl_ask.H>
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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 )
|
|
|
|
{
|
2008-03-09 01:38:34 +01:00
|
|
|
|
|
|
|
case FL_DND_DRAG:
|
2008-04-19 06:16:21 +02:00
|
|
|
return Sequence::handle( m ) | 1;
|
2008-03-09 01:38:34 +01:00
|
|
|
|
|
|
|
/* case FL_DND_ENTER: */
|
|
|
|
/* case FL_DND_LEAVE: */
|
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
case FL_DND_RELEASE:
|
|
|
|
return 1;
|
2008-03-09 01:38:34 +01:00
|
|
|
|
2008-02-22 20:30:49 +01:00
|
|
|
case FL_PASTE:
|
|
|
|
{
|
|
|
|
const char *text = Fl::event_text();
|
|
|
|
|
2008-03-09 01:38:34 +01:00
|
|
|
|
|
|
|
if ( ! strcmp( text, "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-04-09 02:05:15 +02:00
|
|
|
// Region *r =
|
|
|
|
new 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
|
|
|
}
|
|
|
|
}
|
2008-04-07 10:12:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**********/
|
|
|
|
/* Engine */
|
|
|
|
/**********/
|
|
|
|
|
|
|
|
/* THREAD: IO */
|
|
|
|
/** determine region coverage and fill /buf/ with interleaved samples
|
|
|
|
* from /frame/ to /nframes/ for exactly /channels/ channels. */
|
2008-04-07 12:00:16 +02:00
|
|
|
nframes_t
|
2008-04-19 06:16:21 +02:00
|
|
|
Audio_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels )
|
2008-04-07 10:12:01 +02:00
|
|
|
{
|
|
|
|
sample_t *cbuf = new sample_t[ nframes ];
|
|
|
|
|
2008-04-14 06:11:48 +02:00
|
|
|
memset( cbuf, 0, nframes * sizeof( sample_t ) );
|
|
|
|
|
2008-04-07 10:12:01 +02:00
|
|
|
/* quick and dirty--let the regions figure out coverage for themselves */
|
2008-04-19 06:16:21 +02:00
|
|
|
for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin();
|
2008-04-28 16:20:17 +02:00
|
|
|
i != _widgets.end(); ++i )
|
2008-04-07 10:12:01 +02:00
|
|
|
{
|
2008-04-07 12:00:16 +02:00
|
|
|
const Region *r = (Region*)(*i);
|
2008-04-07 10:12:01 +02:00
|
|
|
|
2008-04-07 12:00:16 +02:00
|
|
|
for ( int i = channels; i--; )
|
2008-04-07 10:12:01 +02:00
|
|
|
{
|
2008-04-14 06:11:48 +02:00
|
|
|
int nfr;
|
2008-04-07 10:12:01 +02:00
|
|
|
|
2008-04-14 06:11:48 +02:00
|
|
|
if ( ! ( nfr = r->read( cbuf, frame, nframes, i ) ) )
|
2008-04-13 00:55:25 +02:00
|
|
|
/* error ? */
|
|
|
|
continue;
|
2008-04-07 10:12:01 +02:00
|
|
|
|
2008-04-09 04:20:44 +02:00
|
|
|
if ( channels == 1 )
|
2008-04-16 02:47:51 +02:00
|
|
|
buffer_mix( buf, cbuf, nframes );
|
2008-04-09 04:20:44 +02:00
|
|
|
else
|
2008-04-16 02:47:51 +02:00
|
|
|
buffer_interleave_one_channel_and_mix( buf, cbuf, i, channels, nframes );
|
2008-04-07 10:12:01 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-07 12:00:16 +02:00
|
|
|
|
2008-04-09 02:05:15 +02:00
|
|
|
delete[] cbuf;
|
|
|
|
|
2008-04-07 12:00:16 +02:00
|
|
|
/* FIXME: bogus */
|
|
|
|
return nframes;
|
2008-04-07 10:12:01 +02:00
|
|
|
}
|
2008-04-09 02:05:15 +02:00
|
|
|
|
|
|
|
/* /\* THREAD: RT *\/ */
|
|
|
|
/* nframes_t */
|
2008-04-19 06:16:21 +02:00
|
|
|
/* Audio_Sequence::process ( nframes_t nframes ) */
|
2008-04-09 02:05:15 +02:00
|
|
|
/* { */
|
|
|
|
/* return disktream->process( nframes ); */
|
|
|
|
/* } */
|