Initial checkin.

pull/3/head
Jonathan Moore Liles 2008-02-13 23:47:12 -06:00
commit a7f590aa40
4 changed files with 323 additions and 0 deletions

13
Makefile Normal file
View File

@ -0,0 +1,13 @@
CXXFLAGS=-ggdb
LIBS=`fltk-config --ldflags`
# CXXFLAGS=`fltk-config -cxxflags`
OBJS=Waveform.o main.o
.C.o:
$(CXX) $(CXXFLAGS) -c $< -o $@
test: Waveform.o main.o
$(CXX) $(CXXFLAGS) $(LIBS) $(OBJS) -o $@

179
Waveform.C Normal file
View File

@ -0,0 +1,179 @@
/*******************************************************************************/
/* 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. */
/*******************************************************************************/
#include <stdio.h>
#include <FL/Enumerations.H>
#include <FL/Fl.H>
#include "Waveform.H"
#include <math.h>
extern Fl_Color velocity_colors[];
Waveform::Waveform ( int X, int Y, int W, int H, const char *L=0 ) : Fl_Widget( X, Y, W, H, L )
{
}
#if 0
void
Waveform::buble_draw ( void )
{
int inc = 10;
for ( tick_t x = 0; x < w() && x < _end; ++x )
{
float v1 = _peaks[ _start + (x * inc) ] / (float)127;
int lh1 = (float)(h() / 2) * fabs( v1 );
int ly1 = (h() / 2) - (lh1 / 2);
fl_color( selection_color() );
fl_color( velocity_colors[ 127 - (int)(127 * fabs( v1 )) ] );
fl_pie( x, y() + ly1, inc, lh1, 0, 360 );
fl_color( fl_darker( selection_color() ) );
fl_arc( x, y() + ly1, inc, lh1, 0, 360 );
}
}
#endif
int
Waveform::handle ( int m )
{
if ( m == FL_PUSH )
{
switch ( Fl::event_button() )
{
case 1:
_start += 100;
_end += 100;
redraw();
break;
case 3:
_start -= 100;
_end -= 100;
redraw();
break;
default:
return 0;
}
return 1;
}
return 0;
}
void
Waveform::draw ( void )
{
fl_push_clip( x(), y(), w(), h() );
draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() );
fl_push_matrix();
fl_color( selection_color() );
int j;
float scale = 1;
j = 0;
for ( tick_t x = 0; x < w() && x < _end; ++x )
{
float lo = _peaks[ _start + j++ ] * scale;
float hi = _peaks[ _start + j++ ] * scale;
int mid = y() + (h() / 2);
int rx = this->x() + x;
fl_line( rx, mid + (h() * lo), rx, mid + (h() * hi) );
}
fl_color( fl_darker( fl_darker( selection_color() ) ) );
fl_begin_line();
j = 0;
for ( tick_t x = 0; x < w() && x < _end; ++x )
{
float v = _peaks[ _start + j ] * scale;
j += 2;
fl_vertex( this->x() + x, y() + (h() / 2) + ((float)h() * v ));
}
fl_end_line();
fl_begin_line();
j = 1;
for ( tick_t x = 0; x < w() && x < _end; ++x )
{
float v = _peaks[ _start + j ] * scale;
j += 2;
fl_vertex( this->x() + x, y() + (h() / 2) + ((float)h() * v ));
}
fl_end_line();
fl_pop_matrix();
fl_pop_clip();
}
#if 0
void
Waveform::draw ( void )
{
fl_push_clip( x(), y(), w(), h() );
draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() );
fl_push_matrix();
int inc = 1;
int j = 0;
for ( tick_t x = 0; x < w() && x < _end; ++x )
{
float lo = _peaks[ _start + j++ ];
float hi = _peaks[ _start + j++ ];
int mid = y() + (h() / 2);
int rx = this->x() + x;
fl_color( selection_color() );
fl_line( rx, mid + (h() * lo), rx, mid + (h() * hi) );
}
fl_pop_matrix();
}
#endif

46
Waveform.H Normal file
View File

@ -0,0 +1,46 @@
/*******************************************************************************/
/* 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. */
/*******************************************************************************/
#include <FL/Fl_Widget.H>
#include <FL/fl_draw.H>
typedef unsigned long tick_t;
class Waveform : public Fl_Widget
{
float *_peaks;
tick_t _start;
tick_t _end;
float _scale; /* vertical scaling */
float _zoom; /* horizontal zoom */
public:
Waveform ( int X, int Y, int W, int H, const char *L );
int handle ( int m );
void draw ( void );
void start ( tick_t s ) { _start = s; }
void end ( tick_t e ) { _end = e; }
void peaks ( float *p ) { _peaks = p; }
};

85
main.C Normal file
View File

@ -0,0 +1,85 @@
/*******************************************************************************/
/* 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. */
/*******************************************************************************/
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Scroll.H>
#include "Waveform.H"
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
Fl_Color velocity_colors[128];
void
init_colors ( void )
{
for ( int i = 128; i--; )
velocity_colors[i] = fl_rgb_color( 23, 255 - i * 2, 32 );
}
int
main ( int argc, char **argv )
{
init_colors();
Fl_Window *main_window = new Fl_Window( 0, 0, 800, 600 );
Fl_Scroll *scroll = new Fl_Scroll( 0, 0, 800, 600 );
Waveform *wave = new Waveform( 0, 0, 5000, 100, "foo" );
FILE *fp;
fp = fopen( "peaks", "r" );
struct stat st;
fstat( fileno( fp ), &st );
size_t len = st.st_size;
float *peaks = new float[ len / sizeof( float ) ];
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 );
scroll->end();
main_window->end();
main_window->show();
wave->redraw();
Fl::run();
}