1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include "BeatSequence.h"
- #include <sstream>
- namespace midi {
- BeatSequence::BeatSequence()
- : BeatSequence(0)
- {
- }
- BeatSequence::BeatSequence(BeatIndex size)
- : parent(size)
- {
- }
- void BeatSequence::expand(BeatIndex factor)
- {
- if(factor < 1) {
- throw "factor may not be less than 1.";
- }
- resize(size() * factor);
- for(signed int targetIndex = (size() - factor); targetIndex > 0; targetIndex -= factor)
- {
- BeatIndex sourceIndex = targetIndex / factor;
- at(sourceIndex).swap(at(targetIndex));
- }
- }
- void BeatSequence::print(std::ostream& stream) const
- {
- stream << "beat sequence:\n";
- for(BeatIndex beatIndex = 0; beatIndex < size(); beatIndex++) {
- std::stringstream beatLabelStream;
- beatLabelStream << "beat #" << beatIndex << ": ";
- std::string beatLabel = beatLabelStream.str();
- stream << beatLabel;
- std::string spacer(beatLabel.size(), ' ');
- const MessageList& beat = at(beatIndex);
- if(beat.size() == 0) {
- stream << "no message" << "\n";
- } else {
- for(MessageList::const_iterator msg_it = beat.begin(); msg_it != beat.end(); msg_it++) {
- if(msg_it != beat.begin()) {
- stream << spacer;
- }
- (*msg_it)->print(stream);
- }
- }
- }
- stream << "\n";
- stream.flush();
- }
- } // namepsace
|