Added missing files for new Track class (oops)
[ardour.git] / libs / ardour / track.cc
1 /*
2     Copyright (C) 2006 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #include <pbd/error.h>
19 #include <sigc++/retype.h>
20 #include <sigc++/retype_return.h>
21 #include <sigc++/bind.h>
22
23 #include <ardour/audio_track.h>
24 #include <ardour/audio_diskstream.h>
25 #include <ardour/session.h>
26 #include <ardour/redirect.h>
27 #include <ardour/audioregion.h>
28 #include <ardour/audiosource.h>
29 #include <ardour/route_group_specialized.h>
30 #include <ardour/insert.h>
31 #include <ardour/audioplaylist.h>
32 #include <ardour/panner.h>
33 #include <ardour/utils.h>
34
35 #include "i18n.h"
36
37 using namespace std;
38 using namespace ARDOUR;
39 using namespace PBD;
40
41 Track::Track (Session& sess, string name, Route::Flag flag, TrackMode mode, Buffer::Type default_type)
42         : Route (sess, name, 1, -1, -1, -1, flag, default_type)
43         , _diskstream (0)
44         ,  _rec_enable_control (*this)
45 {
46         _declickable = true;
47         _freeze_record.state = NoFreeze;
48         _saved_meter_point = _meter_point;
49         _mode = mode;
50 }
51
52 Track::Track (Session& sess, const XMLNode& node, Buffer::Type default_type)
53         : Route (sess, "to be renamed", 0, 0, -1, -1, Route::Flag(0), default_type)
54         , _diskstream (0)
55         , _rec_enable_control (*this)
56 {
57         _freeze_record.state = NoFreeze;
58         _declickable = true;
59         _saved_meter_point = _meter_point;
60 }
61
62 void
63 Track::set_meter_point (MeterPoint p, void *src)
64 {
65         Route::set_meter_point (p, src);
66 }
67
68 XMLNode&
69 Track::get_state ()
70 {
71         return state (true);
72 }
73
74 XMLNode&
75 Track::get_template ()
76 {
77         return state (false);
78 }
79
80 void
81 Track::toggle_monitor_input ()
82 {
83         for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
84                 (*i)->request_monitor_input(!(*i)->monitoring_input());
85         }
86 }
87
88 jack_nframes_t
89 Track::update_total_latency ()
90 {
91         _own_latency = 0;
92
93         for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
94                 if ((*i)->active ()) {
95                         _own_latency += (*i)->latency ();
96                 }
97         }
98
99         set_port_latency (_own_latency);
100
101         return _own_latency;
102 }
103
104
105 Track::FreezeRecord::~FreezeRecord ()
106 {
107         for (vector<FreezeRecordInsertInfo*>::iterator i = insert_info.begin(); i != insert_info.end(); ++i) {
108                 delete *i;
109         }
110 }
111
112 Track::FreezeState
113 Track::freeze_state() const
114 {
115         return _freeze_record.state;
116 }
117
118 Track::RecEnableControllable::RecEnableControllable (Track& s)
119         : track (s)
120 {
121 }
122
123 void
124 Track::RecEnableControllable::set_value (float val)
125 {
126         bool bval = ((val >= 0.5f) ? true: false);
127         track.set_record_enable (bval, this);
128 }
129
130 float
131 Track::RecEnableControllable::get_value (void) const
132 {
133         if (track.record_enabled()) { return 1.0f; }
134         return 0.0f;
135 }
136