summaryrefslogtreecommitdiff
path: root/libs/evoral/src
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-06-21 12:08:12 +0200
committerRobin Gareus <robin@gareus.org>2017-06-21 18:12:29 +0200
commit3d15499cdacacbafa32c8fcfb1389e6f0716ce9c (patch)
tree2ac9f1c45ae8ebd256bdb838ffe925898fd733b5 /libs/evoral/src
parentd6c47def098ebf6c44e1b3e0ca2166d1c990e7d3 (diff)
Clamp values in ControlList
Diffstat (limited to 'libs/evoral/src')
-rw-r--r--libs/evoral/src/ControlList.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/libs/evoral/src/ControlList.cpp b/libs/evoral/src/ControlList.cpp
index 516ffc56c2..4ee50a3635 100644
--- a/libs/evoral/src/ControlList.cpp
+++ b/libs/evoral/src/ControlList.cpp
@@ -542,6 +542,9 @@ ControlList::editor_add (double when, double value, bool with_guard)
return false;
}
+ /* clamp new value to allowed range */
+ value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, value));
+
if (_events.empty()) {
/* as long as the point we're adding is not at zero,
@@ -562,11 +565,6 @@ ControlList::editor_add (double when, double value, bool with_guard)
maybe_add_insert_guard (when);
}
- /* clamp new value to allowed range */
-
- value = max ((double)_desc.lower, value);
- value = min ((double)_desc.upper, value);
-
iterator result;
DEBUG_TRACE (DEBUG::ControlList, string_compose ("editor_add: actually add when= %1 value= %2\n", when, value));
result = _events.insert (i, new ControlEvent (when, value));
@@ -646,12 +644,14 @@ ControlList::erase_from_iterator_to (iterator iter, double when)
return iter;
}
+/* this is for making changes from some kind of user interface or
+ * control surface (GUI, MIDI, OSC etc)
+ */
void
ControlList::add (double when, double value, bool with_guards, bool with_initial)
{
- /* this is for making changes from some kind of user interface or
- control surface (GUI, MIDI, OSC etc)
- */
+ /* clamp new value to allowed range */
+ value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, value));
DEBUG_TRACE (DEBUG::ControlList,
string_compose ("@%1 add %2 at %3 guards = %4 write pass = %5 (new? %6) at end? %7\n",
@@ -936,9 +936,12 @@ void
ControlList::modify (iterator iter, double when, double val)
{
/* note: we assume higher level logic is in place to avoid this
- reordering the time-order of control events in the list. ie. all
- points after *iter are later than when.
- */
+ * reordering the time-order of control events in the list. ie. all
+ * points after *iter are later than when.
+ */
+
+ /* catch possible float/double rounding errors from higher levels */
+ val = std::min ((double)_desc.upper, std::max ((double)_desc.lower, val));
{
Glib::Threads::RWLock::WriterLock lm (_lock);
@@ -1774,6 +1777,8 @@ ControlList::paste (const ControlList& alist, double pos)
if (_desc.toggled) {
value = (value < 0.5) ? 0.0 : 1.0;
}
+ /* catch possible rounding errors */
+ value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, value));
}
_events.insert (where, new ControlEvent((*i)->when + pos, value));
end = (*i)->when + pos;