BeatSequence.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "midi/BeatSequence.h"
  3. #include "multiset.h"
  4. #include <map>
  5. #include <ostream>
  6. class BeatSequenceNoteInformation
  7. {
  8. public:
  9. typedef multiset<midi::BeatSequence::BeatIndex> BeatIndexMultiset;
  10. BeatIndexMultiset onBeatIndices, offBeatIndices;
  11. void print(std::ostream& stream, std::size_t indent = 0) const;
  12. void registerMessage(midi::BeatSequence::BeatIndex beatIndex, const std::shared_ptr<midi::NoteMessage>& noteMsg_ptr);
  13. void unregisterMessage(midi::BeatSequence::BeatIndex beatIndex, const std::shared_ptr<midi::NoteMessage>& noteMsg_ptr);
  14. };
  15. class BeatSequence : public midi::BeatSequence
  16. {
  17. typedef midi::BeatSequence parent;
  18. typedef midi::ChannelMessage::Channel Channel;
  19. typedef midi::NoteMessage::Pitch Pitch;
  20. typedef std::pair<Channel, Pitch> ChannelPitchPair;
  21. typedef std::map<ChannelPitchPair, BeatSequenceNoteInformation> NoteInfoMap;
  22. typedef BeatSequenceNoteInformation::BeatIndexMultiset BeatIndexMultiset;
  23. NoteInfoMap noteInfos;
  24. public:
  25. const midi::MessageList& at(BeatIndex beatIndex) const;
  26. const midi::MessageList& operator[](BeatIndex beatIndex) const;
  27. void resize(BeatIndex size);
  28. void pushFrontMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr);
  29. void pushBackMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr);
  30. void eraseMessage(BeatIndex beatIndex, midi::MessageList::const_iterator msg_it);
  31. void expand(BeatIndex factor);
  32. void reduceToNeighbour(BeatIndex factor);
  33. void reduceErasingConflicts(BeatIndex factor);
  34. const BeatIndexMultiset& getNoteOnBeatIndices(Channel channel, Pitch pitch);
  35. const BeatIndexMultiset& getNoteOffBeatIndices(Channel channel, Pitch pitch);
  36. const BeatSequenceNoteInformation& getNoteInfo(Channel channel, Pitch pitch);
  37. void printRegistry(std::ostream& stream) const;
  38. private:
  39. BeatSequenceNoteInformation& getMutableNoteInfo(Channel channel, Pitch pitch);
  40. void refreshRegistry();
  41. void registerMessage(BeatIndex beatIndex, const std::shared_ptr<midi::Message>& msg_ptr);
  42. void unregisterMessage(BeatIndex beatIndex, const std::shared_ptr<midi::Message>& msg_ptr);
  43. };