evoral: add Sequence::channels_present()

This commit is contained in:
Paul Davis
2025-03-08 17:56:44 -07:00
parent cee0b498e9
commit fd890b4891
2 changed files with 35 additions and 10 deletions

View File

@@ -482,6 +482,7 @@ Sequence<Time>::Sequence(const TypeMap& type_map)
, _end_iter(*this, std::numeric_limits<Time>::max(), false, std::set<Evoral::Parameter> ())
, _lowest_note(127)
, _highest_note(0)
, _channels_present (0)
, _explicit_duration (false)
{
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Sequence constructed: %1\n", this));
@@ -504,6 +505,7 @@ Sequence<Time>::Sequence(const Sequence<Time>& other)
, _end_iter(*this, std::numeric_limits<Time>::max(), false, std::set<Evoral::Parameter> ())
, _lowest_note(other._lowest_note)
, _highest_note(other._highest_note)
, _channels_present (0)
, _duration (other._duration)
, _explicit_duration (other._explicit_duration)
{
@@ -728,6 +730,8 @@ Sequence<Time>::add_note_unlocked(const NotePtr note, void* arg)
_highest_note = note->note();
}
_channels_present = _channels_present | (1 << note->channel());
_notes.insert (note);
_pitches[note->channel()].insert (note);
@@ -767,12 +771,21 @@ Sequence<Time>::remove_note_unlocked(const constNotePtr note)
_lowest_note = 127;
_highest_note = 0;
_channels_present = 0;
for (typename Sequence<Time>::Notes::iterator ii = _notes.begin(); ii != _notes.end(); ++ii) {
if ((*ii)->note() < _lowest_note)
_lowest_note = (*ii)->note();
if ((*ii)->note() > _highest_note)
_highest_note = (*ii)->note();
for (auto const & nt : _notes) {
if (nt->note() < _lowest_note) {
_lowest_note = nt->note();
}
if (nt->note() > _highest_note) {
_highest_note = nt->note();
}
_channels_present = _channels_present | (1 << nt->channel());
}
} else {
_channels_present = 0;
for (auto const & nt : _notes) {
_channels_present = _channels_present | (1 << nt->channel());
}
}
@@ -807,12 +820,21 @@ Sequence<Time>::remove_note_unlocked(const constNotePtr note)
_lowest_note = 127;
_highest_note = 0;
_channels_present = 0;
for (typename Sequence<Time>::Notes::iterator ii = _notes.begin(); ii != _notes.end(); ++ii) {
if ((*ii)->note() < _lowest_note)
_lowest_note = (*ii)->note();
if ((*ii)->note() > _highest_note)
_highest_note = (*ii)->note();
for (auto const & nt : _notes) {
if (nt->note() < _lowest_note) {
_lowest_note = nt->note();
}
if (nt->note() > _highest_note) {
_highest_note = nt->note();
}
_channels_present = _channels_present | (1 << nt->channel());
}
} else {
_channels_present = 0;
for (auto const & nt : _notes) {
_channels_present = _channels_present | (1 << nt->channel());
}
}

View File

@@ -314,6 +314,8 @@ public:
uint8_t lowest_note() const { return _lowest_note; }
uint8_t highest_note() const { return _highest_note; }
uint16_t channels_present () const { return _channels_present; }
Time duration() const { return _duration; }
void set_duration (Time const &);
@@ -369,6 +371,7 @@ private:
uint8_t _lowest_note;
uint8_t _highest_note;
uint16_t _channels_present;
Time _duration;
bool _explicit_duration;