BeatSequence.h 2.0 KB

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