BankList MidiDevice::getBanksByLSB(bool percussion, MidiByte lsb) const { BankList banks; for (BankList::const_iterator it = m_bankList.begin(); it != m_bankList.end(); ++it) { if (it->isPercussion() == percussion && it->getLSB() == lsb) banks.push_back(*it); } return banks; }
MidiByteList MidiDevice::getDistinctLSBs(bool percussion, int msb) const { std::set<MidiByte> lsbs; for (BankList::const_iterator it = m_bankList.begin(); it != m_bankList.end(); ++it) { if (it->isPercussion() == percussion && (msb == -1 || it->getMSB() == msb)) lsbs.insert(it->getLSB()); } MidiByteList v; for (std::set<MidiByte>::iterator i = lsbs.begin(); i != lsbs.end(); ++i) { v.push_back(*i); } return v; }
std::string MidiDevice::toXmlString() const { std::stringstream midiDevice; midiDevice << " <device id=\"" << m_id << "\" name=\"" << m_name << "\" direction=\"" << (m_direction == Play ? "play" : "record") << "\" variation=\"" << (m_variationType == VariationFromLSB ? "LSB" : m_variationType == VariationFromMSB ? "MSB" : "") << "\" connection=\"" << encode(m_connection) << "\" type=\"midi\">" << std::endl << std::endl; midiDevice << " <librarian name=\"" << encode(m_librarian.first) << "\" email=\"" << encode(m_librarian.second) << "\"/>" << std::endl; if (m_metronome) { // Write out the metronome - watch the MidiBytes // when using the stringstream // midiDevice << " <metronome " << "instrument=\"" << m_metronome->getInstrument() << "\" " << "barpitch=\"" << (int)m_metronome->getBarPitch() << "\" " << "beatpitch=\"" << (int)m_metronome->getBeatPitch() << "\" " << "subbeatpitch=\"" << (int)m_metronome->getSubBeatPitch() << "\" " << "depth=\"" << (int)m_metronome->getDepth() << "\" " << "barvelocity=\"" << (int)m_metronome->getBarVelocity() << "\" " << "beatvelocity=\"" << (int)m_metronome->getBeatVelocity() << "\" " << "subbeatvelocity=\"" << (int)m_metronome->getSubBeatVelocity() << "\"/>" << std::endl << std::endl; } // and now bank information // BankList::const_iterator it; InstrumentList::const_iterator iit; ProgramList::const_iterator pt; for (it = m_bankList.begin(); it != m_bankList.end(); ++it) { midiDevice << " <bank " << "name=\"" << encode(it->getName()) << "\" " << "percussion=\"" << (it->isPercussion() ? "true" : "false") << "\" " << "msb=\"" << (int)it->getMSB() << "\" " << "lsb=\"" << (int)it->getLSB() << "\">" << std::endl; // Not terribly efficient // for (pt = m_programList.begin(); pt != m_programList.end(); ++pt) { if (pt->getBank().partialCompare(*it)) { midiDevice << " <program " << "id=\"" << (int)pt->getProgram() << "\" " << "name=\"" << encode(pt->getName()) << "\" "; if (!pt->getKeyMapping().empty()) { midiDevice << "keymapping=\"" << encode(pt->getKeyMapping()) << "\" "; } midiDevice << "/>" << std::endl; } } midiDevice << " </bank>" << std::endl << std::endl; } // Now controllers (before Instruments, which can depend on // Controller colours) // midiDevice << " <controls>" << std::endl; ControlList::const_iterator cIt; for (cIt = m_controlList.begin(); cIt != m_controlList.end() ; ++cIt) midiDevice << cIt->toXmlString(); midiDevice << " </controls>" << std::endl << std::endl; // Add instruments // for (iit = m_instruments.begin(); iit != m_instruments.end(); ++iit) midiDevice << (*iit)->toXmlString(); KeyMappingList::const_iterator kit; for (kit = m_keyMappingList.begin(); kit != m_keyMappingList.end(); ++kit) { midiDevice << " <keymapping " << "name=\"" << encode(kit->getName()) << "\">\n"; for (MidiKeyMapping::KeyNameMap::const_iterator nmi = kit->getMap().begin(); nmi != kit->getMap().end(); ++nmi) { midiDevice << " <key number=\"" << (int)nmi->first << "\" name=\"" << encode(nmi->second) << "\"/>\n"; } midiDevice << " </keymapping>\n"; } midiDevice << " </device>" << std::endl; return midiDevice.str(); }