provide a generalized Sequence::get_notes()-by-predicate method, and prototypes for 2 future methods

git-svn-id: svn://localhost/ardour2/branches/3.0@7191 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-05-28 21:36:38 +00:00
parent 8932625869
commit 60ec5dd339
2 changed files with 85 additions and 0 deletions

View file

@ -137,6 +137,24 @@ public:
inline Notes& notes() { return _notes; } inline Notes& notes() { return _notes; }
inline const Notes& notes() const { return _notes; } inline const Notes& notes() const { return _notes; }
enum NoteOperator {
PitchEqual,
PitchLessThan,
PitchLessThanOrEqual,
PitchGreater,
PitchGreaterThanOrEqual,
VelocityEqual,
VelocityLessThan,
VelocityLessThanOrEqual,
VelocityGreater,
VelocityGreaterThanOrEqual,
};
void get_notes (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
void remove_overlapping_notes ();
void remove_duplicate_notes ();
void set_notes (const Sequence<Time>::Notes& n); void set_notes (const Sequence<Time>::Notes& n);
typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes; typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes;

View file

@ -797,6 +797,73 @@ Sequence<Time>::note_lower_bound (Time t) const
return i; return i;
} }
template<typename Time>
void
Sequence<Time>::get_notes (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
{
ReadLock lock (read_lock());
for (typename Notes::const_iterator i = _notes.begin(); i != _notes.end(); ++i) {
if (chan_mask != 0 && !((1<<(*i)->channel()) & chan_mask)) {
continue;
}
switch (op) {
case PitchEqual:
if ((*i)->note() == val) {
n.insert (*i);
}
break;
case PitchLessThan:
if ((*i)->note() < val) {
n.insert (*i);
}
break;
case PitchLessThanOrEqual:
if ((*i)->note() <= val) {
n.insert (*i);
}
break;
case PitchGreater:
if ((*i)->note() > val) {
n.insert (*i);
}
break;
case PitchGreaterThanOrEqual:
if ((*i)->note() >= val) {
n.insert (*i);
}
break;
case VelocityEqual:
if ((*i)->velocity() == val) {
n.insert (*i);
}
break;
case VelocityLessThan:
if ((*i)->velocity() < val) {
n.insert (*i);
}
break;
case VelocityLessThanOrEqual:
if ((*i)->velocity() <= val) {
n.insert (*i);
}
break;
case VelocityGreater:
if ((*i)->velocity() > val) {
n.insert (*i);
}
break;
case VelocityGreaterThanOrEqual:
if ((*i)->velocity() >= val) {
n.insert (*i);
}
break;
}
}
}
template class Sequence<Evoral::MusicalTime>; template class Sequence<Evoral::MusicalTime>;
} // namespace Evoral } // namespace Evoral