#include "BeatSequence.h" void BeatSequenceNoteInformation::print(std::ostream& stream, std::size_t indent) const { stream << std::string(indent, ' ') << "note on beat indices:"; for(BeatIndexMultiset::const_iterator it = onBeatIndices.begin(); it != onBeatIndices.end(); it++) { stream << " " << *it; } stream << "\n"; stream << std::string(indent, ' ') << "note off beat indices:"; for(BeatIndexMultiset::const_iterator it = offBeatIndices.begin(); it != offBeatIndices.end(); it++) { stream << " " << *it; } stream << "\n"; if(indent == 0) { stream << "\n"; } stream.flush(); } void BeatSequenceNoteInformation::registerMessage(BeatSequence::BeatIndex beatIndex, const std::shared_ptr& noteMsg_ptr) { if(std::dynamic_pointer_cast(noteMsg_ptr)) { onBeatIndices.insert(beatIndex); } else { offBeatIndices.insert(beatIndex); } } void BeatSequenceNoteInformation::unregisterMessage(BeatSequence::BeatIndex beatIndex, const std::shared_ptr& noteMsg_ptr) { BeatIndexMultiset::const_iterator it; if(std::dynamic_pointer_cast(noteMsg_ptr)) { it = onBeatIndices.find(beatIndex); if(it != onBeatIndices.end()) { onBeatIndices.erase(it); } } else { it = offBeatIndices.find(beatIndex); if(it != offBeatIndices.end()) { offBeatIndices.erase(it); } } } const midi::MessageList& BeatSequence::at(BeatIndex beatIndex) const { return parent::at(beatIndex); } const midi::MessageList& BeatSequence::operator[](BeatIndex beatIndex) const { return parent::operator[](beatIndex); } void BeatSequence::resize(BeatIndex size) { parent::resize(size); refreshRegistry(); } void BeatSequence::pushFrontMessage(BeatIndex beatIndex, std::shared_ptr msg_ptr) { parent::at(beatIndex).push_front(msg_ptr); registerMessage(beatIndex, msg_ptr); } void BeatSequence::pushBackMessage(BeatIndex beatIndex, std::shared_ptr msg_ptr) { parent::at(beatIndex).push_back(msg_ptr); registerMessage(beatIndex, msg_ptr); } void BeatSequence::eraseMessage(BeatIndex beatIndex, midi::MessageList::const_iterator msg_it) { unregisterMessage(beatIndex, *msg_it); parent::at(beatIndex).erase(msg_it); } void BeatSequence::expand(BeatIndex factor) { parent::expand(factor); refreshRegistry(); } void BeatSequence::reduceToNeighbour(BeatIndex factor) { parent::reduceToNeighbour(factor); refreshRegistry(); } void BeatSequence::reduceErasingConflicts(BeatIndex factor) { parent::reduceErasingConflicts(factor); refreshRegistry(); } const BeatSequence::BeatIndexMultiset& BeatSequence::getNoteOnBeatIndices(Channel channel, Pitch pitch) { return getNoteInfo(channel, pitch).onBeatIndices; } const BeatSequence::BeatIndexMultiset& BeatSequence::getNoteOffBeatIndices(Channel channel, Pitch pitch) { return getNoteInfo(channel, pitch).offBeatIndices; } const BeatSequenceNoteInformation& BeatSequence::getNoteInfo(Channel channel, Pitch pitch) { return getMutableNoteInfo(channel, pitch); } void BeatSequence::printRegistry(std::ostream& stream) const { stream << "beat sequence note info registry: \n"; for(NoteInfoMap::const_iterator noteInfo_it = noteInfos.begin(); noteInfo_it != noteInfos.end(); noteInfo_it++) { stream << std::string(4, ' '); stream << "channel #" << (int)(noteInfo_it->first.first + 1); stream << " pitch=" << (int)noteInfo_it->first.second << ": \n"; noteInfo_it->second.print(stream, 8); } stream.flush(); } BeatSequenceNoteInformation& BeatSequence::getMutableNoteInfo(Channel channel, Pitch pitch) { ChannelPitchPair key(channel, pitch); return noteInfos[key]; } void BeatSequence::refreshRegistry() { noteInfos.clear(); for(BeatIndex beatIndex = 0; beatIndex < size(); beatIndex++) { const midi::MessageList& beat = at(beatIndex); for(midi::MessageList::const_iterator msg_it = beat.begin(); msg_it != beat.end(); msg_it++) { registerMessage(beatIndex, *msg_it); } } } void BeatSequence::registerMessage(BeatIndex beatIndex, const std::shared_ptr& msg_ptr) { std::shared_ptr noteMsg_ptr = std::dynamic_pointer_cast(msg_ptr); if(noteMsg_ptr) { getMutableNoteInfo(noteMsg_ptr->channel, noteMsg_ptr->pitch) .registerMessage(beatIndex, noteMsg_ptr); } } void BeatSequence::unregisterMessage(BeatIndex beatIndex, const std::shared_ptr& msg_ptr) { std::shared_ptr noteMsg_ptr = std::dynamic_pointer_cast(msg_ptr); if(noteMsg_ptr) { getMutableNoteInfo(noteMsg_ptr->channel, noteMsg_ptr->pitch) .unregisterMessage(beatIndex, noteMsg_ptr); } }