2 Copyright (C) 1999-2004 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.
23 #include "ardour/timestamps.h"
25 #include "pbd/error.h"
26 #include "pbd/enumwriter.h"
28 #include "ardour/ardour.h"
29 #include "ardour/audio_diskstream.h"
30 #include "ardour/butler.h"
31 #include "ardour/debug.h"
32 #include "ardour/session_event.h"
37 using namespace ARDOUR;
40 MultiAllocSingleReleasePool SessionEvent::pool ("event", sizeof (SessionEvent), 512);
43 SessionEventManager::add_event (nframes64_t frame, SessionEvent::Type type, nframes64_t target_frame)
45 SessionEvent* ev = new SessionEvent (type, SessionEvent::Add, frame, target_frame, 0);
50 SessionEventManager::remove_event (nframes64_t frame, SessionEvent::Type type)
52 SessionEvent* ev = new SessionEvent (type, SessionEvent::Remove, frame, 0, 0);
57 SessionEventManager::replace_event (SessionEvent::Type type, nframes64_t frame, nframes64_t target)
59 SessionEvent* ev = new SessionEvent (type, SessionEvent::Replace, frame, target, 0);
64 SessionEventManager::clear_events (SessionEvent::Type type)
66 SessionEvent* ev = new SessionEvent (type, SessionEvent::Clear, 0, 0, 0);
72 SessionEventManager::dump_events () const
74 cerr << "EVENT DUMP" << endl;
75 for (Events::const_iterator i = events.begin(); i != events.end(); ++i) {
76 cerr << "\tat " << (*i)->action_frame << ' ' << (*i)->type << " target = " << (*i)->target_frame << endl;
78 cerr << "Next event: ";
80 if ((Events::const_iterator) next_event == events.end()) {
81 cerr << "none" << endl;
83 cerr << "at " << (*next_event)->action_frame << ' '
84 << (*next_event)->type << " target = "
85 << (*next_event)->target_frame << endl;
87 cerr << "Immediate events pending:\n";
88 for (Events::const_iterator i = immediate_events.begin(); i != immediate_events.end(); ++i) {
89 cerr << "\tat " << (*i)->action_frame << ' ' << (*i)->type << " target = " << (*i)->target_frame << endl;
91 cerr << "END EVENT_DUMP" << endl;
95 SessionEventManager::merge_event (SessionEvent* ev)
98 case SessionEvent::Remove:
103 case SessionEvent::Replace:
107 case SessionEvent::Clear:
108 _clear_event_type (ev->type);
112 case SessionEvent::Add:
116 /* try to handle immediate events right here */
118 if (ev->action_frame == 0) {
124 case SessionEvent::AutoLoop:
125 case SessionEvent::StopOnce:
126 _clear_event_type (ev->type);
130 for (Events::iterator i = events.begin(); i != events.end(); ++i) {
131 if ((*i)->type == ev->type && (*i)->action_frame == ev->action_frame) {
132 error << string_compose(_("Session: cannot have two events of type %1 at the same frame (%2)."),
133 enum_2_string (ev->type), ev->action_frame) << endmsg;
139 events.insert (events.begin(), ev);
140 events.sort (SessionEvent::compare);
141 next_event = events.begin();
145 /** @return true when @a ev is deleted. */
147 SessionEventManager::_replace_event (SessionEvent* ev)
152 /* private, used only for events that can only exist once in the queue */
154 for (i = events.begin(); i != events.end(); ++i) {
155 if ((*i)->type == ev->type) {
156 (*i)->action_frame = ev->action_frame;
157 (*i)->target_frame = ev->target_frame;
166 if (i == events.end()) {
167 events.insert (events.begin(), ev);
170 events.sort (SessionEvent::compare);
171 next_event = events.end();
177 /** @return true when @a ev is deleted. */
179 SessionEventManager::_remove_event (SessionEvent* ev)
184 for (i = events.begin(); i != events.end(); ++i) {
185 if ((*i)->type == ev->type && (*i)->action_frame == ev->action_frame) {
191 if (i == next_event) {
199 if (i != events.end()) {
207 SessionEventManager::_clear_event_type (SessionEvent::Type type)
209 Events::iterator i, tmp;
211 for (i = events.begin(); i != events.end(); ) {
216 if ((*i)->type == type) {
218 if (i == next_event) {
227 for (i = immediate_events.begin(); i != immediate_events.end(); ) {
232 if ((*i)->type == type) {
234 immediate_events.erase (i);