2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
20 /* An Audio_Sequence is a sequence of Audio_Regions. Takes and 'track
21 * contents' consist of these objects */
26 #include <FL/fl_ask.H>
28 #include "Audio_Sequence.H"
36 #include "Engine/Audio_File.H" // for ::from_file()
37 #include "Transport.H" // for locate()
41 #include <unistd.h> // for symlink()
43 #include "string_util.h"
47 Audio_Sequence::Audio_Sequence ( Track *track, const char *name ) : Sequence( track )
52 Audio_Sequence::name( name );
57 gettimeofday( &tv, NULL );
65 s[ strlen( s ) - 1 ] = 0;
67 Audio_Sequence::name( s );
75 /* FIXME: temporary */
76 labeltype( FL_NO_LABEL );
81 Audio_Sequence::~Audio_Sequence ( )
83 Loggable::block_start();
89 track()->remove( this );
91 Loggable::block_end();
96 /** return a pointer to the current capture region for this sequence */
98 Audio_Sequence::capture_region ( void ) const
100 return track()->capture_region();
104 Audio_Sequence::get ( Log_Entry &e ) const
106 e.add( ":track", _track );
107 e.add( ":name", name() );
111 Audio_Sequence::set ( Log_Entry &e )
113 for ( int i = 0; i < e.size(); ++i )
119 if ( ! strcmp( ":track", s ) )
122 sscanf( v, "%X", &i );
123 Track *t = (Track*)Loggable::find( i );
129 else if ( ! strcmp( ":name", s ) )
136 Audio_Sequence::handle_widget_change ( nframes_t start, nframes_t length )
138 Sequence::handle_widget_change( start, length );
140 /* a region has changed. we may need to rebuffer... */
142 /* trigger rebuffer */
143 /* FIXME: we really only need to rebuffer *this* sequence! */
144 /* FIXME: how does this fit into the selection? */
146 if ( transport->rolling && ( start > transport->frame || start + length > transport->frame ) )
147 transport->locate( transport->frame );
151 Audio_Sequence::draw ( void )
158 fl_push_clip( x(), y(), w(), h() );
160 /* draw crossfades */
161 for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
163 Sequence_Widget *o = overlaps( *r );
169 /* if ( o->x() == (*r)->x() && o->w() == (*r)->w() ) */
170 /* printf( "complete superposition\n" ); */
172 if ( o->contains( *r ) )
173 /* completely inside */
178 Rectangle b( (*r)->x(),
180 (o->x() + o->w()) - (*r)->x(),
183 Fl_Color c = fl_color_add_alpha( FL_YELLOW, 127 );
186 fl_rectf( b.x, b.y, b.w, b.h );
195 /** event handler that supports DND of audio clips */
197 Audio_Sequence::handle ( int m )
203 const char *text = Fl::event_text();
205 if ( ! strcmp( text, "Audio_Region" ) )
210 if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
212 printf( "invalid drop \"%s\"\n", text );
216 unescape_url( file );
218 printf( "pasted file \"%s\"\n", file );
220 fl_cursor( FL_CURSOR_WAIT );
223 char *t = strdup( file );
225 char *filebase = strdup( basename( t ) );
238 asprintf( &s, "sources/%s-%i", filebase, i );
241 asprintf( &s, "sources/%s", filebase );
243 DMESSAGE( "Symlink %s -> %s", file, s );
244 if ( symlink( file, s ) == 0 )
247 if ( errno != EEXIST )
249 WARNING( "Failed to create symlink: %s", strerror( errno ) );
254 Audio_File *c = Audio_File::from_file( basename( s ) );
259 fl_cursor( FL_CURSOR_DEFAULT );
262 if ( ! c || c->dummy() )
264 fl_alert( "Could not import file \"%s\"", file );
279 new Audio_Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ) );
286 return Sequence::handle( m );