From 408bf5b2969f58c533928ccb0a1e66f231914b97 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 21 Feb 2008 00:39:00 -0600 Subject: [PATCH] Split soundfile DND functionality of Track into Audio_Track class. --- Audio_Track.H | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ Track.C | 40 ------------------------- Track.H | 12 ++++---- main.C | 5 ++-- 4 files changed, 90 insertions(+), 48 deletions(-) create mode 100644 Audio_Track.H diff --git a/Audio_Track.H b/Audio_Track.H new file mode 100644 index 0000000..ffe748c --- /dev/null +++ b/Audio_Track.H @@ -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 ); + } + } +}; diff --git a/Track.C b/Track.C index 0ae155e..04678e0 100644 --- a/Track.C +++ b/Track.C @@ -144,46 +144,6 @@ Track::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() ) ); -// r->position( Fl::event_x(), r->y() ); - - this->add( r ); - - redraw(); - return 1; - } case FL_MOVE: /* these aren't used, so don't bother doing lookups for them */ return 1; diff --git a/Track.H b/Track.H index 53493ec..176fbb3 100644 --- a/Track.H +++ b/Track.H @@ -38,11 +38,11 @@ class Track : public Fl_Group { Track *_next; Track *_prev; - - list _widgets; - char *_name; +protected: + + list _widgets; Track_Widget *event_widget ( void ); public: @@ -61,13 +61,13 @@ public: void prev ( Track *t ) { _prev = t; } void next ( Track *t ) { _next = t; } + void sort ( void ); void draw ( void ); void remove ( 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 ); }; diff --git a/main.C b/main.C index af7b3b4..f6a4d0b 100644 --- a/main.C +++ b/main.C @@ -37,6 +37,7 @@ #include #include "Track.H" +#include "Audio_Track.H" #include "Timeline.H" #include "const.h" @@ -133,7 +134,7 @@ main ( int argc, char **argv ) 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->box( FL_DOWN_BOX ); @@ -159,7 +160,7 @@ main ( int argc, char **argv ) 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" );