second (and hopefully) final part of changes to respond to header format changes...
[ArdourMidi.git] / libs / ardour / session_butler.cc
blobc92c0604c7d5af9adbc43229ff378402aa3bd5aa
1 /*
2 Copyright (C) 1999-2002 Paul Davis
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.
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.
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.
20 #include <algorithm>
21 #include <string>
22 #include <cmath>
23 #include <cerrno>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <poll.h>
28 #include <glibmm/thread.h>
30 #include "pbd/error.h"
31 #include "pbd/pthread_utils.h"
32 #include "pbd/stacktrace.h"
34 #include "ardour/audio_diskstream.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/butler.h"
37 #include "ardour/configuration.h"
38 #include "ardour/crossfade.h"
39 #include "ardour/io.h"
40 #include "ardour/midi_diskstream.h"
41 #include "ardour/session.h"
42 #include "ardour/timestamps.h"
43 #include "ardour/track.h"
45 #include "i18n.h"
47 using namespace std;
48 using namespace ARDOUR;
49 using namespace PBD;
51 /* XXX put this in the right place */
53 static inline uint32_t next_power_of_two (uint32_t n)
55 --n;
56 n |= n >> 16;
57 n |= n >> 8;
58 n |= n >> 4;
59 n |= n >> 2;
60 n |= n >> 1;
61 ++n;
62 return n;
65 /*---------------------------------------------------------------------------
66 BUTLER THREAD
67 ---------------------------------------------------------------------------*/
69 void
70 Session::adjust_playback_buffering ()
72 request_stop (false, false);
73 SessionEvent *ev = new SessionEvent (SessionEvent::AdjustPlaybackBuffering, SessionEvent::Add, SessionEvent::Immediate, 0, 0, 0.0);
74 queue_event (ev);
77 void
78 Session::adjust_capture_buffering ()
80 request_stop (false, false);
81 SessionEvent *ev = new SessionEvent (SessionEvent::AdjustCaptureBuffering, SessionEvent::Add, SessionEvent::Immediate, 0, 0, 0.0);
82 queue_event (ev);
85 void
86 Session::schedule_playback_buffering_adjustment ()
88 add_post_transport_work (PostTransportAdjustPlaybackBuffering);
89 _butler->schedule_transport_work ();
92 void
93 Session::schedule_capture_buffering_adjustment ()
95 add_post_transport_work (PostTransportAdjustCaptureBuffering);
96 _butler->schedule_transport_work ();
99 void
100 Session::schedule_curve_reallocation ()
102 add_post_transport_work (PostTransportCurveRealloc);
103 _butler->schedule_transport_work ();
106 void
107 Session::request_overwrite_buffer (Track* t)
109 SessionEvent *ev = new SessionEvent (SessionEvent::Overwrite, SessionEvent::Add, SessionEvent::Immediate, 0, 0, 0.0);
110 ev->set_ptr (t);
111 queue_event (ev);
114 /** Process thread. */
115 void
116 Session::overwrite_some_buffers (Track* t)
118 if (actively_recording()) {
119 return;
122 if (t) {
124 t->set_pending_overwrite (true);
126 } else {
128 boost::shared_ptr<RouteList> rl = routes.reader();
129 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
130 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
131 if (tr) {
132 tr->set_pending_overwrite (true);
137 add_post_transport_work (PostTransportOverWrite);
138 _butler->schedule_transport_work ();
141 uint32_t
142 Session::playback_load ()
144 return (uint32_t) g_atomic_int_get (&_playback_load);
147 uint32_t
148 Session::capture_load ()
150 return (uint32_t) g_atomic_int_get (&_capture_load);