2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
23 #include "Sequence_Region.H"
30 class Audio_Region : public Sequence_Region
34 Audio_Region & operator = ( const Audio_Region &rhs );
36 static void peaks_ready_callback ( void *v );
40 static bool inherit_track_color;
45 enum fade_type_e { Linear = 0, Sigmoid, Logarithmic, Parabolic };
46 enum fade_dir_e { In, Out };
58 operator< ( const Fade &rhs ) const
60 return length < rhs.length;
63 double increment ( void ) const
68 /** Return gain for frame /index/ of /nframes/ on a gain curve
70 /* FIXME: calling a function per sample is bad, switching on
71 * type mid fade is bad. */
73 gain ( const double fi ) const
80 return (1.0f - cos( fi * M_PI )) / 2.0f;
82 return pow( 0.1f, (1.0f - fi) * 3.0f );
84 return 1.0f - (1.0f - fi) * (1.0f - fi);
90 void apply ( sample_t *buf, fade_dir_e dir, nframes_t start, nframes_t nframes ) const;
93 /* struct Fade_In : public Fade; */
94 /* struct Fade_Out : public Fade; */
98 Audio_File *_clip; /* clip this region represents */
100 bool _adjusting_gain;
101 float _scale; /* amplitude adjustment */
106 nframes_t _loop; /* loop point */
108 friend class Track; /* for _clip */
110 Fl_Menu_Button & menu ( void );
112 static void menu_cb ( Fl_Widget *w, void *v );
113 void menu_cb ( const Fl_Menu_ *m );
115 void draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool filled, int X, int W );
119 virtual void get ( Log_Entry &e ) const;
120 virtual void set ( Log_Entry &e );
122 void draw_label ( const char *label, Fl_Align align )
124 Sequence_Widget::draw_label( label, align );
127 int handle ( int m );
128 void draw_label ( void );
129 void draw_box ( void );
131 void resize ( void );
135 LOG_CREATE_FUNC( Audio_Region );
137 SEQUENCE_WIDGET_CLONE_FUNC( Audio_Region );
139 static Fl_Boxtype _box;
140 static Fl_Color _selection_color;
141 Fl_Color selection_color ( void ) const { return _selection_color; }
142 void selection_color ( Fl_Color v ) { _selection_color = v; }
151 bool current ( void ) const { return this == belowmouse(); }
153 const char * source_name ( void ) const;
155 Audio_Region ( const Audio_Region & rhs );
156 Audio_Region ( Audio_File *c );
157 Audio_Region ( Audio_File *c, Sequence *t, nframes_t o );
160 Fl_Boxtype box ( void ) const { return Audio_Region::_box; }
161 Fl_Align align ( void ) const { return (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE | FL_ALIGN_CLIP ); }
163 void normalize ( void );
164 void split ( nframes_t where );
165 bool recording ( void ) const;
168 nframes_t read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) const;
169 nframes_t write ( nframes_t nframes );
170 void prepare ( void );
171 bool finalize ( nframes_t frame );