/usr/include/tse3/EventTrack.h is in libtse3-dev 0.3.1-4.3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | /*
* @(#)EventTrack.h 3.00 24 May 1999
*
* Copyright (c) 2000 Pete Goodliffe (pete@cthree.org)
*
* This file is part of TSE3 - the Trax Sequencer Engine version 3.00.
*
* This library is modifiable/redistributable under the terms of the GNU
* General Public License.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING. If not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef TSE3_EVENTTRACK_H
#define TSE3_EVENTTRACK_H
#include "tse3/listen/EventTrack.h"
#include "tse3/Notifier.h"
#include "tse3/Midi.h"
#include "tse3/Playable.h"
#include <vector>
#include <algorithm>
#include <functional>
#include <cstddef>
namespace TSE3
{
/**
* The EventTrack provides a simple track containing a given type of
* events.
*
* It is used with instantiations of the @ref Event generic class.
*
* The EventTrack is used as a base class for other types of TSE3 track,
* for example the @ref TimeSigTrack and @ref TempoTrack.
*
* The contained @ref Event objects are held by value.
*
* The EventTrack has two modes of operating, specified as a boolean
* parameter in the constructor. The normal operation (as used by most
* subclasses) is to prevent the insertion of two events with the same
* time. For example, you don't want to have two different time signatures
* at the same time. The second mode of operation allows this time
* duplication.
*
* @short A simple track containing @ref Event objects
* @author Pete Goodliffe
* @version 3.00
* @see Event
* @see EventTrackListener
*/
template <class etype>
class EventTrack : public Playable,
public Notifier<EventTrackListener<etype> >
{
public:
/**
* Creates an EventTrack.
*
* The parameter specifies whether or not duplicate time values
* are allowed in the EventTrack. When false, you may not insert
* two events with the same time.
*
* @param allowDuplicates Whether to allow duplicate time values
*/
EventTrack(bool allowDuplicates = false) : dup(allowDuplicates) {}
~EventTrack() {}
typedef Event<etype> event_type;
/**
* Returns the number of events in this track.
*
* @return The number of events in this track
*/
size_t size() const { return data.size(); }
/**
* Returns the nth event in the track.
*
* The value returned for an index that is out of range is
* undefined. The @ref size method describes the valid
* values.
*
* @param n Index
* @return Event at index n
*/
event_type const &operator[](const size_t n) const
{
return data[n];
}
/**
* Returns the index of the event at a given @ref Clock.
*
* @param c Clock value to search for.
* @param roundup If true index returns the event at or after
* the specified @ref Clock. If false, returns
* the event at of before the specified @ref
* Clock.
* @return Index of event. If past the end of the data then returns
* 'size'.
*/
int index(const Clock c, bool roundup = true);
/**
* Inserts an @ref Event into the EventTrack, and returns the
* index of the insertion point.
*
* If duplicate times are not allowed (see
* @ref EventTrack::EventTrack) then the new @ref Event will
* replace the existing @ref Event at this time.
*
* If duplicate times are allowed then the new @ref Event is
* inserted after any other events with the same time.
*
* @param event The event to insert
* @returns Index of new event
* @see erase
*/
size_t insert(const event_type &event);
/**
* Erase an event.
*
* If the event is not in this track then no error is raised.
*
* @param event The event to erase
* @see insert
*/
void erase(const event_type &event);
/**
* Erase an event.
*
* If the index is invalid then no error is raised.
*
* @param index Index of the event to erase
* @see insert
*/
void erase(size_t index);
protected:
std::vector<event_type> data;
private:
EventTrack &operator=(const EventTrack &);
EventTrack(const EventTrack &);
bool dup;
};
template <class etype>
int EventTrack<etype>::index(const Clock c, bool roundup)
{
typename std::vector< TSE3::Event<etype> >::iterator i = data.begin();
while (i != data.end() && !(c <= (*i).time))
{
++i;
}
if (!roundup
&& i != data.begin()
&& (i == data.end() || (*i).time != c))
{
--i;
}
return i - data.begin();
}
template <class etype>
size_t EventTrack<etype>::insert(const event_type &event)
{
typename std::vector<event_type>::iterator i = data.begin();
while (i != data.end() && *i <= event) ++i;
if (!dup && i != data.begin() && (i-1)->time == event.time)
{
*(i-1) = event;
size_t index = i - data.begin();
Notifier<EventTrackListener<etype> >::notify
(&EventTrackListener<etype>::EventTrack_EventAltered, index);
return index;
}
else
{
size_t index = i - data.begin();
data.insert(i, event);
Notifier<EventTrackListener<etype> >::notify
(&EventTrackListener<etype>::EventTrack_EventInserted, index);
return index;
}
}
template <class etype>
void EventTrack<etype>::erase(const event_type &event)
{
typename std::vector<event_type>::iterator i =
std::find_if(data.begin(), data.end(),
typename event_type::equal_to(event));
if (i != data.end())
{
size_t index = i - data.begin();
data.erase(i);
Notifier<EventTrackListener<etype> >::notify
(&EventTrackListener<etype>::EventTrack_EventErased, index);
}
}
template <class etype>
void EventTrack<etype>::erase(size_t index)
{
if (index < data.size())
{
data.erase(data.begin()+index);
Notifier<EventTrackListener<etype> >::notify
(&EventTrackListener<etype>::EventTrack_EventErased, index);
}
}
}
#endif
|