Re-add erroneously-removed methods related to cut/copy of
[ardour.git] / libs / ardour / session_butler.cc
1 /*
2     Copyright (C) 1999-2002 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 */
19
20 #include <algorithm>
21 #include <string>
22 #include <cmath>
23 #include <cerrno>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <poll.h>
27
28 #include <glibmm/thread.h>
29
30 #include "pbd/error.h"
31 #include "pbd/pthread_utils.h"
32 #include "pbd/stacktrace.h"
33
34 #include "ardour/audio_diskstream.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/butler.h"
37 #include "ardour/configuration.h"
38 #include "ardour/io.h"
39 #include "ardour/midi_diskstream.h"
40 #include "ardour/session.h"
41 #include "ardour/timestamps.h"
42 #include "ardour/track.h"
43
44 #include "i18n.h"
45
46 using namespace std;
47 using namespace ARDOUR;
48 using namespace PBD;
49
50 /* XXX put this in the right place */
51
52 static inline uint32_t next_power_of_two (uint32_t n)
53 {
54         --n;
55         n |= n >> 16;
56         n |= n >> 8;
57         n |= n >> 4;
58         n |= n >> 2;
59         n |= n >> 1;
60         ++n;
61         return n;
62 }
63
64 /*---------------------------------------------------------------------------
65  BUTLER THREAD
66  ---------------------------------------------------------------------------*/
67
68 void
69 Session::adjust_playback_buffering ()
70 {
71         request_stop (false, false);
72         SessionEvent *ev = new SessionEvent (SessionEvent::AdjustPlaybackBuffering, SessionEvent::Add, SessionEvent::Immediate, 0, 0, 0.0);
73         queue_event (ev);
74 }
75
76 void
77 Session::adjust_capture_buffering ()
78 {
79         request_stop (false, false);
80         SessionEvent *ev = new SessionEvent (SessionEvent::AdjustCaptureBuffering, SessionEvent::Add, SessionEvent::Immediate, 0, 0, 0.0);
81         queue_event (ev);
82 }
83
84 void
85 Session::schedule_playback_buffering_adjustment ()
86 {
87         add_post_transport_work (PostTransportAdjustPlaybackBuffering);
88         _butler->schedule_transport_work ();
89 }
90
91 void
92 Session::schedule_capture_buffering_adjustment ()
93 {
94         add_post_transport_work (PostTransportAdjustCaptureBuffering);
95         _butler->schedule_transport_work ();
96 }
97
98 void
99 Session::schedule_curve_reallocation ()
100 {
101         add_post_transport_work (PostTransportCurveRealloc);
102         _butler->schedule_transport_work ();
103 }
104
105 void
106 Session::request_overwrite_buffer (Track* t)
107 {
108         SessionEvent *ev = new SessionEvent (SessionEvent::Overwrite, SessionEvent::Add, SessionEvent::Immediate, 0, 0, 0.0);
109         ev->set_ptr (t);
110         queue_event (ev);
111 }
112
113 /** Process thread. */
114 void
115 Session::overwrite_some_buffers (Track* t)
116 {
117         if (actively_recording()) {
118                 return;
119         }
120
121         if (t) {
122
123                 t->set_pending_overwrite (true);
124
125         } else {
126
127                 boost::shared_ptr<RouteList> rl = routes.reader();
128                 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
129                         boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
130                         if (tr) {
131                                 tr->set_pending_overwrite (true);
132                         }
133                 }
134         }
135
136         add_post_transport_work (PostTransportOverWrite);
137         _butler->schedule_transport_work ();
138 }
139
140 uint32_t
141 Session::playback_load ()
142 {
143         return (uint32_t) g_atomic_int_get (&_playback_load);
144 }
145
146 uint32_t
147 Session::capture_load ()
148 {
149         return (uint32_t) g_atomic_int_get (&_capture_load);
150 }