void
MIDIInstrumentParameterPanel::slotControllerChanged(int controllerNumber)
{
    RG_DEBUG << "slotControllerChanged(" << controllerNumber << ")";

    if (!getSelectedInstrument())
        return;

    int value = -1;

    // Figure out who sent this signal.
    Rotary *rotary = dynamic_cast<Rotary *>(m_rotaryMapper->mapping(controllerNumber));
    if (rotary)
        value = static_cast<int>(std::floor(rotary->getPosition() + .5));

    if (value == -1) {
        std::cerr << "MIDIInstrumentParameterPanel::slotControllerChanged(): Couldn't get value of rotary for controller " << controllerNumber << '\n';
        return;
    }

    getSelectedInstrument()->setControllerValue(
            static_cast<MidiByte>(controllerNumber),
            static_cast<MidiByte>(value));
    getSelectedInstrument()->sendController(
            static_cast<MidiByte>(controllerNumber),
            static_cast<MidiByte>(value));
    getSelectedInstrument()->changed();
}