summaryrefslogtreecommitdiff
path: root/libs/evoral/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-12-01 14:28:03 -0500
committerDavid Robillard <d@drobilla.net>2014-12-01 23:35:24 -0500
commit767c0238a34ef4acc4d345e88cd5ddb0c8a8e421 (patch)
treefed11fb6f4e4e08a7c35eb45f53aea70dc66e4f8 /libs/evoral/src
parentcb8abbe8d2f0e4dfe52bd35613ebba7689628eca (diff)
Replace half-baked param metadata with descriptor.
Among other things, this means that automation controls/lists have the actual min/max/normal/toggled of parameters, and not those inferred from the Parameter ID, which is not correct for things like plugin parameters. Pushing things down to the Evoral::ParmeterDescriptor may be useful in the future to have lists do smarter things based on parameter range, but currently I have just pushed down the above-mentioned currently used attributes.
Diffstat (limited to 'libs/evoral/src')
-rw-r--r--libs/evoral/src/Control.cpp10
-rw-r--r--libs/evoral/src/ControlList.cpp25
-rw-r--r--libs/evoral/src/ParameterDescriptor.cpp67
-rw-r--r--libs/evoral/src/Sequence.cpp6
4 files changed, 93 insertions, 15 deletions
diff --git a/libs/evoral/src/Control.cpp b/libs/evoral/src/Control.cpp
index 480d027ccc..b7537c57ed 100644
--- a/libs/evoral/src/Control.cpp
+++ b/libs/evoral/src/Control.cpp
@@ -22,14 +22,16 @@
#include "evoral/Control.hpp"
#include "evoral/ControlList.hpp"
+#include "evoral/ParameterDescriptor.hpp"
+#include "evoral/TypeMap.hpp"
namespace Evoral {
-Parameter::TypeMetadata Parameter::_type_metadata;
-
-Control::Control(const Parameter& parameter, boost::shared_ptr<ControlList> list)
+Control::Control(const Parameter& parameter,
+ const ParameterDescriptor& desc,
+ boost::shared_ptr<ControlList> list)
: _parameter(parameter)
- , _user_value(list ? list->default_value() : parameter.normal())
+ , _user_value(list ? list->default_value() : desc.normal)
{
set_list (list);
}
diff --git a/libs/evoral/src/ControlList.cpp b/libs/evoral/src/ControlList.cpp
index 0876cdef28..a4b98934c2 100644
--- a/libs/evoral/src/ControlList.cpp
+++ b/libs/evoral/src/ControlList.cpp
@@ -28,10 +28,14 @@
#endif
#include <cassert>
-#include <utility>
+#include <cmath>
#include <iostream>
+#include <utility>
+
#include "evoral/ControlList.hpp"
#include "evoral/Curve.hpp"
+#include "evoral/ParameterDescriptor.hpp"
+#include "evoral/TypeMap.hpp"
#include "pbd/compose.h"
#include "pbd/debug.h"
@@ -46,16 +50,17 @@ inline bool event_time_less_than (ControlEvent* a, ControlEvent* b)
return a->when < b->when;
}
-ControlList::ControlList (const Parameter& id)
+ControlList::ControlList (const Parameter& id, const ParameterDescriptor& desc)
: _parameter(id)
- , _interpolation(id.toggled() ? Discrete : Linear)
+ , _desc(desc)
, _curve(0)
{
+ _interpolation = desc.toggled ? Discrete : Linear;
_frozen = 0;
_changed_when_thawed = false;
- _min_yval = id.min();
- _max_yval = id.max();
- _default_value = id.normal();
+ _min_yval = desc.lower;
+ _max_yval = desc.upper;
+ _default_value = desc.normal;
_lookup_cache.left = -1;
_lookup_cache.range.first = _events.end();
_lookup_cache.range.second = _events.end();
@@ -71,6 +76,7 @@ ControlList::ControlList (const Parameter& id)
ControlList::ControlList (const ControlList& other)
: _parameter(other._parameter)
+ , _desc(other._desc)
, _interpolation(other._interpolation)
, _curve(0)
{
@@ -96,6 +102,7 @@ ControlList::ControlList (const ControlList& other)
ControlList::ControlList (const ControlList& other, double start, double end)
: _parameter(other._parameter)
+ , _desc(other._desc)
, _interpolation(other._interpolation)
, _curve(0)
{
@@ -136,9 +143,9 @@ ControlList::~ControlList()
}
boost::shared_ptr<ControlList>
-ControlList::create(Parameter id)
+ControlList::create(const Parameter& id, const ParameterDescriptor& desc)
{
- return boost::shared_ptr<ControlList>(new ControlList(id));
+ return boost::shared_ptr<ControlList>(new ControlList(id, desc));
}
bool
@@ -1503,7 +1510,7 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, do
boost::shared_ptr<ControlList>
ControlList::cut_copy_clear (double start, double end, int op)
{
- boost::shared_ptr<ControlList> nal = create (_parameter);
+ boost::shared_ptr<ControlList> nal = create (_parameter, _desc);
iterator s, e;
ControlEvent cp (start, 0.0);
diff --git a/libs/evoral/src/ParameterDescriptor.cpp b/libs/evoral/src/ParameterDescriptor.cpp
new file mode 100644
index 0000000000..ffac8d2fd3
--- /dev/null
+++ b/libs/evoral/src/ParameterDescriptor.cpp
@@ -0,0 +1,67 @@
+/* This file is part of Evoral.
+ * Copyright (C) 2000-2014 Paul Davis
+ * Author: David Robillard
+ *
+ * Evoral 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.
+ *
+ * Evoral 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 details.
+ *
+ * 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "evoral/ParameterDescriptor.hpp"
+
+namespace Evoral {
+
+ParameterDescriptor::ParameterDescriptor()
+ : key((uint32_t)-1)
+ , datatype(Variant::NOTHING)
+ , unit(NONE)
+ , normal(0)
+ , lower(0)
+ , upper(0)
+ , step(0)
+ , smallstep(0)
+ , largestep(0)
+ , integer_step(false)
+ , toggled(false)
+ , logarithmic(false)
+ , sr_dependent(false)
+ , min_unbound(0)
+ , max_unbound(0)
+ , enumeration(false)
+{}
+
+/* Set step, smallstep, and largestep, based on current description */
+void
+ParameterDescriptor::update_steps()
+{
+ if (unit == ParameterDescriptor::MIDI_NOTE) {
+ step = smallstep = 1; // semitone
+ largestep = 12; // octave
+ } else if (integer_step) {
+ const float delta = upper - lower;
+
+ smallstep = delta / 10000.0f;
+ step = delta / 1000.0f;
+ largestep = delta / 40.0f;
+
+ smallstep = std::max(1.0, rint(smallstep));
+ step = std::max(1.0, rint(step));
+ largestep = std::max(1.0, rint(largestep));
+ }
+ /* else: leave all others as default '0'
+ * in that case the UI (eg. AutomationController::create)
+ * uses internal_to_interface() to map the value
+ * to an appropriate interface range
+ */
+}
+
+} // namespace Evoral
diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp
index fca4879322..dd891a0ac2 100644
--- a/libs/evoral/src/Sequence.cpp
+++ b/libs/evoral/src/Sequence.cpp
@@ -35,6 +35,7 @@
#include "evoral/ControlList.hpp"
#include "evoral/ControlSet.hpp"
#include "evoral/EventSink.hpp"
+#include "evoral/ParameterDescriptor.hpp"
#include "evoral/Sequence.hpp"
#include "evoral/TypeMap.hpp"
#include "evoral/midi_util.h"
@@ -140,9 +141,10 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t
assert(x >= 0);
- if (y < i->first.min() || y > i->first.max()) {
+ const ParameterDescriptor& desc = seq.type_map().descriptor(i->first);
+ if (y < desc.lower || y > desc.upper) {
cerr << "ERROR: Controller value " << y
- << " out of range [" << i->first.min() << "," << i->first.max()
+ << " out of range [" << desc.lower << "," << desc.upper
<< "], event ignored" << endl;
continue;
}