summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-11-06 18:12:49 -0500
committerDavid Robillard <d@drobilla.net>2016-12-03 15:18:20 -0500
commit0f5a73a7fd00015b9d95bf05f5f4266ae782d469 (patch)
treece5bda90ed6b3a09c0c4ac1e092d67d754eb73ca /libs
parent90fcdcfde9459f3bc65c48568dc2a5faf4cd7708 (diff)
Fix Sequence/Event const-correctness issues
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/midi_playlist.cc2
-rw-r--r--libs/ardour/midi_source.cc30
-rw-r--r--libs/ardour/smf_source.cc4
-rw-r--r--libs/evoral/evoral/Sequence.hpp5
-rw-r--r--libs/evoral/src/Sequence.cpp4
5 files changed, 27 insertions, 18 deletions
diff --git a/libs/ardour/midi_playlist.cc b/libs/ardour/midi_playlist.cc
index 4c200f60b5..67764d66ae 100644
--- a/libs/ardour/midi_playlist.cc
+++ b/libs/ardour/midi_playlist.cc
@@ -92,7 +92,7 @@ MidiPlaylist::~MidiPlaylist ()
template<typename Time>
struct EventsSortByTimeAndType {
- bool operator() (Evoral::Event<Time>* a, Evoral::Event<Time>* b) {
+ bool operator() (const Evoral::Event<Time>* a, const Evoral::Event<Time>* b) {
if (a->time() == b->time()) {
if (parameter_is_midi ((AutomationType)a->event_type()) &&
parameter_is_midi ((AutomationType)b->event_type())) {
diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc
index d1a3455ba2..d14a23d666 100644
--- a/libs/ardour/midi_source.cc
+++ b/libs/ardour/midi_source.cc
@@ -190,8 +190,8 @@ MidiSource::midi_read (const Lock& lm,
MidiStateTracker* tracker,
MidiChannelFilter* filter,
const std::set<Evoral::Parameter>& filtered,
- const double pos_beats,
- const double start_beats) const
+ const double pos_beats,
+ const double start_beats) const
{
BeatsFramesConverter converter(_session.tempo_map(), source_start);
@@ -245,18 +245,28 @@ MidiSource::midi_read (const Lock& lm,
/* in range */
- if (filter && filter->filter(i->buffer(), i->size())) {
- DEBUG_TRACE (DEBUG::MidiSourceIO,
- string_compose ("%1: filter event @ %2 type %3 size %4\n",
- _name, time_frames, i->event_type(), i->size()));
- continue;
- }
-
if (loop_range) {
time_frames = loop_range->squish (time_frames);
}
- dst.write (time_frames, i->event_type(), i->size(), i->buffer());
+ const uint8_t status = i->buffer()[0];
+ const bool is_channel_event = (0x80 <= (status & 0xF0)) && (status <= 0xE0);
+ if (filter && is_channel_event) {
+ /* Copy event so the filter can modify the channel. I'm not
+ sure if this is necessary here (channels are mapped later in
+ buffers anyway), but it preserves existing behaviour without
+ destroying events in the model during read. */
+ Evoral::Event<Evoral::Beats> ev(*i, true);
+ if (!filter->filter(ev.buffer(), ev.size())) {
+ dst.write(time_frames, ev.event_type(), ev.size(), ev.buffer());
+ } else {
+ DEBUG_TRACE (DEBUG::MidiSourceIO,
+ string_compose ("%1: filter event @ %2 type %3 size %4\n",
+ _name, time_frames, i->event_type(), i->size()));
+ }
+ } else {
+ dst.write (time_frames, i->event_type(), i->size(), i->buffer());
+ }
#ifndef NDEBUG
if (DEBUG_ENABLED(DEBUG::MidiSourceIO)) {
diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc
index 33ba6e2a00..0ddc14f78d 100644
--- a/libs/ardour/smf_source.cc
+++ b/libs/ardour/smf_source.cc
@@ -604,8 +604,8 @@ SMFSource::safe_midi_file_extension (const string& file)
}
static bool compare_eventlist (
- const std::pair< Evoral::Event<Evoral::Beats>*, gint >& a,
- const std::pair< Evoral::Event<Evoral::Beats>*, gint >& b) {
+ const std::pair< const Evoral::Event<Evoral::Beats>*, gint >& a,
+ const std::pair< const Evoral::Event<Evoral::Beats>*, gint >& b) {
return ( a.first->time() < b.first->time() );
}
diff --git a/libs/evoral/evoral/Sequence.hpp b/libs/evoral/evoral/Sequence.hpp
index 8485f94a49..7c0818a7fb 100644
--- a/libs/evoral/evoral/Sequence.hpp
+++ b/libs/evoral/evoral/Sequence.hpp
@@ -232,9 +232,8 @@ public:
void invalidate(std::set<WeakNotePtr>* notes);
- const Event<Time>& operator*() const { return *_event; }
- const boost::shared_ptr< Event<Time> > operator->() const { return _event; }
- const boost::shared_ptr< Event<Time> > get_event_pointer() { return _event; }
+ const Event<Time>& operator*() const { return *_event; }
+ const boost::shared_ptr< const Event<Time> > operator->() const { return _event; }
const const_iterator& operator++(); // prefix only
diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp
index 1d518c3f07..b44091371b 100644
--- a/libs/evoral/src/Sequence.cpp
+++ b/libs/evoral/src/Sequence.cpp
@@ -203,7 +203,7 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>&
DEBUG_TRACE(DEBUG::Sequence,
string_compose("Starting at type 0x%1 : 0x%2 @ %3\n",
(int)_event->event_type(),
- (int)((MIDIEvent<Time>*)_event.get())->type(),
+ (int)_event->buffer()[0],
_event->time()));
}
}
@@ -330,7 +330,7 @@ Sequence<Time>::const_iterator::operator++()
assert(_event && _event->buffer() && _event->size() > 0);
- const MIDIEvent<Time>& ev = *((MIDIEvent<Time>*)_event.get());
+ const MIDIEvent<Time>& ev = *((const MIDIEvent<Time>*)_event.get());
if (!( ev.is_note()
|| ev.is_cc()