Beispiel #1
0
void GOrgueMidiInPort::Receive(const std::vector<unsigned char> msg)
{
	if (!IsActive())
		return;

	GOrgueMidiEvent e;
	e.FromMidi(msg, m_midi->GetMidiMap());
	if (e.GetMidiType() == MIDI_NONE)
		return;
	e.SetDevice(GetID());
	e.SetTime(wxGetLocalTimeMillis());

	if (!m_merger.Process(e))
		return;

	/* Compat stuff */
	if (e.GetChannel() != -1)
		e.SetChannel(((e.GetChannel() - 1 + m_ChannelShift) & 0x0F) + 1);

	m_midi->Recv(e);
}
bool GOrgueMidiMerger::Process(GOrgueMidiEvent& e)
{
    if (e.GetMidiType() == MIDI_CTRL_CHANGE && e.GetKey() == MIDI_CTRL_BANK_SELECT_MSB)
    {
        m_BankMsb[e.GetChannel() - 1] = e.GetValue();
        return false;
    }
    if (e.GetMidiType() == MIDI_CTRL_CHANGE && e.GetKey() == MIDI_CTRL_BANK_SELECT_LSB)
    {
        m_BankLsb[e.GetChannel() - 1] = e.GetValue();
        return false;
    }
    if (e.GetMidiType() == MIDI_CTRL_CHANGE && e.GetKey() == MIDI_CTRL_RPN_LSB)
    {
        m_RpnLsb[e.GetChannel() - 1] = e.GetValue();
        m_Rpn = true;
        return false;
    }
    if (e.GetMidiType() == MIDI_CTRL_CHANGE && e.GetKey() == MIDI_CTRL_RPN_MSB)
    {
        m_RpnMsb[e.GetChannel() - 1] = e.GetValue();
        m_Rpn = true;
        return false;
    }
    if (e.GetMidiType() == MIDI_CTRL_CHANGE && e.GetKey() == MIDI_CTRL_NRPN_LSB)
    {
        m_NrpnLsb[e.GetChannel() - 1] = e.GetValue();
        m_Rpn = false;
        return false;
    }
    if (e.GetMidiType() == MIDI_CTRL_CHANGE && e.GetKey() == MIDI_CTRL_NRPN_MSB)
    {
        m_NrpnMsb[e.GetChannel() - 1] = e.GetValue();
        m_Rpn = false;
        return false;
    }
    if (e.GetMidiType() == MIDI_PGM_CHANGE)
        e.SetKey(((e.GetKey() - 1) | (m_BankLsb[e.GetChannel() - 1] << 7) | (m_BankMsb[e.GetChannel() - 1] << 14)) + 1);

    if (e.GetMidiType() == MIDI_CTRL_CHANGE && e.GetKey() == MIDI_CTRL_DATA_ENTRY)
    {
        if (m_Rpn)
        {
            e.SetMidiType(MIDI_RPN);
            e.SetKey((m_RpnLsb[e.GetChannel() - 1] << 0) | (m_RpnMsb[e.GetChannel() - 1] << 7));
        }
        else
        {
            e.SetMidiType(MIDI_NRPN);
            e.SetKey((m_NrpnLsb[e.GetChannel() - 1] << 0) | (m_NrpnMsb[e.GetChannel() - 1] << 7));
        }
    }

    return true;
}