2019-08-02 23:10:55 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008-2012 Hans Baier <hansfbaier@googlemail.com>
|
|
|
|
* Copyright (C) 2008-2016 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2019-08-02 23:10:55 -04:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2019-08-02 23:10:55 -04:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2008-09-18 20:47:49 -04:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2019-08-02 23:10:55 -04:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-18 20:47:49 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <algorithm>
|
2009-02-14 15:52:15 -05:00
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
2009-02-15 19:16:28 -05:00
|
|
|
#include <limits>
|
2008-09-18 20:47:49 -04:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <stdint.h>
|
2009-05-17 20:21:17 -04:00
|
|
|
#include <cstdio>
|
2010-05-31 15:47:15 -04:00
|
|
|
|
2013-07-15 17:45:34 -04:00
|
|
|
#if __clang__
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/Note.h"
|
2013-07-15 17:45:34 -04:00
|
|
|
#endif
|
|
|
|
|
2010-05-31 15:47:15 -04:00
|
|
|
#include "pbd/compose.h"
|
2011-08-11 11:58:28 -04:00
|
|
|
#include "pbd/error.h"
|
2010-05-31 15:47:15 -04:00
|
|
|
|
2017-09-24 12:03:54 -04:00
|
|
|
#include "temporal/beats.h"
|
|
|
|
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/Control.h"
|
|
|
|
#include "evoral/ControlList.h"
|
|
|
|
#include "evoral/ControlSet.h"
|
|
|
|
#include "evoral/EventSink.h"
|
|
|
|
#include "evoral/ParameterDescriptor.h"
|
|
|
|
#include "evoral/Sequence.h"
|
|
|
|
#include "evoral/TypeMap.h"
|
2009-02-15 19:16:28 -05:00
|
|
|
#include "evoral/midi_util.h"
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2011-08-11 11:58:28 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
using namespace std;
|
2010-05-31 15:47:15 -04:00
|
|
|
using namespace PBD;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2010-09-28 14:47:24 -04:00
|
|
|
/** Minimum time between MIDI outputs from a single interpolated controller,
|
2010-09-24 10:05:20 -04:00
|
|
|
expressed in beats. This is to limit the rate at which MIDI messages
|
2010-09-28 14:47:24 -04:00
|
|
|
are generated. It is only applied to interpolated controllers.
|
2010-09-24 10:05:20 -04:00
|
|
|
|
|
|
|
XXX: This is a hack. The time should probably be expressed in
|
|
|
|
seconds rather than beats, and should be configurable etc. etc.
|
|
|
|
*/
|
2020-08-24 16:40:03 -04:00
|
|
|
static Temporal::Beats const time_between_interpolated_controller_outputs = Temporal::Beats::ticks (256);
|
2010-09-24 10:05:20 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
namespace Evoral {
|
|
|
|
|
|
|
|
// Read iterator (const_iterator)
|
|
|
|
|
2009-02-14 20:24:26 -05:00
|
|
|
template<typename Time>
|
|
|
|
Sequence<Time>::const_iterator::const_iterator()
|
|
|
|
: _seq(NULL)
|
2014-11-20 15:36:11 -05:00
|
|
|
, _event(boost::shared_ptr< Event<Time> >(new Event<Time>()))
|
2016-11-07 05:14:55 -05:00
|
|
|
, _active_patch_change_message (NO_EVENT)
|
2014-11-20 15:36:11 -05:00
|
|
|
, _type(NIL)
|
2009-02-14 20:24:26 -05:00
|
|
|
, _is_end(true)
|
2009-02-16 02:02:28 -05:00
|
|
|
, _control_iter(_control_iters.end())
|
2014-11-20 15:36:11 -05:00
|
|
|
, _force_discrete(false)
|
2009-02-14 20:24:26 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-13 20:58:15 -04:00
|
|
|
/** @param force_discrete true to force ControlLists to use discrete evaluation, otherwise false to get them to use their configured mode */
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
2020-08-24 16:40:03 -04:00
|
|
|
Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq,
|
|
|
|
Time t,
|
|
|
|
bool force_discrete,
|
|
|
|
const std::set<Evoral::Parameter>& filtered,
|
|
|
|
std::set<WeakNotePtr> const * active_notes)
|
2008-09-18 20:47:49 -04:00
|
|
|
: _seq(&seq)
|
2010-12-28 13:19:40 -05:00
|
|
|
, _active_patch_change_message (0)
|
2009-02-15 19:16:28 -05:00
|
|
|
, _type(NIL)
|
2021-01-13 11:02:47 -05:00
|
|
|
, _is_end((t == std::numeric_limits<Time>::max()) || seq.empty())
|
2009-02-16 02:02:28 -05:00
|
|
|
, _note_iter(seq.notes().end())
|
|
|
|
, _sysex_iter(seq.sysexes().end())
|
2010-12-28 13:19:40 -05:00
|
|
|
, _patch_change_iter(seq.patch_changes().end())
|
2009-02-16 02:02:28 -05:00
|
|
|
, _control_iter(_control_iters.end())
|
2010-07-13 20:58:15 -04:00
|
|
|
, _force_discrete (force_discrete)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2010-05-31 15:47:15 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Created Iterator @ %1 (is end: %2)\n)", t, _is_end));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-05-17 08:00:10 -04:00
|
|
|
if (_is_end) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-17 08:00:10 -04:00
|
|
|
_lock = seq.read_lock();
|
|
|
|
|
2015-03-01 13:33:25 -05:00
|
|
|
// Add currently active notes, if given
|
|
|
|
if (active_notes) {
|
2020-08-24 16:40:03 -04:00
|
|
|
for (typename std::set<WeakNotePtr>::const_iterator i = active_notes->begin(); i != active_notes->end(); ++i) {
|
2015-03-01 13:33:25 -05:00
|
|
|
NotePtr note = i->lock();
|
|
|
|
if (note && note->time() <= t && note->end_time() > t) {
|
|
|
|
_active_notes.push(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 12:39:39 -04:00
|
|
|
// Find first note which begins at or after t
|
|
|
|
_note_iter = seq.note_lower_bound(t);
|
|
|
|
// Find first sysex event at or after t
|
2009-02-10 17:06:56 -05:00
|
|
|
for (typename Sequence<Time>::SysExes::const_iterator i = seq.sysexes().begin();
|
2011-11-22 19:17:31 -05:00
|
|
|
i != seq.sysexes().end(); ++i) {
|
2009-02-06 15:31:00 -05:00
|
|
|
if ((*i)->time() >= t) {
|
|
|
|
_sysex_iter = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(_sysex_iter == seq.sysexes().end() || (*_sysex_iter)->time() >= t);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2010-12-28 13:19:40 -05:00
|
|
|
// Find first patch event at or after t
|
|
|
|
for (typename Sequence<Time>::PatchChanges::const_iterator i = seq.patch_changes().begin(); i != seq.patch_changes().end(); ++i) {
|
|
|
|
if ((*i)->time() >= t) {
|
|
|
|
_patch_change_iter = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert (_patch_change_iter == seq.patch_changes().end() || (*_patch_change_iter)->time() >= t);
|
|
|
|
|
2009-02-15 19:16:28 -05:00
|
|
|
// Find first control event after t
|
2008-09-21 12:17:02 -04:00
|
|
|
_control_iters.reserve(seq._controls.size());
|
2009-02-16 02:02:28 -05:00
|
|
|
bool found = false;
|
|
|
|
size_t earliest_control_index = 0;
|
2021-02-18 19:02:42 -05:00
|
|
|
Temporal::timepos_t earliest_control_x = Temporal::timepos_t::max (typeid(Time) == typeid (Temporal::Beats) ? Temporal::BeatTime : Temporal::AudioTime);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2008-09-21 12:17:02 -04:00
|
|
|
for (Controls::const_iterator i = seq._controls.begin(); i != seq._controls.end(); ++i) {
|
2010-06-25 16:47:09 -04:00
|
|
|
|
|
|
|
if (filtered.find (i->first) != filtered.end()) {
|
|
|
|
/* this parameter is filtered, so don't bother setting up an iterator for it */
|
|
|
|
continue;
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2010-05-31 15:47:15 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Iterator: control: %1\n", seq._type_map.to_symbol(i->first)));
|
2021-02-18 19:02:42 -05:00
|
|
|
Temporal::timepos_t xtime (Temporal::BeatTime); /* domain may change */
|
2020-08-24 16:40:03 -04:00
|
|
|
double y;
|
2010-07-13 20:58:15 -04:00
|
|
|
bool ret;
|
2014-11-20 15:36:11 -05:00
|
|
|
if (_force_discrete || i->second->list()->interpolation() == ControlList::Discrete) {
|
2020-08-24 16:40:03 -04:00
|
|
|
ret = i->second->list()->rt_safe_earliest_event_discrete_unlocked (Temporal::timepos_t (t), xtime, y, true);
|
2010-07-13 20:58:15 -04:00
|
|
|
} else {
|
2020-08-24 16:40:03 -04:00
|
|
|
ret = i->second->list()->rt_safe_earliest_event_linear_unlocked(Temporal::timepos_t (t), xtime, y, true);
|
2010-07-13 20:58:15 -04:00
|
|
|
}
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (!ret) {
|
2010-05-31 15:47:15 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Iterator: CC %1 (size %2) has no events past %3\n",
|
2011-11-22 19:17:31 -05:00
|
|
|
i->first.id(), i->second->list()->size(), t));
|
2008-09-18 20:47:49 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-01 14:28:03 -05:00
|
|
|
const ParameterDescriptor& desc = seq.type_map().descriptor(i->first);
|
|
|
|
if (y < desc.lower || y > desc.upper) {
|
2009-02-15 17:10:32 -05:00
|
|
|
cerr << "ERROR: Controller value " << y
|
2014-12-01 14:28:03 -05:00
|
|
|
<< " out of range [" << desc.lower << "," << desc.upper
|
2011-11-22 19:17:31 -05:00
|
|
|
<< "], event ignored" << endl;
|
2008-09-18 20:47:49 -04:00
|
|
|
continue;
|
2009-02-10 18:57:52 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Iterator: CC %1 added (%2, %3)\n", i->first.id(), xtime, y));
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
const ControlIterator new_iter(i->second->list(), xtime, y);
|
2008-09-18 20:47:49 -04:00
|
|
|
_control_iters.push_back(new_iter);
|
|
|
|
|
2009-02-15 19:16:28 -05:00
|
|
|
// Found a new earliest_control
|
2020-08-24 16:40:03 -04:00
|
|
|
if (xtime < earliest_control_x) {
|
|
|
|
earliest_control_x = xtime;
|
2009-02-16 02:02:28 -05:00
|
|
|
earliest_control_index = _control_iters.size() - 1;
|
2014-12-30 14:45:11 -05:00
|
|
|
found = true;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
}
|
2009-02-16 02:02:28 -05:00
|
|
|
|
|
|
|
if (found) {
|
|
|
|
_control_iter = _control_iters.begin() + earliest_control_index;
|
2009-10-23 00:24:20 -04:00
|
|
|
assert(_control_iter != _control_iters.end());
|
2014-12-30 14:45:11 -05:00
|
|
|
assert(_control_iter->list);
|
2009-02-16 02:02:28 -05:00
|
|
|
} else {
|
|
|
|
_control_iter = _control_iters.end();
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2014-12-30 14:45:11 -05:00
|
|
|
// Choose the earliest event overall to point to
|
|
|
|
choose_next(t);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2014-12-30 14:45:11 -05:00
|
|
|
// Allocate a new event for storing the current event in MIDI format
|
|
|
|
_event = boost::shared_ptr< Event<Time> >(
|
2016-11-07 05:14:55 -05:00
|
|
|
new Event<Time>(NO_EVENT, Time(), 4, NULL, true));
|
2014-12-30 14:45:11 -05:00
|
|
|
|
|
|
|
// Set event from chosen sub-iterator
|
|
|
|
set_event();
|
|
|
|
|
|
|
|
if (_is_end) {
|
|
|
|
DEBUG_TRACE(DEBUG::Sequence,
|
|
|
|
string_compose("Starting at end @ %1\n", t));
|
|
|
|
} else {
|
|
|
|
DEBUG_TRACE(DEBUG::Sequence,
|
|
|
|
string_compose("Starting at type 0x%1 : 0x%2 @ %3\n",
|
|
|
|
(int)_event->event_type(),
|
2016-11-06 18:12:49 -05:00
|
|
|
(int)_event->buffer()[0],
|
2014-12-30 14:45:11 -05:00
|
|
|
_event->time()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
void
|
2020-08-24 16:40:03 -04:00
|
|
|
Sequence<Time>::const_iterator::get_active_notes (std::set<WeakNotePtr>& active_notes) const
|
2014-12-30 14:45:11 -05:00
|
|
|
{
|
2020-08-24 16:40:03 -04:00
|
|
|
/* can't iterate over a std::priority_queue<> such as ActiveNotes */
|
|
|
|
ActiveNotes copy (_active_notes);
|
|
|
|
while (!copy.empty()) {
|
|
|
|
active_notes.insert (copy.top());
|
|
|
|
copy.pop ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::const_iterator::invalidate(bool preserve_active_notes)
|
|
|
|
{
|
|
|
|
if (!preserve_active_notes) {
|
|
|
|
_active_notes = ActiveNotes();
|
2014-12-30 14:45:11 -05:00
|
|
|
}
|
|
|
|
_type = NIL;
|
|
|
|
_is_end = true;
|
|
|
|
if (_seq) {
|
|
|
|
_note_iter = _seq->notes().end();
|
|
|
|
_sysex_iter = _seq->sysexes().end();
|
|
|
|
_patch_change_iter = _seq->patch_changes().end();
|
|
|
|
_active_patch_change_message = 0;
|
|
|
|
}
|
|
|
|
_control_iters.clear();
|
|
|
|
_control_iter = _control_iters.end();
|
|
|
|
_lock.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
Time
|
|
|
|
Sequence<Time>::const_iterator::choose_next(Time earliest_t)
|
|
|
|
{
|
|
|
|
_type = NIL;
|
|
|
|
|
2019-07-30 15:17:15 -04:00
|
|
|
// Next earliest note on, if any
|
2014-12-30 14:45:11 -05:00
|
|
|
if (_note_iter != _seq->notes().end()) {
|
|
|
|
_type = NOTE_ON;
|
2009-02-15 19:16:28 -05:00
|
|
|
earliest_t = (*_note_iter)->time();
|
2009-02-06 15:31:00 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-07-30 15:17:15 -04:00
|
|
|
/* Use the next earliest patch change iff it is earlier or coincident with the note-on.
|
|
|
|
* A patch-change with the same time-stamp applies to the concurrent note-on */
|
|
|
|
if (_patch_change_iter != _seq->patch_changes().end()) {
|
|
|
|
if (_type == NIL || (*_patch_change_iter)->time() <= earliest_t) {
|
|
|
|
_type = PATCH_CHANGE;
|
|
|
|
earliest_t = (*_patch_change_iter)->time();
|
2014-12-30 14:45:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 15:17:15 -04:00
|
|
|
/* Use the next earliest controller iff it's earlier or coincident with the note-on
|
|
|
|
* or patch-change. Bank-select (CC0, CC32) needs to be sent before the PGM. */
|
2014-12-30 14:45:11 -05:00
|
|
|
if (_control_iter != _control_iters.end() &&
|
2021-02-18 19:02:42 -05:00
|
|
|
_control_iter->list && _control_iter->x != Temporal::timepos_t::max (typeid(Time) == typeid (Temporal::Beats) ? Temporal::BeatTime : Temporal::AudioTime)) {
|
2020-08-24 16:40:03 -04:00
|
|
|
if (_type == NIL || _control_iter->x <= earliest_t) {
|
2014-12-30 14:45:11 -05:00
|
|
|
_type = CONTROL;
|
2020-08-24 16:40:03 -04:00
|
|
|
earliest_t = _control_iter->x.beats();
|
2014-12-30 14:45:11 -05:00
|
|
|
}
|
2009-02-06 15:31:00 -05:00
|
|
|
}
|
2009-02-15 19:16:28 -05:00
|
|
|
|
2019-07-30 15:17:15 -04:00
|
|
|
/* .. but prefer to send any Note-off first */
|
|
|
|
if ((!_active_notes.empty())) {
|
2020-08-24 16:40:03 -04:00
|
|
|
if (_type == NIL || _active_notes.top()->end_time() <= earliest_t) {
|
2019-07-30 15:17:15 -04:00
|
|
|
_type = NOTE_OFF;
|
|
|
|
earliest_t = _active_notes.top()->end_time();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SysEx is last, always sent after any other concurrent 3 byte event */
|
2014-12-30 14:45:11 -05:00
|
|
|
if (_sysex_iter != _seq->sysexes().end()) {
|
|
|
|
if (_type == NIL || (*_sysex_iter)->time() < earliest_t) {
|
|
|
|
_type = SYSEX;
|
|
|
|
earliest_t = (*_sysex_iter)->time();
|
|
|
|
}
|
2010-12-28 13:19:40 -05:00
|
|
|
}
|
|
|
|
|
2014-12-30 14:45:11 -05:00
|
|
|
return earliest_t;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2014-12-30 14:45:11 -05:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::const_iterator::set_event()
|
|
|
|
{
|
2009-02-15 19:16:28 -05:00
|
|
|
switch (_type) {
|
|
|
|
case NOTE_ON:
|
2014-12-30 14:45:11 -05:00
|
|
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = note on\n");
|
2015-09-18 11:34:12 -04:00
|
|
|
_event->assign ((*_note_iter)->on_event());
|
2008-09-22 12:28:02 -04:00
|
|
|
_active_notes.push(*_note_iter);
|
2009-02-15 19:16:28 -05:00
|
|
|
break;
|
2014-12-30 14:45:11 -05:00
|
|
|
case NOTE_OFF:
|
|
|
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = note off\n");
|
|
|
|
assert(!_active_notes.empty());
|
2015-09-18 11:34:12 -04:00
|
|
|
_event->assign (_active_notes.top()->off_event());
|
2015-03-01 13:33:25 -05:00
|
|
|
// We don't pop the active note until we increment past it
|
2014-12-30 14:45:11 -05:00
|
|
|
break;
|
2009-02-15 19:16:28 -05:00
|
|
|
case SYSEX:
|
2014-12-30 14:45:11 -05:00
|
|
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = sysex\n");
|
2015-09-18 11:34:12 -04:00
|
|
|
_event->assign (*(*_sysex_iter));
|
2009-02-15 19:16:28 -05:00
|
|
|
break;
|
|
|
|
case CONTROL:
|
2014-12-30 14:45:11 -05:00
|
|
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = control\n");
|
|
|
|
_seq->control_to_midi_event(_event, *_control_iter);
|
2009-02-15 19:16:28 -05:00
|
|
|
break;
|
2010-12-28 13:19:40 -05:00
|
|
|
case PATCH_CHANGE:
|
2014-12-30 14:45:11 -05:00
|
|
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = program change\n");
|
2015-09-18 11:34:12 -04:00
|
|
|
_event->assign ((*_patch_change_iter)->message (_active_patch_change_message));
|
2010-12-28 13:19:40 -05:00
|
|
|
break;
|
2009-02-15 19:16:28 -05:00
|
|
|
default:
|
2014-12-30 14:45:11 -05:00
|
|
|
_is_end = true;
|
2009-02-15 23:46:06 -05:00
|
|
|
break;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2009-02-15 23:46:06 -05:00
|
|
|
if (_type == NIL || !_event || _event->size() == 0) {
|
2014-12-30 14:45:11 -05:00
|
|
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = end\n");
|
2009-02-15 19:16:28 -05:00
|
|
|
_type = NIL;
|
2009-02-15 23:39:34 -05:00
|
|
|
_is_end = true;
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
2009-02-15 23:46:06 -05:00
|
|
|
assert(midi_event_is_valid(_event->buffer(), _event->size()));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-02-17 01:09:37 -05:00
|
|
|
}
|
|
|
|
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
|
|
|
const typename Sequence<Time>::const_iterator&
|
|
|
|
Sequence<Time>::const_iterator::operator++()
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
if (_is_end) {
|
|
|
|
throw std::logic_error("Attempt to iterate past end of Sequence");
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-02-09 03:49:57 -05:00
|
|
|
assert(_event && _event->buffer() && _event->size() > 0);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-11-06 22:04:35 -05:00
|
|
|
const Event<Time>& ev = *_event.get();
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2009-02-15 19:16:28 -05:00
|
|
|
if (!( ev.is_note()
|
2011-11-22 19:17:31 -05:00
|
|
|
|| ev.is_cc()
|
|
|
|
|| ev.is_pgm_change()
|
|
|
|
|| ev.is_pitch_bender()
|
|
|
|
|| ev.is_channel_pressure()
|
2016-11-27 11:25:42 -05:00
|
|
|
|| ev.is_poly_pressure()
|
2011-11-22 19:17:31 -05:00
|
|
|
|| ev.is_sysex()) ) {
|
2009-02-15 19:16:28 -05:00
|
|
|
cerr << "WARNING: Unknown event (type " << _type << "): " << hex
|
2011-11-22 19:17:31 -05:00
|
|
|
<< int(ev.buffer()[0]) << int(ev.buffer()[1]) << int(ev.buffer()[2]) << endl;
|
2009-02-15 19:16:28 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2021-02-18 19:02:42 -05:00
|
|
|
Temporal::timepos_t x (typeid(Time) == typeid (Temporal::Beats) ? Temporal::BeatTime : Temporal::AudioTime);
|
2020-08-24 16:40:03 -04:00
|
|
|
double y = 0.0;
|
|
|
|
bool ret = false;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-02-15 19:16:28 -05:00
|
|
|
// Increment past current event
|
|
|
|
switch (_type) {
|
|
|
|
case NOTE_ON:
|
|
|
|
++_note_iter;
|
|
|
|
break;
|
|
|
|
case NOTE_OFF:
|
2015-03-01 13:33:25 -05:00
|
|
|
_active_notes.pop();
|
2009-02-15 19:16:28 -05:00
|
|
|
break;
|
|
|
|
case CONTROL:
|
|
|
|
// Increment current controller iterator
|
2010-09-28 14:47:24 -04:00
|
|
|
if (_force_discrete || _control_iter->list->interpolation() == ControlList::Discrete) {
|
2021-02-18 17:16:18 -05:00
|
|
|
ret = _control_iter->list->rt_safe_earliest_event_discrete_unlocked (_control_iter->x, x, y, false);
|
2010-07-13 20:58:15 -04:00
|
|
|
} else {
|
2010-09-28 14:47:24 -04:00
|
|
|
ret = _control_iter->list->rt_safe_earliest_event_linear_unlocked (
|
2021-02-18 17:16:18 -05:00
|
|
|
_control_iter->x, x, y, false, Temporal::timecnt_t::from_ticks (time_between_interpolated_controller_outputs.to_ticks()));
|
2010-07-13 20:58:15 -04:00
|
|
|
}
|
2008-12-12 00:21:06 -05:00
|
|
|
assert(!ret || x > _control_iter->x);
|
2008-09-18 20:47:49 -04:00
|
|
|
if (ret) {
|
2021-02-18 17:16:18 -05:00
|
|
|
_control_iter->x = x;
|
2008-09-18 20:47:49 -04:00
|
|
|
_control_iter->y = y;
|
|
|
|
} else {
|
2021-02-18 19:02:42 -05:00
|
|
|
_control_iter->x = Temporal::timepos_t::max (typeid(Time) == typeid (Temporal::Beats) ? Temporal::BeatTime : Temporal::AudioTime);
|
2008-09-18 20:47:49 -04:00
|
|
|
_control_iter->list.reset();
|
2008-09-22 12:28:02 -04:00
|
|
|
_control_iter->y = DBL_MAX;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-02-15 19:16:28 -05:00
|
|
|
// Find the controller with the next earliest event time
|
|
|
|
_control_iter = _control_iters.begin();
|
|
|
|
for (ControlIterators::iterator i = _control_iters.begin();
|
2011-11-22 19:17:31 -05:00
|
|
|
i != _control_iters.end(); ++i) {
|
2009-02-15 19:16:28 -05:00
|
|
|
if (i->x < _control_iter->x) {
|
|
|
|
_control_iter = i;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-02-15 19:16:28 -05:00
|
|
|
break;
|
|
|
|
case SYSEX:
|
|
|
|
++_sysex_iter;
|
|
|
|
break;
|
2010-12-28 13:19:40 -05:00
|
|
|
case PATCH_CHANGE:
|
|
|
|
++_active_patch_change_message;
|
|
|
|
if (_active_patch_change_message == (*_patch_change_iter)->messages()) {
|
|
|
|
++_patch_change_iter;
|
|
|
|
_active_patch_change_message = 0;
|
|
|
|
}
|
|
|
|
break;
|
2009-02-15 19:16:28 -05:00
|
|
|
default:
|
|
|
|
assert(false);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2014-12-30 14:45:11 -05:00
|
|
|
// Choose the earliest event overall to point to
|
2021-02-18 19:02:42 -05:00
|
|
|
choose_next (std::numeric_limits<Time>::max());
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2014-12-30 14:45:11 -05:00
|
|
|
// Set event from chosen sub-iterator
|
|
|
|
set_event();
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2008-09-22 12:28:02 -04:00
|
|
|
assert(_is_end || (_event->size() > 0 && _event->buffer() && _event->buffer()[0] != '\0'));
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
2008-09-21 12:17:02 -04:00
|
|
|
bool
|
2009-02-10 17:06:56 -05:00
|
|
|
Sequence<Time>::const_iterator::operator==(const const_iterator& other) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2009-02-15 19:16:28 -05:00
|
|
|
if (_seq != other._seq) {
|
|
|
|
return false;
|
|
|
|
} else if (_is_end || other._is_end) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return (_is_end == other._is_end);
|
2009-02-15 19:16:28 -05:00
|
|
|
} else if (_type != other._type) {
|
|
|
|
return false;
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
|
|
|
return (_event == other._event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
|
|
|
typename Sequence<Time>::const_iterator&
|
|
|
|
Sequence<Time>::const_iterator::operator=(const const_iterator& other)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
_seq = other._seq;
|
2009-02-15 19:16:28 -05:00
|
|
|
_event = other._event;
|
2008-09-18 20:47:49 -04:00
|
|
|
_active_notes = other._active_notes;
|
2009-02-15 19:16:28 -05:00
|
|
|
_type = other._type;
|
2008-09-18 20:47:49 -04:00
|
|
|
_is_end = other._is_end;
|
|
|
|
_note_iter = other._note_iter;
|
2009-02-06 15:31:00 -05:00
|
|
|
_sysex_iter = other._sysex_iter;
|
2010-12-28 13:19:40 -05:00
|
|
|
_patch_change_iter = other._patch_change_iter;
|
2008-09-18 20:47:49 -04:00
|
|
|
_control_iters = other._control_iters;
|
2010-07-13 20:58:15 -04:00
|
|
|
_force_discrete = other._force_discrete;
|
2010-12-28 13:19:40 -05:00
|
|
|
_active_patch_change_message = other._active_patch_change_message;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-05-17 08:00:10 -04:00
|
|
|
if (other._lock) {
|
2009-10-22 12:15:36 -04:00
|
|
|
_lock = _seq->read_lock();
|
2011-05-17 08:00:10 -04:00
|
|
|
} else {
|
2009-10-22 12:15:36 -04:00
|
|
|
_lock.reset();
|
2011-05-17 08:00:10 -04:00
|
|
|
}
|
2009-10-22 12:15:36 -04:00
|
|
|
|
2009-02-16 02:02:28 -05:00
|
|
|
if (other._control_iter == other._control_iters.end()) {
|
|
|
|
_control_iter = _control_iters.end();
|
|
|
|
} else {
|
|
|
|
const size_t index = other._control_iter - other._control_iters.begin();
|
|
|
|
_control_iter = _control_iters.begin() + index;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sequence
|
|
|
|
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
2009-10-19 11:23:42 -04:00
|
|
|
Sequence<Time>::Sequence(const TypeMap& type_map)
|
2009-02-17 01:09:37 -05:00
|
|
|
: _edited(false)
|
2011-11-22 19:17:31 -05:00
|
|
|
, _overlapping_pitches_accepted (true)
|
|
|
|
, _overlap_pitch_resolution (FirstOnFirstOff)
|
2008-09-18 20:47:49 -04:00
|
|
|
, _writing(false)
|
2010-06-12 09:55:22 -04:00
|
|
|
, _type_map(type_map)
|
2014-11-22 04:05:42 -05:00
|
|
|
, _end_iter(*this, std::numeric_limits<Time>::max(), false, std::set<Evoral::Parameter> ())
|
2008-09-18 20:47:49 -04:00
|
|
|
, _percussive(false)
|
2008-09-22 22:40:29 -04:00
|
|
|
, _lowest_note(127)
|
|
|
|
, _highest_note(0)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2010-05-31 15:47:15 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Sequence constructed: %1\n", this));
|
2008-09-18 20:47:49 -04:00
|
|
|
assert(_end_iter._is_end);
|
2009-10-22 12:15:36 -04:00
|
|
|
assert( ! _end_iter._lock);
|
2010-12-28 13:19:40 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
_bank[i] = 0;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2010-05-18 23:03:28 -04:00
|
|
|
template<typename Time>
|
|
|
|
Sequence<Time>::Sequence(const Sequence<Time>& other)
|
|
|
|
: ControlSet (other)
|
2011-11-22 19:17:31 -05:00
|
|
|
, _edited(false)
|
|
|
|
, _overlapping_pitches_accepted (other._overlapping_pitches_accepted)
|
|
|
|
, _overlap_pitch_resolution (other._overlap_pitch_resolution)
|
2010-05-18 23:03:28 -04:00
|
|
|
, _writing(false)
|
2010-06-12 09:55:22 -04:00
|
|
|
, _type_map(other._type_map)
|
2014-11-22 04:05:42 -05:00
|
|
|
, _end_iter(*this, std::numeric_limits<Time>::max(), false, std::set<Evoral::Parameter> ())
|
2010-05-18 23:03:28 -04:00
|
|
|
, _percussive(other._percussive)
|
|
|
|
, _lowest_note(other._lowest_note)
|
|
|
|
, _highest_note(other._highest_note)
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
for (typename Notes::const_iterator i = other._notes.begin(); i != other._notes.end(); ++i) {
|
|
|
|
NotePtr n (new Note<Time> (**i));
|
|
|
|
_notes.insert (n);
|
|
|
|
}
|
2010-05-18 23:03:28 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
for (typename SysExes::const_iterator i = other._sysexes.begin(); i != other._sysexes.end(); ++i) {
|
|
|
|
boost::shared_ptr<Event<Time> > n (new Event<Time> (**i, true));
|
2012-10-10 23:22:17 -04:00
|
|
|
_sysexes.insert (n);
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2010-05-18 23:03:28 -04:00
|
|
|
|
2010-12-28 13:19:40 -05:00
|
|
|
for (typename PatchChanges::const_iterator i = other._patch_changes.begin(); i != other._patch_changes.end(); ++i) {
|
|
|
|
PatchChangePtr n (new PatchChange<Time> (**i));
|
|
|
|
_patch_changes.insert (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
_bank[i] = other._bank[i];
|
|
|
|
}
|
|
|
|
|
2010-05-31 15:47:15 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Sequence copied: %1\n", this));
|
2010-05-18 23:03:28 -04:00
|
|
|
assert(_end_iter._is_end);
|
|
|
|
assert(! _end_iter._lock);
|
|
|
|
}
|
|
|
|
|
2016-11-07 05:14:55 -05:00
|
|
|
/** Write the controller event pointed to by `iter` to `ev`.
|
|
|
|
* The buffer of `ev` will be allocated or resized as necessary.
|
2008-09-18 20:47:49 -04:00
|
|
|
* \return true on success
|
|
|
|
*/
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
2008-09-18 20:47:49 -04:00
|
|
|
bool
|
2009-02-15 19:16:28 -05:00
|
|
|
Sequence<Time>::control_to_midi_event(
|
2011-11-22 19:17:31 -05:00
|
|
|
boost::shared_ptr< Event<Time> >& ev,
|
|
|
|
const ControlIterator& iter) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
assert(iter.list.get());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-02-06 15:31:00 -05:00
|
|
|
// initialize the event pointer with a new event, if necessary
|
2008-09-18 20:47:49 -04:00
|
|
|
if (!ev) {
|
2016-11-07 05:14:55 -05:00
|
|
|
ev = boost::shared_ptr< Event<Time> >(new Event<Time>(NO_EVENT, Time(), 3, NULL, true));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-11-07 05:14:55 -05:00
|
|
|
const uint8_t midi_type = _type_map.parameter_midi_type(iter.list->parameter());
|
|
|
|
ev->set_event_type(MIDI_EVENT);
|
2015-09-18 11:37:03 -04:00
|
|
|
ev->set_id(-1);
|
2008-09-22 12:28:02 -04:00
|
|
|
switch (midi_type) {
|
|
|
|
case MIDI_CMD_CONTROL:
|
2008-09-18 20:47:49 -04:00
|
|
|
assert(iter.list.get());
|
|
|
|
assert(iter.list->parameter().channel() < 16);
|
|
|
|
assert(iter.list->parameter().id() <= INT8_MAX);
|
2009-01-29 19:27:02 -05:00
|
|
|
assert(iter.y <= INT8_MAX);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
ev->set_time(iter.x.beats());
|
2008-09-18 20:47:49 -04:00
|
|
|
ev->realloc(3);
|
|
|
|
ev->buffer()[0] = MIDI_CMD_CONTROL + iter.list->parameter().channel();
|
|
|
|
ev->buffer()[1] = (uint8_t)iter.list->parameter().id();
|
|
|
|
ev->buffer()[2] = (uint8_t)iter.y;
|
|
|
|
break;
|
|
|
|
|
2008-09-22 12:28:02 -04:00
|
|
|
case MIDI_CMD_PGM_CHANGE:
|
2008-09-18 20:47:49 -04:00
|
|
|
assert(iter.list.get());
|
|
|
|
assert(iter.list->parameter().channel() < 16);
|
|
|
|
assert(iter.y <= INT8_MAX);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
ev->set_time(iter.x.beats());
|
2008-09-18 20:47:49 -04:00
|
|
|
ev->realloc(2);
|
|
|
|
ev->buffer()[0] = MIDI_CMD_PGM_CHANGE + iter.list->parameter().channel();
|
|
|
|
ev->buffer()[1] = (uint8_t)iter.y;
|
|
|
|
break;
|
|
|
|
|
2008-09-22 12:28:02 -04:00
|
|
|
case MIDI_CMD_BENDER:
|
2008-09-18 20:47:49 -04:00
|
|
|
assert(iter.list.get());
|
|
|
|
assert(iter.list->parameter().channel() < 16);
|
|
|
|
assert(iter.y < (1<<14));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
ev->set_time(iter.x.beats());
|
2008-09-18 20:47:49 -04:00
|
|
|
ev->realloc(3);
|
|
|
|
ev->buffer()[0] = MIDI_CMD_BENDER + iter.list->parameter().channel();
|
|
|
|
ev->buffer()[1] = uint16_t(iter.y) & 0x7F; // LSB
|
|
|
|
ev->buffer()[2] = (uint16_t(iter.y) >> 7) & 0x7F; // MSB
|
|
|
|
break;
|
|
|
|
|
2016-11-27 11:25:42 -05:00
|
|
|
case MIDI_CMD_NOTE_PRESSURE:
|
|
|
|
assert(iter.list.get());
|
|
|
|
assert(iter.list->parameter().channel() < 16);
|
|
|
|
assert(iter.list->parameter().id() <= INT8_MAX);
|
|
|
|
assert(iter.y <= INT8_MAX);
|
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
ev->set_time(iter.x.beats());
|
2016-11-27 11:25:42 -05:00
|
|
|
ev->realloc(3);
|
|
|
|
ev->buffer()[0] = MIDI_CMD_NOTE_PRESSURE + iter.list->parameter().channel();
|
|
|
|
ev->buffer()[1] = (uint8_t)iter.list->parameter().id();
|
|
|
|
ev->buffer()[2] = (uint8_t)iter.y;
|
|
|
|
break;
|
|
|
|
|
2008-09-22 12:28:02 -04:00
|
|
|
case MIDI_CMD_CHANNEL_PRESSURE:
|
2008-09-18 20:47:49 -04:00
|
|
|
assert(iter.list.get());
|
|
|
|
assert(iter.list->parameter().channel() < 16);
|
|
|
|
assert(iter.y <= INT8_MAX);
|
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
ev->set_time(iter.x.beats());
|
2008-09-18 20:47:49 -04:00
|
|
|
ev->realloc(2);
|
|
|
|
ev->buffer()[0] = MIDI_CMD_CHANNEL_PRESSURE + iter.list->parameter().channel();
|
|
|
|
ev->buffer()[1] = (uint8_t)iter.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Clear all events from the model.
|
|
|
|
*/
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
2008-09-21 12:17:02 -04:00
|
|
|
void
|
2009-02-10 17:06:56 -05:00
|
|
|
Sequence<Time>::clear()
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2009-10-22 12:15:36 -04:00
|
|
|
WriteLock lock(write_lock());
|
2008-09-18 20:47:49 -04:00
|
|
|
_notes.clear();
|
|
|
|
for (Controls::iterator li = _controls.begin(); li != _controls.end(); ++li)
|
|
|
|
li->second->list()->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Begin a write of events to the model.
|
|
|
|
*
|
2008-09-22 12:28:02 -04:00
|
|
|
* If \a mode is Sustained, complete notes with length are constructed as note
|
2008-09-18 20:47:49 -04:00
|
|
|
* on/off events are received. Otherwise (Percussive), only note on events are
|
|
|
|
* stored; note off events are discarded entirely and all contained notes will
|
2008-09-22 12:28:02 -04:00
|
|
|
* have length 0.
|
2008-09-18 20:47:49 -04:00
|
|
|
*/
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
2008-09-21 12:17:02 -04:00
|
|
|
void
|
2009-02-10 17:06:56 -05:00
|
|
|
Sequence<Time>::start_write()
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2010-05-31 15:47:15 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 : start_write (percussive = %2)\n", this, _percussive));
|
2009-10-22 12:15:36 -04:00
|
|
|
WriteLock lock(write_lock());
|
2008-09-18 20:47:49 -04:00
|
|
|
_writing = true;
|
2009-02-15 19:16:28 -05:00
|
|
|
for (int i = 0; i < 16; ++i) {
|
2008-09-18 20:47:49 -04:00
|
|
|
_write_notes[i].clear();
|
2009-02-15 19:16:28 -05:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Finish a write of events to the model.
|
|
|
|
*
|
|
|
|
* If \a delete_stuck is true and the current mode is Sustained, note on events
|
|
|
|
* that were never resolved with a corresonding note off will be deleted.
|
2008-09-22 12:28:02 -04:00
|
|
|
* Otherwise they will remain as notes with length 0.
|
2008-09-18 20:47:49 -04:00
|
|
|
*/
|
2009-02-10 17:06:56 -05:00
|
|
|
template<typename Time>
|
2008-09-21 12:17:02 -04:00
|
|
|
void
|
2011-07-20 14:13:03 -04:00
|
|
|
Sequence<Time>::end_write (StuckNoteOption option, Time when)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2009-10-22 12:15:36 -04:00
|
|
|
WriteLock lock(write_lock());
|
2009-10-21 18:21:44 -04:00
|
|
|
|
|
|
|
if (!_writing) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2011-07-20 14:13:03 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 : end_write (%2 notes) delete stuck option %3 @ %4\n", this, _notes.size(), option, when));
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2015-02-19 15:20:19 -05:00
|
|
|
for (typename Notes::iterator n = _notes.begin(); n != _notes.end() ;) {
|
|
|
|
typename Notes::iterator next = n;
|
|
|
|
++next;
|
|
|
|
|
2020-01-11 12:56:19 -05:00
|
|
|
if ((*n)->end_time() == std::numeric_limits<Temporal::Beats>::max()) {
|
2015-02-19 15:20:19 -05:00
|
|
|
switch (option) {
|
|
|
|
case Relax:
|
|
|
|
break;
|
|
|
|
case DeleteStuckNotes:
|
2020-05-03 19:23:49 -04:00
|
|
|
cerr << "WARNING: Stuck note lost (end was " << when << "): " << (**n) << endl;
|
2015-02-19 15:20:19 -05:00
|
|
|
_notes.erase(n);
|
|
|
|
break;
|
|
|
|
case ResolveStuckNotes:
|
|
|
|
if (when <= (*n)->time()) {
|
|
|
|
cerr << "WARNING: Stuck note resolution - end time @ "
|
|
|
|
<< when << " is before note on: " << (**n) << endl;
|
2020-01-25 16:15:09 -05:00
|
|
|
_notes.erase (n);
|
2015-02-19 15:20:19 -05:00
|
|
|
} else {
|
|
|
|
(*n)->set_length (when - (*n)->time());
|
|
|
|
cerr << "WARNING: resolved note-on with no note-off to generate " << (**n) << endl;
|
2011-07-14 13:41:06 -04:00
|
|
|
}
|
2015-02-19 15:20:19 -05:00
|
|
|
break;
|
2011-07-14 13:41:06 -04:00
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2015-02-19 15:20:19 -05:00
|
|
|
|
|
|
|
n = next;
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
_write_notes[i].clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
_writing = false;
|
|
|
|
}
|
|
|
|
|
2010-06-01 16:40:45 -04:00
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
bool
|
2010-06-14 19:43:10 -04:00
|
|
|
Sequence<Time>::add_note_unlocked(const NotePtr note, void* arg)
|
2010-06-01 16:40:45 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
/* This is the core method to add notes to a Sequence
|
|
|
|
*/
|
2010-06-01 16:40:45 -04:00
|
|
|
|
2011-11-22 15:29:41 -05:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 add note %2 @ %3 dur %4\n", this, (int)note->note(), note->time(), note->length()));
|
2010-06-01 16:40:45 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (resolve_overlaps_unlocked (note, arg)) {
|
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 DISALLOWED: note %2 @ %3\n", this, (int)note->note(), note->time()));
|
|
|
|
return false;
|
2010-06-01 16:40:45 -04:00
|
|
|
}
|
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (note->id() < 0) {
|
|
|
|
note->set_id (Evoral::next_event_id());
|
|
|
|
}
|
2010-06-01 16:40:45 -04:00
|
|
|
|
|
|
|
if (note->note() < _lowest_note)
|
|
|
|
_lowest_note = note->note();
|
|
|
|
if (note->note() > _highest_note)
|
|
|
|
_highest_note = note->note();
|
|
|
|
|
2010-06-02 15:55:37 -04:00
|
|
|
_notes.insert (note);
|
2011-11-22 19:17:31 -05:00
|
|
|
_pitches[note->channel()].insert (note);
|
|
|
|
|
2010-07-20 12:27:34 -04:00
|
|
|
_edited = true;
|
2010-06-01 16:40:45 -04:00
|
|
|
|
2011-06-21 17:29:22 -04:00
|
|
|
return true;
|
2010-06-01 16:40:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
void
|
2010-06-12 09:55:22 -04:00
|
|
|
Sequence<Time>::remove_note_unlocked(const constNotePtr note)
|
2010-06-01 16:40:45 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
bool erased = false;
|
2013-03-29 11:52:25 -04:00
|
|
|
bool id_matched = false;
|
2010-06-01 16:40:45 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 remove note #%2 %3 @ %4\n", this, note->id(), (int)note->note(), note->time()));
|
2010-06-01 16:40:45 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
/* first try searching for the note using the time index, which is
|
|
|
|
* faster since the container is "indexed" by time. (technically, this
|
|
|
|
* means that lower_bound() can do a binary search rather than linear)
|
|
|
|
*
|
|
|
|
* this may not work, for reasons explained below.
|
|
|
|
*/
|
2010-12-09 16:35:33 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
typename Sequence<Time>::Notes::iterator i;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-11-22 04:05:42 -05:00
|
|
|
for (i = note_lower_bound(note->time()); i != _notes.end() && (*i)->time() == note->time(); ++i) {
|
2010-06-01 16:40:45 -04:00
|
|
|
|
|
|
|
if (*i == note) {
|
2010-12-09 16:35:33 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing note #%2 %3 @ %4\n", this, (*i)->id(), (int)(*i)->note(), (*i)->time()));
|
2010-06-01 16:40:45 -04:00
|
|
|
_notes.erase (i);
|
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
if (note->note() == _lowest_note || note->note() == _highest_note) {
|
2011-11-22 19:17:31 -05:00
|
|
|
|
|
|
|
_lowest_note = 127;
|
|
|
|
_highest_note = 0;
|
2010-06-01 16:40:45 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2010-06-01 16:40:45 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
erased = true;
|
2013-03-29 11:52:25 -04:00
|
|
|
break;
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2013-03-29 11:52:25 -04:00
|
|
|
}
|
2010-12-09 16:35:33 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\ttime-based lookup did not find note #%2 %3 @ %4\n", this, note->id(), (int)note->note(), note->time()));
|
|
|
|
|
|
|
|
if (!erased) {
|
|
|
|
|
|
|
|
/* if the note's time property was changed in tandem with some
|
|
|
|
* other property as the next operation after it was added to
|
|
|
|
* the sequence, then at the point where we call this to undo
|
|
|
|
* the add, the note we are targetting currently has a
|
|
|
|
* different time property than the one we we passed via
|
|
|
|
* the argument.
|
|
|
|
*
|
|
|
|
* in this scenario, we have no choice other than to linear
|
|
|
|
* search the list of notes and find the note by ID.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
for (i = _notes.begin(); i != _notes.end(); ++i) {
|
|
|
|
|
|
|
|
if ((*i)->id() == note->id()) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\tID-based pass, erasing note #%2 %3 @ %4\n", this, (*i)->id(), (int)(*i)->note(), (*i)->time()));
|
|
|
|
_notes.erase (i);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
if (note->note() == _lowest_note || note->note() == _highest_note) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
_lowest_note = 127;
|
|
|
|
_highest_note = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
erased = true;
|
|
|
|
id_matched = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-14 15:52:15 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
if (erased) {
|
2009-02-14 15:52:15 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
Pitches& p (pitches (note->channel()));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
typename Pitches::iterator j;
|
2010-05-20 18:38:12 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
/* if we had to ID-match above, we can't expect to find it in
|
|
|
|
* pitches via note comparison either. so do another linear
|
|
|
|
* search to locate it. otherwise, we can use the note index
|
|
|
|
* to potentially speed things up.
|
|
|
|
*/
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
if (id_matched) {
|
|
|
|
|
|
|
|
for (j = p.begin(); j != p.end(); ++j) {
|
|
|
|
if ((*j)->id() == note->id()) {
|
|
|
|
p.erase (j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
/* Now find the same note in the "pitches" list (which indexes
|
|
|
|
* notes by channel+time. We care only about its note number
|
|
|
|
* so the search_note has all other properties unset.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-11-22 04:05:42 -05:00
|
|
|
NotePtr search_note (new Note<Time>(0, Time(), Time(), note->note(), 0));
|
2013-03-29 11:52:25 -04:00
|
|
|
|
|
|
|
for (j = p.lower_bound (search_note); j != p.end() && (*j)->note() == note->note(); ++j) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
if ((*j) == note) {
|
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing pitch %2 @ %3\n", this, (int)(*j)->note(), (*j)->time()));
|
|
|
|
p.erase (j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2010-12-09 16:35:33 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
if (j == p.end()) {
|
|
|
|
warning << string_compose ("erased note %1 not found in pitches for channel %2", *note, (int) note->channel()) << endmsg;
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
_edited = true;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
} else {
|
|
|
|
cerr << "Unable to find note to erase matching " << *note.get() << endmsg;
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2010-06-12 09:55:22 -04:00
|
|
|
}
|
2010-05-31 15:47:15 -04:00
|
|
|
|
2010-12-28 13:19:40 -05:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::remove_patch_change_unlocked (const constPatchChangePtr p)
|
|
|
|
{
|
|
|
|
typename Sequence<Time>::PatchChanges::iterator i = patch_change_lower_bound (p->time ());
|
2013-03-29 11:52:25 -04:00
|
|
|
|
2014-11-22 04:05:42 -05:00
|
|
|
while (i != _patch_changes.end() && ((*i)->time() == p->time())) {
|
2010-12-28 13:19:40 -05:00
|
|
|
|
|
|
|
typename Sequence<Time>::PatchChanges::iterator tmp = i;
|
|
|
|
++tmp;
|
|
|
|
|
2013-03-29 11:52:25 -04:00
|
|
|
if (**i == *p) {
|
2010-12-28 13:19:40 -05:00
|
|
|
_patch_changes.erase (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-10 23:22:17 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::remove_sysex_unlocked (const SysExPtr sysex)
|
|
|
|
{
|
|
|
|
typename Sequence<Time>::SysExes::iterator i = sysex_lower_bound (sysex->time ());
|
|
|
|
while (i != _sysexes.end() && (*i)->time() == sysex->time()) {
|
|
|
|
|
|
|
|
typename Sequence<Time>::SysExes::iterator tmp = i;
|
|
|
|
++tmp;
|
|
|
|
|
|
|
|
if (*i == sysex) {
|
|
|
|
_sysexes.erase (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-12 09:55:22 -04:00
|
|
|
/** Append \a ev to model. NOT realtime safe.
|
|
|
|
*
|
|
|
|
* The timestamp of event is expected to be relative to
|
|
|
|
* the start of this model (t=0) and MUST be monotonically increasing
|
|
|
|
* and MUST be >= the latest event currently in the model.
|
|
|
|
*/
|
|
|
|
template<typename Time>
|
|
|
|
void
|
2016-11-06 22:04:35 -05:00
|
|
|
Sequence<Time>::append(const Event<Time>& ev, event_id_t evid)
|
2010-06-12 09:55:22 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
WriteLock lock(write_lock());
|
|
|
|
|
2014-11-22 04:05:42 -05:00
|
|
|
assert(_notes.empty() || ev.time() >= (*_notes.rbegin())->time());
|
2011-11-22 19:17:31 -05:00
|
|
|
assert(_writing);
|
|
|
|
|
|
|
|
if (!midi_event_is_valid(ev.buffer(), ev.size())) {
|
|
|
|
cerr << "WARNING: Sequence ignoring illegal MIDI event" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:55:16 -05:00
|
|
|
if (ev.is_note_on() && ev.velocity() > 0) {
|
|
|
|
append_note_on_unlocked (ev, evid);
|
|
|
|
} else if (ev.is_note_off() || (ev.is_note_on() && ev.velocity() == 0)) {
|
2011-11-22 19:17:31 -05:00
|
|
|
/* XXX note: event ID is discarded because we merge the on+off events into
|
|
|
|
a single note object
|
|
|
|
*/
|
2015-02-19 15:55:16 -05:00
|
|
|
append_note_off_unlocked (ev);
|
2011-11-22 19:17:31 -05:00
|
|
|
} else if (ev.is_sysex()) {
|
|
|
|
append_sysex_unlocked(ev, evid);
|
2010-12-28 13:19:40 -05:00
|
|
|
} else if (ev.is_cc() && (ev.cc_number() == MIDI_CTL_MSB_BANK || ev.cc_number() == MIDI_CTL_LSB_BANK)) {
|
|
|
|
/* note bank numbers in our _bank[] array, so that we can write an event when the program change arrives */
|
|
|
|
if (ev.cc_number() == MIDI_CTL_MSB_BANK) {
|
2011-04-16 11:10:25 -04:00
|
|
|
_bank[ev.channel()] &= ~(0x7f << 7);
|
2010-12-28 13:19:40 -05:00
|
|
|
_bank[ev.channel()] |= ev.cc_value() << 7;
|
|
|
|
} else {
|
2011-04-16 11:10:25 -04:00
|
|
|
_bank[ev.channel()] &= ~0x7f;
|
2010-12-28 13:19:40 -05:00
|
|
|
_bank[ev.channel()] |= ev.cc_value();
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
} else if (ev.is_cc()) {
|
2016-11-07 05:14:55 -05:00
|
|
|
const ParameterType ptype = _type_map.midi_parameter_type(ev.buffer(), ev.size());
|
2011-11-22 19:17:31 -05:00
|
|
|
append_control_unlocked(
|
2016-11-07 05:14:55 -05:00
|
|
|
Parameter(ptype, ev.channel(), ev.cc_number()),
|
2011-11-22 19:17:31 -05:00
|
|
|
ev.time(), ev.cc_value(), evid);
|
|
|
|
} else if (ev.is_pgm_change()) {
|
2010-12-28 13:19:40 -05:00
|
|
|
/* write a patch change with this program change and any previously set-up bank number */
|
2016-11-07 05:14:55 -05:00
|
|
|
append_patch_change_unlocked (
|
|
|
|
PatchChange<Time> (ev.time(), ev.channel(),
|
|
|
|
ev.pgm_number(), _bank[ev.channel()]), evid);
|
2011-11-22 19:17:31 -05:00
|
|
|
} else if (ev.is_pitch_bender()) {
|
2016-11-07 05:14:55 -05:00
|
|
|
const ParameterType ptype = _type_map.midi_parameter_type(ev.buffer(), ev.size());
|
2011-11-22 19:17:31 -05:00
|
|
|
append_control_unlocked(
|
2016-11-07 05:14:55 -05:00
|
|
|
Parameter(ptype, ev.channel()),
|
2011-11-22 19:17:31 -05:00
|
|
|
ev.time(), double ((0x7F & ev.pitch_bender_msb()) << 7
|
|
|
|
| (0x7F & ev.pitch_bender_lsb())),
|
|
|
|
evid);
|
2016-08-18 09:44:20 -04:00
|
|
|
} else if (ev.is_poly_pressure()) {
|
2019-04-02 09:35:57 -04:00
|
|
|
const ParameterType ptype = _type_map.midi_parameter_type(ev.buffer(), ev.size());
|
|
|
|
append_control_unlocked (Parameter (ptype, ev.channel(), ev.poly_note()), ev.time(), ev.poly_pressure(), evid);
|
2011-11-22 19:17:31 -05:00
|
|
|
} else if (ev.is_channel_pressure()) {
|
2016-11-07 05:14:55 -05:00
|
|
|
const ParameterType ptype = _type_map.midi_parameter_type(ev.buffer(), ev.size());
|
2011-11-22 19:17:31 -05:00
|
|
|
append_control_unlocked(
|
2016-11-07 05:14:55 -05:00
|
|
|
Parameter(ptype, ev.channel()),
|
2011-11-22 19:17:31 -05:00
|
|
|
ev.time(), ev.channel_pressure(), evid);
|
|
|
|
} else if (!_type_map.type_is_midi(ev.event_type())) {
|
|
|
|
printf("WARNING: Sequence: Unknown event type %X: ", ev.event_type());
|
|
|
|
for (size_t i=0; i < ev.size(); ++i) {
|
|
|
|
printf("%X ", ev.buffer()[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
} else {
|
|
|
|
printf("WARNING: Sequence: Unknown MIDI event type %X\n", ev.type());
|
|
|
|
}
|
|
|
|
|
|
|
|
_edited = true;
|
2010-06-12 09:55:22 -04:00
|
|
|
}
|
2010-06-02 15:55:37 -04:00
|
|
|
|
2010-06-12 09:55:22 -04:00
|
|
|
template<typename Time>
|
2010-07-20 12:27:34 -04:00
|
|
|
void
|
2016-11-06 22:04:35 -05:00
|
|
|
Sequence<Time>::append_note_on_unlocked (const Event<Time>& ev, event_id_t evid)
|
2010-07-20 12:27:34 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 on @ %4 v=%5\n", this,
|
2015-02-19 15:55:16 -05:00
|
|
|
(int)ev.channel(), (int)ev.note(),
|
|
|
|
ev.time(), (int)ev.velocity()));
|
2011-11-22 19:17:31 -05:00
|
|
|
assert(_writing);
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2015-02-19 15:55:16 -05:00
|
|
|
if (ev.note() > 127) {
|
|
|
|
error << string_compose (_("invalid note on number (%1) ignored"), (int) ev.note()) << endmsg;
|
2011-08-11 11:58:28 -04:00
|
|
|
return;
|
2015-02-19 15:55:16 -05:00
|
|
|
} else if (ev.channel() >= 16) {
|
|
|
|
error << string_compose (_("invalid note on channel (%1) ignored"), (int) ev.channel()) << endmsg;
|
2011-08-11 11:58:28 -04:00
|
|
|
return;
|
2015-02-19 15:55:16 -05:00
|
|
|
} else if (ev.velocity() == 0) {
|
|
|
|
// Note on with velocity 0 handled as note off by caller
|
|
|
|
error << string_compose (_("invalid note on velocity (%1) ignored"), (int) ev.velocity()) << endmsg;
|
2011-11-22 19:17:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-11 12:56:19 -05:00
|
|
|
/* nascent (incoming notes without a note-off ...yet) have a duration
|
|
|
|
that extends to Beats::max()
|
|
|
|
*/
|
|
|
|
NotePtr note(new Note<Time>(ev.channel(), ev.time(), std::numeric_limits<Temporal::Beats>::max() - ev.time(), ev.note(), ev.velocity()));
|
|
|
|
assert (note->end_time() == std::numeric_limits<Temporal::Beats>::max());
|
2015-02-19 15:55:16 -05:00
|
|
|
note->set_id (evid);
|
|
|
|
|
2021-06-29 19:29:29 -04:00
|
|
|
add_note_unlocked (note);
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Appending active note on %1 channel %2\n",
|
|
|
|
(unsigned)(uint8_t)note->note(), note->channel()));
|
2015-02-19 15:20:19 -05:00
|
|
|
_write_notes[note->channel()].insert (note);
|
2012-10-12 01:58:47 -04:00
|
|
|
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
void
|
2016-11-06 22:04:35 -05:00
|
|
|
Sequence<Time>::append_note_off_unlocked (const Event<Time>& ev)
|
2010-07-20 12:27:34 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 OFF @ %4 v=%5\n",
|
2015-02-19 15:55:16 -05:00
|
|
|
this, (int)ev.channel(),
|
|
|
|
(int)ev.note(), ev.time(), (int)ev.velocity()));
|
2011-11-22 19:17:31 -05:00
|
|
|
assert(_writing);
|
2011-08-11 12:06:31 -04:00
|
|
|
|
2015-02-19 15:55:16 -05:00
|
|
|
if (ev.note() > 127) {
|
|
|
|
error << string_compose (_("invalid note off number (%1) ignored"), (int) ev.note()) << endmsg;
|
2011-08-11 12:06:31 -04:00
|
|
|
return;
|
2015-02-19 15:55:16 -05:00
|
|
|
} else if (ev.channel() >= 16) {
|
|
|
|
error << string_compose (_("invalid note off channel (%1) ignored"), (int) ev.channel()) << endmsg;
|
2011-08-11 12:06:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
_edited = true;
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
bool resolved = false;
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* _write_notes is sorted earliest-latest, so this will find the first matching note (FIFO) that
|
|
|
|
matches this note (by pitch & channel). the MIDI specification doesn't provide any guidance
|
|
|
|
whether to use FIFO or LIFO for this matching process, so SMF is fundamentally a lossy
|
|
|
|
format.
|
|
|
|
*/
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* XXX use _overlap_pitch_resolution to determine FIFO/LIFO ... */
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2015-02-19 15:55:16 -05:00
|
|
|
for (typename WriteNotes::iterator n = _write_notes[ev.channel()].begin(); n != _write_notes[ev.channel()].end(); ) {
|
2010-12-09 16:35:33 -05:00
|
|
|
|
|
|
|
typename WriteNotes::iterator tmp = n;
|
|
|
|
++tmp;
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
NotePtr nn = *n;
|
2021-06-28 10:30:22 -04:00
|
|
|
if (ev.note() == nn->note() && nn->channel() == ev.channel()) {
|
2021-06-29 19:29:29 -04:00
|
|
|
assert(ev.time() >= nn->time());
|
|
|
|
|
|
|
|
nn->set_length (ev.time() - nn->time());
|
|
|
|
nn->set_off_velocity (ev.velocity());
|
|
|
|
|
|
|
|
_write_notes[ev.channel()].erase(n);
|
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("resolved note @ %2 length: %1\n", nn->length(), nn->time()));
|
|
|
|
resolved = true;
|
|
|
|
break;
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2010-12-09 16:35:33 -05:00
|
|
|
|
|
|
|
n = tmp;
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (!resolved) {
|
2015-02-19 15:55:16 -05:00
|
|
|
cerr << this << " spurious note off chan " << (int)ev.channel()
|
|
|
|
<< ", note " << (int)ev.note() << " @ " << ev.time() << endl;
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
2010-05-31 15:47:15 -04:00
|
|
|
|
2010-07-20 12:27:34 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
2010-09-02 13:01:36 -04:00
|
|
|
Sequence<Time>::append_control_unlocked(const Parameter& param, Time time, double value, event_id_t /* evid */)
|
2010-07-20 12:27:34 -04:00
|
|
|
{
|
2013-05-02 10:11:31 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 %2 @ %3 = %4 # controls: %5\n",
|
2011-11-22 19:17:31 -05:00
|
|
|
this, _type_map.to_symbol(param), time, value, _controls.size()));
|
2014-12-05 00:03:47 -05:00
|
|
|
boost::shared_ptr<Control> c = control(param, true);
|
2020-08-24 16:40:03 -04:00
|
|
|
c->list()->add (Temporal::timepos_t (time), value, true, false);
|
2011-11-22 19:17:31 -05:00
|
|
|
/* XXX control events should use IDs */
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
void
|
2016-11-06 22:04:35 -05:00
|
|
|
Sequence<Time>::append_sysex_unlocked(const Event<Time>& ev, event_id_t /* evid */)
|
2010-07-20 12:27:34 -04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_SEQUENCE
|
2011-11-22 19:17:31 -05:00
|
|
|
cerr << this << " SysEx @ " << ev.time() << " \t= \t [ " << hex;
|
|
|
|
for (size_t i=0; i < ev.size(); ++i) {
|
|
|
|
cerr << int(ev.buffer()[i]) << " ";
|
|
|
|
} cerr << "]" << endl;
|
2010-07-20 12:27:34 -04:00
|
|
|
#endif
|
|
|
|
|
2016-11-06 22:04:35 -05:00
|
|
|
boost::shared_ptr< Event<Time> > event(new Event<Time>(ev, true));
|
2011-11-22 19:17:31 -05:00
|
|
|
/* XXX sysex events should use IDs */
|
2012-10-10 23:22:17 -04:00
|
|
|
_sysexes.insert(event);
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
2010-12-28 13:19:40 -05:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::append_patch_change_unlocked (const PatchChange<Time>& ev, event_id_t id)
|
|
|
|
{
|
|
|
|
PatchChangePtr p (new PatchChange<Time> (ev));
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2010-12-28 13:19:40 -05:00
|
|
|
if (p->id() < 0) {
|
|
|
|
p->set_id (id);
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2010-12-28 13:19:40 -05:00
|
|
|
_patch_changes.insert (p);
|
|
|
|
}
|
|
|
|
|
2012-07-16 10:46:21 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::add_patch_change_unlocked (PatchChangePtr p)
|
|
|
|
{
|
|
|
|
if (p->id () < 0) {
|
|
|
|
p->set_id (Evoral::next_event_id ());
|
|
|
|
}
|
|
|
|
|
|
|
|
_patch_changes.insert (p);
|
|
|
|
}
|
|
|
|
|
2012-10-10 23:22:17 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::add_sysex_unlocked (SysExPtr s)
|
|
|
|
{
|
|
|
|
if (s->id () < 0) {
|
|
|
|
s->set_id (Evoral::next_event_id ());
|
|
|
|
}
|
|
|
|
|
|
|
|
_sysexes.insert (s);
|
|
|
|
}
|
|
|
|
|
2010-07-20 12:27:34 -04:00
|
|
|
template<typename Time>
|
|
|
|
bool
|
|
|
|
Sequence<Time>::contains (const NotePtr& note) const
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
ReadLock lock (read_lock());
|
|
|
|
return contains_unlocked (note);
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
bool
|
|
|
|
Sequence<Time>::contains_unlocked (const NotePtr& note) const
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
const Pitches& p (pitches (note->channel()));
|
2014-11-22 04:05:42 -05:00
|
|
|
NotePtr search_note(new Note<Time>(0, Time(), Time(), note->note()));
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
for (typename Pitches::const_iterator i = p.lower_bound (search_note);
|
|
|
|
i != p.end() && (*i)->note() == note->note(); ++i) {
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (**i == *note) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 12:27:34 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
return false;
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
bool
|
|
|
|
Sequence<Time>::overlaps (const NotePtr& note, const NotePtr& without) const
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
ReadLock lock (read_lock());
|
|
|
|
return overlaps_unlocked (note, without);
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
bool
|
|
|
|
Sequence<Time>::overlaps_unlocked (const NotePtr& note, const NotePtr& without) const
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
Time sa = note->time();
|
|
|
|
Time ea = note->end_time();
|
|
|
|
|
|
|
|
const Pitches& p (pitches (note->channel()));
|
2014-11-22 04:05:42 -05:00
|
|
|
NotePtr search_note(new Note<Time>(0, Time(), Time(), note->note()));
|
2011-11-22 19:17:31 -05:00
|
|
|
|
|
|
|
for (typename Pitches::const_iterator i = p.lower_bound (search_note);
|
|
|
|
i != p.end() && (*i)->note() == note->note(); ++i) {
|
|
|
|
|
|
|
|
if (without && (**i) == *without) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Time sb = (*i)->time();
|
|
|
|
Time eb = (*i)->end_time();
|
|
|
|
|
|
|
|
if (((sb > sa) && (eb <= ea)) ||
|
|
|
|
((eb >= sa) && (eb <= ea)) ||
|
|
|
|
((sb > sa) && (sb <= ea)) ||
|
|
|
|
((sa >= sb) && (sa <= eb) && (ea <= eb))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
void
|
2013-07-23 02:56:30 -04:00
|
|
|
Sequence<Time>::set_notes (const typename Sequence<Time>::Notes& n)
|
2010-07-20 12:27:34 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
_notes = n;
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
|
|
|
|
2013-07-23 02:56:30 -04:00
|
|
|
// CONST iterator implementations (x3)
|
|
|
|
|
2010-07-20 12:27:34 -04:00
|
|
|
/** Return the earliest note with time >= t */
|
|
|
|
template<typename Time>
|
|
|
|
typename Sequence<Time>::Notes::const_iterator
|
|
|
|
Sequence<Time>::note_lower_bound (Time t) const
|
|
|
|
{
|
2014-11-22 04:05:42 -05:00
|
|
|
NotePtr search_note(new Note<Time>(0, t, Time(), 0, 0));
|
2011-11-22 19:17:31 -05:00
|
|
|
typename Sequence<Time>::Notes::const_iterator i = _notes.lower_bound(search_note);
|
2014-11-22 04:05:42 -05:00
|
|
|
assert(i == _notes.end() || (*i)->time() >= t);
|
2011-11-22 19:17:31 -05:00
|
|
|
return i;
|
2010-07-20 12:27:34 -04:00
|
|
|
}
|
2010-05-31 15:47:15 -04:00
|
|
|
|
2010-12-28 13:19:40 -05:00
|
|
|
/** Return the earliest patch change with time >= t */
|
|
|
|
template<typename Time>
|
|
|
|
typename Sequence<Time>::PatchChanges::const_iterator
|
|
|
|
Sequence<Time>::patch_change_lower_bound (Time t) const
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
PatchChangePtr search (new PatchChange<Time> (t, 0, 0, 0));
|
|
|
|
typename Sequence<Time>::PatchChanges::const_iterator i = _patch_changes.lower_bound (search);
|
2014-11-22 04:05:42 -05:00
|
|
|
assert (i == _patch_changes.end() || (*i)->time() >= t);
|
2011-11-22 19:17:31 -05:00
|
|
|
return i;
|
2010-12-28 13:19:40 -05:00
|
|
|
}
|
|
|
|
|
2012-10-10 23:22:17 -04:00
|
|
|
/** Return the earliest sysex with time >= t */
|
|
|
|
template<typename Time>
|
|
|
|
typename Sequence<Time>::SysExes::const_iterator
|
|
|
|
Sequence<Time>::sysex_lower_bound (Time t) const
|
|
|
|
{
|
2016-11-07 05:14:55 -05:00
|
|
|
SysExPtr search (new Event<Time> (NO_EVENT, t));
|
2012-10-10 23:22:17 -04:00
|
|
|
typename Sequence<Time>::SysExes::const_iterator i = _sysexes.lower_bound (search);
|
2014-11-22 04:05:42 -05:00
|
|
|
assert (i == _sysexes.end() || (*i)->time() >= t);
|
2012-10-10 23:22:17 -04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2013-07-23 02:56:30 -04:00
|
|
|
// NON-CONST iterator implementations (x3)
|
|
|
|
|
|
|
|
/** Return the earliest note with time >= t */
|
|
|
|
template<typename Time>
|
|
|
|
typename Sequence<Time>::Notes::iterator
|
|
|
|
Sequence<Time>::note_lower_bound (Time t)
|
|
|
|
{
|
2014-11-22 04:05:42 -05:00
|
|
|
NotePtr search_note(new Note<Time>(0, t, Time(), 0, 0));
|
2013-07-23 02:56:30 -04:00
|
|
|
typename Sequence<Time>::Notes::iterator i = _notes.lower_bound(search_note);
|
2014-11-22 04:05:42 -05:00
|
|
|
assert(i == _notes.end() || (*i)->time() >= t);
|
2013-07-23 02:56:30 -04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the earliest patch change with time >= t */
|
|
|
|
template<typename Time>
|
|
|
|
typename Sequence<Time>::PatchChanges::iterator
|
|
|
|
Sequence<Time>::patch_change_lower_bound (Time t)
|
|
|
|
{
|
|
|
|
PatchChangePtr search (new PatchChange<Time> (t, 0, 0, 0));
|
|
|
|
typename Sequence<Time>::PatchChanges::iterator i = _patch_changes.lower_bound (search);
|
2014-11-22 04:05:42 -05:00
|
|
|
assert (i == _patch_changes.end() || (*i)->time() >= t);
|
2013-07-23 02:56:30 -04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the earliest sysex with time >= t */
|
|
|
|
template<typename Time>
|
|
|
|
typename Sequence<Time>::SysExes::iterator
|
|
|
|
Sequence<Time>::sysex_lower_bound (Time t)
|
|
|
|
{
|
2016-11-07 05:14:55 -05:00
|
|
|
SysExPtr search (new Event<Time> (NO_EVENT, t));
|
2013-07-23 02:56:30 -04:00
|
|
|
typename Sequence<Time>::SysExes::iterator i = _sysexes.lower_bound (search);
|
2014-11-22 04:05:42 -05:00
|
|
|
assert (i == _sysexes.end() || (*i)->time() >= t);
|
2013-07-23 02:56:30 -04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2009-08-12 21:57:03 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
2010-06-02 15:55:37 -04:00
|
|
|
Sequence<Time>::get_notes (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
|
2009-10-21 12:39:39 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
switch (op) {
|
|
|
|
case PitchEqual:
|
|
|
|
case PitchLessThan:
|
|
|
|
case PitchLessThanOrEqual:
|
|
|
|
case PitchGreater:
|
|
|
|
case PitchGreaterThanOrEqual:
|
|
|
|
get_notes_by_pitch (n, op, val, chan_mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VelocityEqual:
|
|
|
|
case VelocityLessThan:
|
|
|
|
case VelocityLessThanOrEqual:
|
|
|
|
case VelocityGreater:
|
|
|
|
case VelocityGreaterThanOrEqual:
|
|
|
|
get_notes_by_velocity (n, op, val, chan_mask);
|
|
|
|
break;
|
|
|
|
}
|
2009-10-21 12:39:39 -04:00
|
|
|
}
|
|
|
|
|
2010-05-28 17:36:38 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
2010-06-02 15:55:37 -04:00
|
|
|
Sequence<Time>::get_notes_by_pitch (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
|
2010-05-28 17:36:38 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
for (uint8_t c = 0; c < 16; ++c) {
|
|
|
|
|
|
|
|
if (chan_mask != 0 && !((1<<c) & chan_mask)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Pitches& p (pitches (c));
|
2014-11-22 04:05:42 -05:00
|
|
|
NotePtr search_note(new Note<Time>(0, Time(), Time(), val, 0));
|
2011-11-22 19:17:31 -05:00
|
|
|
typename Pitches::const_iterator i;
|
|
|
|
switch (op) {
|
|
|
|
case PitchEqual:
|
|
|
|
i = p.lower_bound (search_note);
|
|
|
|
while (i != p.end() && (*i)->note() == val) {
|
|
|
|
n.insert (*i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PitchLessThan:
|
|
|
|
i = p.upper_bound (search_note);
|
|
|
|
while (i != p.end() && (*i)->note() < val) {
|
|
|
|
n.insert (*i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PitchLessThanOrEqual:
|
|
|
|
i = p.upper_bound (search_note);
|
|
|
|
while (i != p.end() && (*i)->note() <= val) {
|
|
|
|
n.insert (*i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PitchGreater:
|
|
|
|
i = p.lower_bound (search_note);
|
|
|
|
while (i != p.end() && (*i)->note() > val) {
|
|
|
|
n.insert (*i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PitchGreaterThanOrEqual:
|
|
|
|
i = p.lower_bound (search_note);
|
|
|
|
while (i != p.end() && (*i)->note() >= val) {
|
|
|
|
n.insert (*i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//fatal << string_compose (_("programming error: %1 %2", X_("get_notes_by_pitch() called with illegal operator"), op)) << endmsg;
|
2014-11-14 04:47:43 -05:00
|
|
|
abort(); /* NOTREACHED*/
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
|
|
|
}
|
2010-06-02 15:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::get_notes_by_velocity (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
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 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;
|
|
|
|
default:
|
|
|
|
// fatal << string_compose (_("programming error: %1 %2", X_("get_notes_by_velocity() called with illegal operator"), op)) << endmsg;
|
2014-11-14 04:47:43 -05:00
|
|
|
abort(); /* NOTREACHED*/
|
2011-11-22 19:17:31 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 17:36:38 -04:00
|
|
|
}
|
|
|
|
|
2010-06-03 11:58:15 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::set_overlap_pitch_resolution (OverlapPitchResolution opr)
|
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
_overlap_pitch_resolution = opr;
|
2010-06-03 11:58:15 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* XXX todo: clean up existing overlaps in source data? */
|
2010-06-03 11:58:15 -04:00
|
|
|
}
|
|
|
|
|
2010-07-11 20:41:45 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
|
|
|
Sequence<Time>::control_list_marked_dirty ()
|
|
|
|
{
|
|
|
|
set_edited (true);
|
|
|
|
}
|
|
|
|
|
2011-06-21 17:29:22 -04:00
|
|
|
template<typename Time>
|
|
|
|
void
|
2020-08-24 16:40:03 -04:00
|
|
|
Sequence<Time>::dump (ostream& str, typename Sequence<Time>::const_iterator x, uint32_t limit) const
|
2011-06-21 17:29:22 -04:00
|
|
|
{
|
2020-08-24 16:40:03 -04:00
|
|
|
typename Sequence<Time>::const_iterator i = begin();
|
|
|
|
|
|
|
|
if (x != end()) {
|
|
|
|
i = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
str << "+++ dump";
|
|
|
|
if (i != end()) {
|
|
|
|
str << " from " << i->time();
|
|
|
|
}
|
|
|
|
str << endl;
|
|
|
|
for (; i != end() && (limit >= 0); ++i) {
|
2011-06-21 17:29:22 -04:00
|
|
|
str << *i << endl;
|
2020-08-24 16:40:03 -04:00
|
|
|
if (limit) {
|
|
|
|
if (--limit == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-21 17:29:22 -04:00
|
|
|
}
|
|
|
|
str << "--- dump\n";
|
|
|
|
}
|
|
|
|
|
2017-09-24 12:03:54 -04:00
|
|
|
template class Sequence<Temporal::Beats>;
|
2011-12-21 21:09:39 -05:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
} // namespace Evoral
|