Split soundfile DND functionality of Track into Audio_Track class.

This commit is contained in:
Jonathan Moore Liles 2008-02-21 00:39:00 -06:00
parent 9321a19a5d
commit 408bf5b296
4 changed files with 90 additions and 48 deletions

81
Audio_Track.H Normal file
View File

@ -0,0 +1,81 @@
/*******************************************************************************/
/* 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. */
/*******************************************************************************/
#pragma once
#include "Track.H"
class Audio_Track : public Track
{
public:
Audio_Track ( int X, int Y, int W, int H ) : Track( X, Y, W, H )
{
}
/** event handler that supports DND of audio clips */
int
handle ( int m )
{
switch ( m )
{
case FL_DND_DRAG:
case FL_DND_ENTER:
case FL_ENTER:
return 1;
case FL_DND_LEAVE:
case FL_DND_RELEASE:
return 1;
case FL_PASTE:
{
const char *text = Fl::event_text();
char *file;
if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
{
printf( "invalid drop \"%s\"\n", text );
return 0;
}
printf( "pasted file \"%s\"\n", file );
Clip *c = Clip::from_file( file );
if ( ! c )
{
free( file );
return 0;
}
Region *r = new Region( c );
r->offset( timeline.x_to_ts( Fl::event_x() ) );
this->add( r );
redraw();
return 1;
}
default:
return Track::handle( m );
}
}
};

40
Track.C
View File

@ -144,46 +144,6 @@ Track::handle ( int m )
switch ( m ) switch ( m )
{ {
case FL_DND_DRAG:
case FL_DND_ENTER:
case FL_ENTER:
return 1;
case FL_DND_LEAVE:
case FL_DND_RELEASE:
return 1;
case FL_PASTE:
{
const char *text = Fl::event_text();
char *file;
if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
{
printf( "invalid drop \"%s\"\n", text );
return 0;
}
printf( "pasted file \"%s\"\n", file );
Clip *c = Clip::from_file( file );
if ( ! c )
{
free( file );
return 0;
}
Region *r = new Region( c );
r->offset( timeline.x_to_ts( Fl::event_x() ) );
// r->position( Fl::event_x(), r->y() );
this->add( r );
redraw();
return 1;
}
case FL_MOVE: case FL_MOVE:
/* these aren't used, so don't bother doing lookups for them */ /* these aren't used, so don't bother doing lookups for them */
return 1; return 1;

12
Track.H
View File

@ -38,11 +38,11 @@ class Track : public Fl_Group
{ {
Track *_next; Track *_next;
Track *_prev; Track *_prev;
list <Track_Widget *> _widgets;
char *_name; char *_name;
protected:
list <Track_Widget *> _widgets;
Track_Widget *event_widget ( void ); Track_Widget *event_widget ( void );
public: public:
@ -61,13 +61,13 @@ public:
void prev ( Track *t ) { _prev = t; } void prev ( Track *t ) { _prev = t; }
void next ( Track *t ) { _next = t; } void next ( Track *t ) { _next = t; }
void sort ( void );
void draw ( void ); void draw ( void );
void remove ( Track_Widget *r ); void remove ( Track_Widget *r );
void add ( Track_Widget *r ); void add ( Track_Widget *r );
void snap ( Track_Widget *r );
int handle ( int m );
void sort ( void ); virtual void snap ( Track_Widget *r );
virtual int handle ( int m );
}; };

5
main.C
View File

@ -37,6 +37,7 @@
#include <string.h> #include <string.h>
#include "Track.H" #include "Track.H"
#include "Audio_Track.H"
#include "Timeline.H" #include "Timeline.H"
#include "const.h" #include "const.h"
@ -133,7 +134,7 @@ main ( int argc, char **argv )
tempo_track->end(); tempo_track->end();
} }
Track *track1 = new Track( 40, 0, 800, 100 ); Track *track1 = new Audio_Track( 40, 0, 800, 100 );
// pack->type( Fl_Pack::VERTICAL ); // pack->type( Fl_Pack::VERTICAL );
// pack->box( FL_DOWN_BOX ); // pack->box( FL_DOWN_BOX );
@ -159,7 +160,7 @@ main ( int argc, char **argv )
track1->end(); track1->end();
Track *track2 = new Track( 40, 0, 5000, 100 ); Track *track2 = new Audio_Track( 40, 0, 5000, 100 );
// Region *wave2 = new Region( 0, 0, 350, 100, "bar" ); // Region *wave2 = new Region( 0, 0, 350, 100, "bar" );