|
@@ -0,0 +1,142 @@
|
|
|
+#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<midi::NoteMessage>& noteMsg_ptr)
|
|
|
+{
|
|
|
+ if(std::dynamic_pointer_cast<midi::NoteOnMessage>(noteMsg_ptr)) {
|
|
|
+ onBeatIndices.insert(beatIndex);
|
|
|
+ } else {
|
|
|
+ offBeatIndices.insert(beatIndex);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void BeatSequenceNoteInformation::unregisterMessage(BeatSequence::BeatIndex beatIndex, const std::shared_ptr<midi::NoteMessage>& noteMsg_ptr)
|
|
|
+{
|
|
|
+ BeatIndexMultiset::const_iterator it;
|
|
|
+ if(std::dynamic_pointer_cast<midi::NoteOnMessage>(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::pushBackMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message>& 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();
|
|
|
+}
|
|
|
+
|
|
|
+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::getNoteInfo(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<midi::Message>& msg_ptr)
|
|
|
+{
|
|
|
+ std::shared_ptr<midi::NoteMessage> noteMsg_ptr
|
|
|
+ = std::dynamic_pointer_cast<midi::NoteMessage>(msg_ptr);
|
|
|
+ if(noteMsg_ptr) {
|
|
|
+ getNoteInfo(noteMsg_ptr->channel, noteMsg_ptr->pitch)
|
|
|
+ .registerMessage(beatIndex, noteMsg_ptr);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void BeatSequence::unregisterMessage(BeatIndex beatIndex, const std::shared_ptr<midi::Message>& msg_ptr)
|
|
|
+{
|
|
|
+ std::shared_ptr<midi::NoteMessage> noteMsg_ptr
|
|
|
+ = std::dynamic_pointer_cast<midi::NoteMessage>(msg_ptr);
|
|
|
+ if(noteMsg_ptr) {
|
|
|
+ getNoteInfo(noteMsg_ptr->channel, noteMsg_ptr->pitch)
|
|
|
+ .unregisterMessage(beatIndex, noteMsg_ptr);
|
|
|
+ }
|
|
|
+}
|