various libraries.tags/non-daw-v1.1.0
| @@ -0,0 +1,43 @@ | |||
| /*******************************************************************************/ | |||
| /* 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 "Audio_File.H" | |||
| #include "Audio_File_SF.H" | |||
| /** attmpet to open any supported filetype */ | |||
| Audio_File * | |||
| Audio_File::from_file ( const char * filename ) | |||
| { | |||
| Audio_File *a; | |||
| if ( ( a = Audio_File_SF::from_file( filename ) ) ) | |||
| goto done; | |||
| a->_peaks.open(); | |||
| // TODO: other formats | |||
| return NULL; | |||
| done: | |||
| a->_peaks.open(); | |||
| return a; | |||
| } | |||
| @@ -0,0 +1,61 @@ | |||
| /*******************************************************************************/ | |||
| /* 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 | |||
| /* Base class for all audio file library interfaces */ | |||
| #include <stdlib.h> | |||
| typedef unsigned long nframes_t; | |||
| typedef float sample_t; | |||
| #include "Peaks.H" | |||
| class Audio_File | |||
| { | |||
| protected: | |||
| Peaks _peaks; | |||
| const char *_filename; | |||
| nframes_t _length; /* length of file in samples */ | |||
| public: | |||
| Audio_File ( ) : _peaks( this ) | |||
| { | |||
| _filename = NULL; | |||
| _length = 0; | |||
| } | |||
| static Audio_File *from_file ( const char *filename ); | |||
| Peaks const * peaks ( void ) { return &_peaks; } | |||
| const char *name ( void ) { return _filename; } | |||
| nframes_t length ( void ) { return _length; } | |||
| // Peaks const * peaks ( void ) { return &_peaks; } | |||
| virtual bool open ( void ) = 0; | |||
| virtual void close ( void ) = 0; | |||
| virtual void seek ( nframes_t offset ) = 0; | |||
| virtual nframes_t read ( sample_t *buf, nframes_t len ) = 0; | |||
| virtual nframes_t read ( sample_t *buf, nframes_t start, nframes_t end ) = 0; | |||
| }; | |||
| @@ -17,7 +17,7 @@ | |||
| /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |||
| /*******************************************************************************/ | |||
| #include "Clip.H" | |||
| #include "Audio_File_SF.H" | |||
| #include "Timeline.H" | |||
| #include <sndfile.h> | |||
| @@ -25,56 +25,13 @@ | |||
| #include <stdlib.h> | |||
| #include <string.h> | |||
| Clip::Clip ( void ) : _peaks( this ) | |||
| { | |||
| _filename = NULL; | |||
| _length = 0; | |||
| } | |||
| /* Clip::Clip ( const char *filename ) : _peaks( this ) */ | |||
| /* { */ | |||
| /* _filename = filename; */ | |||
| /* SNDFILE *in; */ | |||
| /* SF_INFO si; */ | |||
| /* memset( &si, 0, sizeof( si ) ); */ | |||
| /* if ( ! ( in = sf_open( filename, SFM_READ, &si ) ) ) */ | |||
| /* { */ | |||
| /* printf( "couldn't open file\n" ); */ | |||
| /* return; */ | |||
| /* } */ | |||
| /* if ( si.channels != 1 ) */ | |||
| /* { */ | |||
| /* printf( "error: incompatible format\n" ); */ | |||
| /* return; */ | |||
| /* } */ | |||
| /* if ( si.samplerate != timeline->sample_rate ) */ | |||
| /* { */ | |||
| /* printf( "error: samplerate mismatch!\n" ); */ | |||
| /* return; */ | |||
| /* } */ | |||
| /* _length = si.frames; */ | |||
| /* sf_close( in ); */ | |||
| /* _peaks.open(); */ | |||
| /* } */ | |||
| Clip * | |||
| Clip::from_file ( const char *filename ) | |||
| Audio_File_SF * | |||
| Audio_File_SF::from_file ( const char *filename ) | |||
| { | |||
| SNDFILE *in; | |||
| SF_INFO si; | |||
| Clip *c = NULL; | |||
| Audio_File_SF *c = NULL; | |||
| memset( &si, 0, sizeof( si ) ); | |||
| @@ -96,18 +53,15 @@ Clip::from_file ( const char *filename ) | |||
| goto invalid; | |||
| } | |||
| c = new Clip; | |||
| c = new Audio_File_SF; | |||
| c->_filename = filename; | |||
| c->_length = si.frames; | |||
| sf_close( in ); | |||
| c->_peaks.open(); | |||
| return c; | |||
| invalid: | |||
| sf_close( in ); | |||
| @@ -115,7 +69,7 @@ invalid: | |||
| } | |||
| bool | |||
| Clip::open ( void ) | |||
| Audio_File_SF::open ( void ) | |||
| { | |||
| SF_INFO si; | |||
| @@ -128,27 +82,26 @@ Clip::open ( void ) | |||
| } | |||
| void | |||
| Clip::close ( void ) | |||
| Audio_File_SF::close ( void ) | |||
| { | |||
| sf_close( _in ); | |||
| } | |||
| void | |||
| Clip::seek ( nframes_t offset ) | |||
| Audio_File_SF::seek ( nframes_t offset ) | |||
| { | |||
| sf_seek( _in, offset, SEEK_SET ); | |||
| } | |||
| nframes_t | |||
| Clip::read ( sample_t *buf, nframes_t len ) | |||
| Audio_File_SF::read ( sample_t *buf, nframes_t len ) | |||
| { | |||
| return sf_read_float ( _in, buf, len ); | |||
| } | |||
| /** read samples from /start/ to /end/ into /buf/ */ | |||
| nframes_t | |||
| Clip::read ( sample_t *buf, nframes_t start, nframes_t end ) | |||
| Audio_File_SF::read ( sample_t *buf, nframes_t start, nframes_t end ) | |||
| { | |||
| open(); | |||
| @@ -17,36 +17,19 @@ | |||
| /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |||
| /*******************************************************************************/ | |||
| #pragma once | |||
| typedef unsigned long nframes_t; | |||
| typedef float sample_t; | |||
| #include "Peaks.H" | |||
| #include "Audio_File.H" | |||
| #include <sndfile.h> | |||
| class Clip | |||
| class Audio_File_SF : public Audio_File | |||
| { | |||
| const char *_filename; | |||
| Peaks _peaks; | |||
| nframes_t _length; /* length of clip in samples */ | |||
| // Audio_File_SF ( const char *filename ) | |||
| SNDFILE *_in; | |||
| public: | |||
| Clip ( ); | |||
| // Clip ( const char *filename ); | |||
| static Clip *from_file ( const char *filename ); | |||
| Peaks const * peaks ( void ) { return &_peaks; } | |||
| const char *name ( void ) { return _filename; } | |||
| nframes_t length ( void ) { return _length; } | |||
| static Audio_File_SF *from_file ( const char *filename ); | |||
| bool open ( void ); | |||
| void close ( void ); | |||
| @@ -66,7 +66,7 @@ public: | |||
| printf( "pasted file \"%s\"\n", file ); | |||
| Clip *c = Clip::from_file( file ); | |||
| Audio_File *c = Audio_File::from_file( file ); | |||
| if ( ! c ) | |||
| { | |||
| @@ -5,7 +5,7 @@ CXXFLAGS=-ggdb -Wall -O0 | |||
| LIBS=-lsndfile `fltk-config --ldflags` | |||
| # CXXFLAGS=`fltk-config -cxxflags` | |||
| SRCS= Clip.C Waveform.C Region.C Peaks.C main.C Track.C Timeline.C | |||
| SRCS= Waveform.C Region.C Peaks.C main.C Track.C Timeline.C Audio_File.C Audio_File_SF.C | |||
| OBJS=$(SRCS:.C=.o) | |||
| @@ -24,7 +24,7 @@ test: $(OBJS) | |||
| $(CXX) $(CXXFLAGS) $(LIBS) $(OBJS) -o $@ | |||
| clean: | |||
| rm -f $(OBJS) test | |||
| rm -f $(OBJS) test makedepend | |||
| valgrind: | |||
| valgrind ./test | |||
| @@ -31,7 +31,7 @@ | |||
| #include <sndfile.h> | |||
| #include "Clip.H" | |||
| #include "Audio_File.H" | |||
| #include "assert.h" | |||
| @@ -28,7 +28,7 @@ struct Peak { | |||
| float max; | |||
| }; | |||
| class Clip; | |||
| class Audio_File; | |||
| class Peaks | |||
| { | |||
| @@ -56,7 +56,7 @@ class Peaks | |||
| static peakbuffer peakbuf; | |||
| Clip *_clip; | |||
| Audio_File *_clip; | |||
| peakdata *_peaks; | |||
| @@ -67,9 +67,11 @@ class Peaks | |||
| Peak & peak ( nframes_t start, nframes_t end ) const; | |||
| Peaks ( ); | |||
| public: | |||
| Peaks ( Clip *c ) | |||
| Peaks ( Audio_File *c ) | |||
| { | |||
| _peaks = new peakdata; | |||
| @@ -81,7 +81,7 @@ Region::Region ( const Region & rhs ) | |||
| _scale = rhs._scale; | |||
| } | |||
| Region::Region ( Clip *c ) | |||
| Region::Region ( Audio_File *c ) | |||
| { | |||
| init(); | |||
| _clip = c; | |||
| @@ -23,7 +23,7 @@ | |||
| // #include "Waveform.H" | |||
| #include "Clip.H" | |||
| #include "Audio_File.H" | |||
| #include "Track.H" | |||
| #include "Timeline.H" | |||
| @@ -38,7 +38,7 @@ using namespace std; | |||
| class Region : public Track_Widget | |||
| { | |||
| Clip *_clip; /* clip this region represents */ | |||
| Audio_File *_clip; /* clip this region represents */ | |||
| float _scale; /* amplitude adjustment */ | |||
| @@ -56,7 +56,7 @@ public: | |||
| Fl_Boxtype box ( void ) const { return Region::_box; } | |||
| Region ( const Region & rhs ); | |||
| Region ( Clip *c ); | |||
| Region ( Audio_File *c ); | |||
| int handle ( int m ); | |||
| void draw_box( int X, int Y, int W, int H ); | |||
| @@ -24,7 +24,7 @@ | |||
| #include <FL/Fl_Scrollbar.H> | |||
| #include <FL/Fl_Widget.H> | |||
| #include "Clip.H" | |||
| #include "Audio_File.H" // just for nframes_t | |||
| #include <math.h> | |||
| #include <assert.h> | |||
| @@ -24,27 +24,14 @@ | |||
| #include <FL/fl_draw.H> | |||
| #include "Timeline.H" | |||
| // #include "Waveform.H" | |||
| #include "Clip.H" | |||
| #include "Audio_File.H" | |||
| // extern Timeline timeline; | |||
| // #include "Timeline.H" | |||
| #include <math.h> | |||
| /* void */ | |||
| /* Waveform::draw ( void ) */ | |||
| /* { */ | |||
| /* int X, Y, W, H; */ | |||
| /* fl_clip_box( x(), y(), w(), h(), X, Y, W, H ); */ | |||
| /* draw( X, y(), W, h() ); */ | |||
| /* } */ | |||
| /** draw a portion of /clip/'s waveform. coordinates are the portion to draw */ | |||
| void | |||
| draw_waveform ( int X, int Y, int W, int H, Clip *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color ) | |||
| draw_waveform ( int X, int Y, int W, int H, Audio_File *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color ) | |||
| { | |||
| fl_push_clip( X, Y, W, H ); | |||
| @@ -24,6 +24,6 @@ | |||
| #include "Timeline.H" | |||
| #include "Clip.H" | |||
| #include "Audio_File.H" | |||
| void draw_waveform ( int X, int Y, int W, int H, Clip *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color ); | |||
| void draw_waveform ( int X, int Y, int W, int H, Audio_File *_clip, nframes_t _start, nframes_t _end, float _scale, Fl_Color color ); | |||