Browse Source

Add tracks. Support dragging regions between tracks.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
62781a70ed
6 changed files with 174 additions and 7 deletions
  1. +3
    -0
      Makefile
  2. +47
    -1
      Region.C
  3. +8
    -0
      Region.H
  4. +83
    -0
      Track.H
  5. +4
    -0
      Waveform.C
  6. +29
    -6
      main.C

+ 3
- 0
Makefile View File

@@ -11,3 +11,6 @@ OBJS=Waveform.o Region.o main.o

test: $(OBJS)
$(CXX) $(CXXFLAGS) $(LIBS) $(OBJS) -o $@

clean:
rm -f $(OBJS) test

+ 47
- 1
Region.C View File

@@ -17,18 +17,24 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/

#include "Track.H"
#include "Region.H"

#include <FL/fl_draw.H>
#include <FL/Fl.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Widget.H>

#include <stdio.h>

Region::Region ( int X, int Y, int W, int H, const char *L=0 ) : Waveform( X, Y, W, H, L )
{
align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM );
align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP );
labeltype( FL_SHADOW_LABEL );
labelcolor( FL_WHITE );
box( FL_PLASTIC_UP_BOX );

_track = NULL;
}

int
@@ -38,6 +44,9 @@ Region::handle ( int m )
if ( Fl_Widget::handle( m ) )
return 1;

static int ox, oy;


switch ( m )
{
case FL_PUSH:
@@ -73,9 +82,46 @@ Region::handle ( int m )
}
return 1;
}
else
{
ox = x() - Fl::event_x();
oy = y() - Fl::event_y();

if ( Fl::event_button() == 2 )
{
// _track->add( new Region( *this ) );
}

return 1;
}
return 0;
break;
}
case FL_RELEASE:
fl_cursor( FL_CURSOR_DEFAULT );
return 1;
case FL_DRAG:

if ( ox + Fl::event_x() >= _track->x() )
position( ox + Fl::event_x(), y() );

if ( Fl::event_y() > y() + h() )
{
if ( _track->next() )
_track->next()->add( this );
}
else
if ( Fl::event_y() < y() )
{
if ( _track->prev() )
_track->prev()->add( this );
}
// if ( Fl::event_y() - oy >= h() )

parent()->redraw();

fl_cursor( FL_CURSOR_MOVE );
return 1;
default:
return 0;
break;


+ 8
- 0
Region.H View File

@@ -17,16 +17,24 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/

#pragma once

class Track;

#include "Waveform.H"

class Region : public Waveform
{

Track *_track;

public:

Region ( int X, int Y, int W, int H, const char *L );

int handle ( int m );
void draw ( void );

Track * track ( void ) { return _track; }
void track ( Track *t ) { _track = t; }
};

+ 83
- 0
Track.H View File

@@ -0,0 +1,83 @@

/*******************************************************************************/
/* 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 <FL/Fl_Group.H>

#include "Region.H"


#include <stdio.h>

#include <list>
using std::list;

class Track : public Fl_Group
{
Track *_next;
Track *_prev;

list <Region *> _regions;

char *_name;

public:

Track ( int X, int Y, int W, int H ) : Fl_Group( X, Y, W, H )
{
_next = _prev = NULL;
_name = NULL;

box( FL_DOWN_BOX );
color( fl_darker( FL_GRAY ) );
}

Track *next ( void ) { return _next; }
Track *prev ( void ) { return _prev; }
void prev ( Track *t ) { _prev = t; }
void next ( Track *t ) { _next = t; }

void remove_region ( Region *r )
{
_regions.remove( r );
}

void add ( Region *r )
{

printf( "add" );

if ( r->track() )
{
r->track()->remove_region( r );
r->track()->redraw();
}

_regions.push_back( r );

r->track( this );

Fl_Group::add( r );
// add( r );

r->position( r->x(), y() );
r->redraw();
}
};

+ 4
- 0
Waveform.C View File

@@ -143,6 +143,8 @@ Waveform::draw ( int X, int Y, int W, int H )

fl_color( fl_darker( fl_darker( selection_color() ) ) );

fl_line_style( FL_SOLID, 2 );

fl_begin_line();

j = 0;
@@ -167,6 +169,8 @@ Waveform::draw ( int X, int Y, int W, int H )

fl_end_line();

fl_line_style( FL_SOLID, 0 );

fl_pop_matrix();

// fl_pop_clip();


+ 29
- 6
main.C View File

@@ -35,6 +35,8 @@

Fl_Color velocity_colors[128];

#include "Track.H"

void
init_colors ( void )
{
@@ -52,10 +54,16 @@ main ( int argc, char **argv )

Fl_Scroll *scroll = new Fl_Scroll( 0, 0, 800, 600 );

Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 );
Fl_Pack *tracks = new Fl_Pack( 0, 0, 5000, 5000 );
tracks->type( Fl_Pack::VERTICAL );


// Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 );

Track *track1 = new Track( 40, 0, 5000, 100 );

// pack->type( Fl_Pack::VERTICAL );
pack->box( FL_DOWN_BOX );
// pack->box( FL_DOWN_BOX );

Region *wave = new Region( 0, 0, 5000, 100, "foo" );

@@ -78,19 +86,34 @@ main ( int argc, char **argv )

fread( peaks, len, 1, fp );


wave->peaks( peaks );
wave->start( 0 );
wave->end( len );

wave->color( FL_CYAN );
wave->selection_color( fl_darker( FL_GRAY ) );

wave->selection_color( FL_GREEN );

pack->add( wave );
track1->add( wave );

track1->end();

Track *track2 = new Track( 40, 0, 5000, 100 );

Region *wave2 = new Region( 0, 0, 350, 100, "bar" );

wave2->peaks( peaks );
wave2->start( 0 );
wave2->end( len / 2 );

track2->add( wave2 );

track2->end();

track1->next( track2 );
track2->prev( track1 );

pack->end();
tracks->end();
scroll->end();

main_window->end();


Loading…
Cancel
Save