Fix range problems for pitch wheel controller.

git-svn-id: svn://localhost/ardour2/branches/3.0@3308 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2008-05-02 21:34:00 +00:00
parent ab2af5d185
commit fb1fbf71af
4 changed files with 16 additions and 10 deletions

View File

@ -1169,6 +1169,7 @@ AutomationLine::set_state (const XMLNode &node)
void
AutomationLine::view_to_model_y (double& y)
{
/* TODO: This should be more generic ... */
if (alist->parameter().type() == GainAutomation) {
y = slider_position_to_gain (y);
y = max (0.0, y);
@ -1176,25 +1177,26 @@ AutomationLine::view_to_model_y (double& y)
} else if (alist->parameter().type() == PanAutomation) {
// vertical coordinate axis reversal
y = 1.0 - y;
} else if (alist->parameter().type() == MidiCCAutomation) {
y = (int)(y * 127.0);
} else if (alist->parameter().type() == PluginAutomation) {
y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
} else {
y = (int)(y * alist->parameter().max());
}
}
void
AutomationLine::model_to_view_y (double& y)
{
/* TODO: This should be more generic ... */
if (alist->parameter().type() == GainAutomation) {
y = gain_to_slider_position (y);
} else if (alist->parameter().type() == PanAutomation) {
// vertical coordinate axis reversal
y = 1.0 - y;
} else if (alist->parameter().type() == MidiCCAutomation) {
y = y / 127.0;
} else if (alist->parameter().type() == PluginAutomation) {
y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
} else {
y = y / (double)alist->parameter().max(); /* ... like this */
}
}

View File

@ -339,7 +339,8 @@ MidiTimeAxisView::create_automation_child (Parameter param, bool show)
boost::shared_ptr<AutomationControl> c = _route->control(param);
if (!c) {
boost::shared_ptr<AutomationList> al(new ARDOUR::AutomationList(param, 0, 127, 64));
boost::shared_ptr<AutomationList> al(new ARDOUR::AutomationList(param,
param.min(), param.max(), (param.max() - param.min() / 2)));
c = boost::shared_ptr<AutomationControl>(_route->control_factory(al));
_route->add_control(c);
}

View File

@ -55,6 +55,7 @@ static void dumpit (const AutomationList& al, string prefix = "")
}
#endif
/* XXX: min_val max_val redundant? (param.min() param.max()) */
AutomationList::AutomationList (Parameter id, double min_val, double max_val, double default_val)
: _parameter(id)
, _interpolation(Linear)

View File

@ -109,8 +109,8 @@ MidiModel::const_iterator::const_iterator(const MidiModel& model, double t)
}
assert(x >= 0);
assert(y >= 0);
assert(y <= UINT8_MAX);
assert(y >= i->first.min());
assert(y <= i->first.max());
const MidiControlIterator new_iter(i->second->list(), x, y);
@ -202,7 +202,7 @@ MidiModel::const_iterator::operator++()
for (std::vector<MidiControlIterator>::iterator i = _control_iters.begin();
i != _control_iters.end(); ++i) {
if (i->x < _control_iter->x && i != old_control_iter) {
if (i->x < _control_iter->x) {
_control_iter = i;
}
}
@ -227,7 +227,9 @@ MidiModel::const_iterator::operator++()
}
// Use the next earliest controller iff it's earlier than the note event
if (_control_iter != _control_iters.end() && _control_iter->x != DBL_MAX)
if (_control_iter != _control_iters.end()
&& _control_iter->x != DBL_MAX
&& _control_iter != old_control_iter)
if (type == NIL || _control_iter->x < t)
type = AUTOMATION;
@ -386,7 +388,7 @@ MidiModel::control_to_midi_event(MIDI::Event& ev, const MidiControlIterator& ite
assert(iter.automation_list);
assert(iter.automation_list->parameter().channel() < 16);
assert(iter.automation_list->parameter().id() <= INT8_MAX);
assert(iter.y <= INT8_MAX);
assert(iter.y < (1<<14));
ev.buffer()[0] = MIDI_CMD_BENDER + iter.automation_list->parameter().channel();
ev.buffer()[1] = ((Byte)iter.y) & 0x7F; // LSB
ev.buffer()[2] = (((Byte)iter.y) >> 7) & 0x7F; // MSB