BeatSequence.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "midi/BeatSequence.h"
  2. #include "multiset.h"
  3. #include <map>
  4. #include <ostream>
  5. class BeatSequenceNoteInformation
  6. {
  7. public:
  8. typedef 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. const BeatSequenceNoteInformation& getNoteInfo(Channel channel, Pitch pitch);
  36. void printRegistry(std::ostream& stream) const;
  37. private:
  38. BeatSequenceNoteInformation& getMutableNoteInfo(Channel channel, Pitch pitch);
  39. void refreshRegistry();
  40. void registerMessage(BeatIndex beatIndex, const std::shared_ptr<midi::Message>& msg_ptr);
  41. void unregisterMessage(BeatIndex beatIndex, const std::shared_ptr<midi::Message>& msg_ptr);
  42. };