Update NTK.
[nondaw.git] / timeline / src / Track.H
blob523165f7aac8247a4f0b3c04b95e64e3364b4433
2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles                                     */
4 /*                                                                             */
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.                                                  */
9 /*                                                                             */
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   */
13 /* more details.                                                               */
14 /*                                                                             */
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 /*******************************************************************************/
20 #pragma once
22 #include <FL/Fl.H>
23 #include "Sequence.H"
24 #include <FL/Fl_Group.H>
25 #include <FL/Fl_Input.H>
26 #include <FL/Fl_Button.H>
27 #include <FL/Fl_Menu_Button.H>
28 #include <FL/Fl_Pack.H>
29 #include <FL/Fl_Box.H>
30 #include <FL/fl_draw.H>
32 #include "Loggable.H"
34 /* TODO: rename this to Audio_Track or something since it's clearly audio specific. */
36 #include <vector>
37 using std::vector;
39 #include "JACK/Port.H"
41 #include "Timeline.H"
43 class Control_Sequence;
44 class Annotation_Sequence;
45 class Playback_DS;
46 class Record_DS;
47 // class JACK::Port;
48 class Audio_Region;
49 class Audio_File;
51 //class Audio_Sequence;
53 #include "Audio_Sequence.H"
55 class Track : public Fl_Group, public Loggable
58     /* not permitted  */
59     Track ( const Track &rhs );
60     Track & operator= ( const Track &rhs );
62 public:
64     Track ( const char *L, int channels=1 );
65     virtual ~Track ( );
67     static bool soloing ( void ) { return _soloing; }
69     static const char *capture_format;
71     struct Capture
72     {
73         Audio_File *audio_file;
74         Audio_Region *region;
76         Capture ( )
77             {
78                 region = 0;
79                 audio_file = 0;
80             }
81     };
83     Fl_Color color ( void ) const { return child(0)->color(); }
84     void color ( Fl_Color c ) { child(0)->color( c ); }
86     bool operator< ( const Track &rhs ) const
87         {
88             return _row < rhs._row;
89         }
91 private:
93     static int _soloing;
95     char *_name;
97     bool _selected;
99     bool _show_all_takes;
101     int _size;
103     int _row;
105     enum { AUDIO } _type;
107     Audio_Sequence *_sequence;
109     bool configure_outputs ( int n );
110     bool configure_inputs ( int n );
112     void update_port_names ( void );
113     const char *name_for_port( JACK::Port::type_e type, int n );
114     void update_take_menu ( void );
116     Track ( );
117     void init ( void );
120 protected:
122     void get ( Log_Entry &e ) const;
123     void get_unjournaled ( Log_Entry &e ) const;
124     void set ( Log_Entry &e );
126 public:
128     virtual void log_children ( void ) const;
130     Fl_Input       *name_field;
131     Fl_Button      *record_button;
132     Fl_Button      *mute_button;
133     Fl_Button      *solo_button;
134     Fl_Menu_Button *take_menu;
135     Fl_Group       *controls;
137     Fl_Pack        *pack;
138     Fl_Pack        *annotation;
139     Fl_Pack        *control;
140     Fl_Pack        *takes;
143     vector<JACK::Port>   input;                        /* input ports... */
144     vector<JACK::Port>   output;                       /* output ports... */
146     Playback_DS    *playback_ds;
147     Record_DS      *record_ds;
149     /* for loggable */
150     LOG_CREATE_FUNC( Track );
152     void add ( Annotation_Sequence *t );
153     void remove ( Annotation_Sequence *t );
155     void add ( Control_Sequence *t );
156     void add ( Audio_Sequence *t );
157     void remove ( Audio_Sequence *t );
158     void remove ( Control_Sequence *t );
160     void select ( int X, int Y, int W, int H, bool include_control, bool merge_control );
162     int size ( void ) const { return _size; }
164     int ncontrols ( void ) { return control->children(); }
166     void adjust_size ( void );
167     void size ( int v );
169     int height ( void ) const
170         {
171             static int table[] = { 30, 80, 150, 300 };
173             return table[ _size ];
174         }
176     void show_all_takes ( bool b )
177         {
178             _show_all_takes = b;
179             adjust_size();
180         }
182     void name ( const char *name )
183         {
184             if ( _name )
185                 free( _name );
187             _name = strdup( name );
189             if ( name_field )
190                 name_field->value( _name );
192             update_port_names();
193         }
195     const char * name ( void ) const { return _name; }
196     bool mute ( void ) const { return mute_button->value(); }
197     void mute ( bool b ) { mute_button->value( b ); }
198     bool solo ( void ) const { return solo_button->value(); }
199     void solo ( bool b );
201     bool armed ( void ) const { return record_button->value(); }
202     void armed ( bool b ) { record_button->value( b ); }
204     bool selected ( void ) const { return _selected; }
206     int row ( void ) const;
207     void row ( int );
209     static void cb_input_field ( Fl_Widget *w, void *v );
210     void cb_input_field ( void );
211     static void cb_button ( Fl_Widget *w, void *v );
212     void cb_button ( Fl_Widget *w );
215     static int width ( void ) { return 150; }
217     void sequence ( Audio_Sequence * t );
218     Audio_Sequence * sequence ( void ) const { return _sequence; }
221     Fl_Menu_Button & menu ( void ) const;
223     static void menu_cb ( Fl_Widget *w, void *v );
224     void menu_cb ( const Fl_Menu_ *m );
226     void draw ( void );
227     int handle ( int m );
229     /* Engine */
230     const Audio_Region *capture_region ( void ) const;
231     Capture *capture ( void );
233     void resize_buffers ( nframes_t nframes );
234     nframes_t process_input ( nframes_t nframes );
235     nframes_t process_output ( nframes_t nframes );
236     void seek ( nframes_t frame );
237     void delay ( nframes_t frames );
239     void record ( Capture *c, nframes_t frame );
240     void write ( Capture *c, sample_t *buf, nframes_t nframes );
241     void finalize ( Capture *c, nframes_t frame );