BeatSequence.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. void resize(BeatIndex size);
  26. void pushFrontMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr);
  27. void pushBackMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr);
  28. void eraseMessage(BeatIndex beatIndex, midi::MessageList::iterator msg_it);
  29. void expand(BeatIndex factor);
  30. void reduceToNeighbour(BeatIndex factor);
  31. void reduceErasingConflicts(BeatIndex factor);
  32. const BeatIndexMultiset& getNoteOnBeatIndices(Channel channel, Pitch pitch);
  33. const BeatIndexMultiset& getNoteOffBeatIndices(Channel channel, Pitch pitch);
  34. const BeatSequenceNoteInformation& getNoteInfo(Channel channel, Pitch pitch);
  35. void printRegistry(std::ostream& stream) const;
  36. private:
  37. BeatSequenceNoteInformation& getMutableNoteInfo(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. };