diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
commit | 145364a8af6a1fec06556221e66d4b724a62fc9a (patch) | |
tree | 53bd71a544008c518034f208d64c932dc2883f50 /src/sound/MappedComposition.cpp | |
download | rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip |
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/sound/MappedComposition.cpp')
-rw-r--r-- | src/sound/MappedComposition.cpp | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/src/sound/MappedComposition.cpp b/src/sound/MappedComposition.cpp new file mode 100644 index 0000000..975fccf --- /dev/null +++ b/src/sound/MappedComposition.cpp @@ -0,0 +1,216 @@ +// -*- c-indentation-style:"stroustrup" c-basic-offset: 4 -*- + +/* + Rosegarden + A sequencer and musical notation editor. + + This program is Copyright 2000-2008 + Guillaume Laurent <[email protected]>, + Chris Cannam <[email protected]>, + Richard Bown <[email protected]> + + The moral right of the authors to claim authorship of this work + has been asserted. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include <qdatastream.h> +#include "MappedComposition.h" +#include "MappedEvent.h" +#include "SegmentPerformanceHelper.h" +#include <iostream> + +namespace Rosegarden +{ + +using std::cerr; +using std::cout; +using std::endl; + +MappedComposition::~MappedComposition() +{ + clear(); +} + +// copy constructor +MappedComposition::MappedComposition(const MappedComposition &mC): + std::multiset<MappedEvent *, MappedEvent::MappedEventCmp>() +{ + clear(); + + // deep copy + for (MappedComposition::const_iterator it = mC.begin(); it != mC.end(); it++) + this->insert(new MappedEvent(**it)); + +} + +// Turn a MappedComposition into a QDataStream - MappedEvents can +// stream themselves. +// +QDataStream& +operator<<(QDataStream &dS, MappedComposition *mC) +{ + dS << int(mC->size()); + + for (MappedCompositionIterator it = mC->begin(); it != mC->end(); ++it ) + dS << (*it); + + return dS; +} + + +QDataStream& +operator<<(QDataStream &dS, const MappedComposition &mC) +{ + dS << int(mC.size()); + + for (MappedComposition::const_iterator it = mC.begin(); it != mC.end(); ++it ) + dS << (*it); + + return dS; +} + + +// Turn a QDataStream into a MappedComposition +// +QDataStream& +operator>>(QDataStream &dS, MappedComposition *mC) +{ + int sliceSize; + MappedEvent *mE; + + dS >> sliceSize; + + while (!dS.atEnd() && sliceSize) { + mE = new MappedEvent(); + dS >> mE; + + try { + mC->insert(mE); + } catch (...) { + ; + } + + sliceSize--; + + } + +#ifdef DEBUG_MAPPEDCOMPOSITION + if (sliceSize) { + cerr << "operator>> - wrong number of events received" << endl; + } +#endif + + return dS; +} + +QDataStream& +operator>>(QDataStream &dS, MappedComposition &mC) +{ + int sliceSize; + MappedEvent *mE; + + dS >> sliceSize; + + while (!dS.atEnd() && sliceSize) { + mE = new MappedEvent(); + + dS >> mE; + + try { + mC.insert(mE); + } catch (...) { + ; + } + + sliceSize--; + + } + +#ifdef DEBUG_MAPPEDCOMPOSITION + if (sliceSize) { + cerr << "operator>> - wrong number of events received" << endl; + } +#endif + + + return dS; +} + +// Move the start time of this MappedComposition and all its events. +// Actually - we have a special case for audio events at the moment.. +// +// +void +MappedComposition::moveStartTime(const RealTime &mT) +{ + MappedCompositionIterator it; + + for (it = this->begin(); it != this->end(); ++it) { + // Reset start time and duration + // + (*it)->setEventTime((*it)->getEventTime() + mT); + (*it)->setDuration((*it)->getDuration() - mT); + + // For audio adjust the start index + // + if ((*it)->getType() == MappedEvent::Audio) + (*it)->setAudioStartMarker((*it)->getAudioStartMarker() + mT); + } + + m_startTime = m_startTime + mT; + m_endTime = m_endTime + mT; + +} + + +// Concatenate MappedComposition +// +MappedComposition& +MappedComposition::operator+(const MappedComposition &mC) +{ + for (MappedComposition::const_iterator it = mC.begin(); it != mC.end(); it++) + this->insert(new MappedEvent(**it)); // deep copy + + return *this; +} + +// Assign (clear and deep copy) +// +MappedComposition& +MappedComposition::operator=(const MappedComposition &mC) +{ + if (&mC == this) + return * this; + + clear(); + + // deep copy + for (MappedComposition::const_iterator it = mC.begin(); it != mC.end(); it++) + this->insert(new MappedEvent(**it)); + + return *this; +} + +void +MappedComposition::clear() +{ + // Only clear if the events aren't persistent + // + for (MappedCompositionIterator it = this->begin(); it != this->end(); it++) + if (!(*it)->isPersistent()) + delete (*it); + + this->erase(this->begin(), this->end()); +} + + + +} + + |