diff --git a/src/core/base/IMixer.h b/src/core/base/IMixer.h index 2cb1814..2b554bd 100644 --- a/src/core/base/IMixer.h +++ b/src/core/base/IMixer.h @@ -74,12 +74,13 @@ namespace talcs { virtual void eraseSource(const SourceIterator &srcIt) = 0; virtual void removeAllSources() = 0; - virtual void moveSource(const SourceIterator &pos, const SourceIterator &target) = 0; + virtual void moveSource(const SourceIterator &pos, const SourceIterator &first, const SourceIterator &last) = 0; virtual void swapSource(const SourceIterator &first, const SourceIterator &second) = 0; virtual QList sources() const = 0; virtual SourceIterator firstSource() const = 0; virtual SourceIterator lastSource() const = 0; + virtual SourceIterator sourceAt(int index) const = 0; virtual SourceIterator findSource(T *src) const = 0; virtual SourceIterator nullIterator() const = 0; diff --git a/src/core/base/IMixer_p.h b/src/core/base/IMixer_p.h index dbf48f6..d3510f7 100644 --- a/src/core/base/IMixer_p.h +++ b/src/core/base/IMixer_p.h @@ -95,8 +95,8 @@ namespace talcs { return SrcIt(std::find(sourceList.cbegin(), sourceList.cend(), src), &sourceList); } - void moveSource(const SrcIt &pos, const SrcIt &target) { - sourceList.splice(pos.m_it, sourceList, target.m_it); + void moveSource(const SrcIt &pos, const SrcIt &first, const SrcIt &last) { + sourceList.splice(pos.m_it, sourceList, first.m_it, last.m_it); } void swapSource(const SrcIt &first, const SrcIt &second) { @@ -138,6 +138,13 @@ namespace talcs { return sourceIteratorEnd().previous(); } + SrcIt sourceAt(int index) const { + auto it = sourceList.cbegin(); + while (index--) + it++; + return SrcIt(it, &sourceList); + } + int soloCounter = 0; void setSourceSolo(T *src, bool isSolo) { diff --git a/src/core/source/MixerAudioSource.cpp b/src/core/source/MixerAudioSource.cpp index c13320b..1915a33 100644 --- a/src/core/source/MixerAudioSource.cpp +++ b/src/core/source/MixerAudioSource.cpp @@ -144,11 +144,10 @@ namespace talcs { d->removeAllSources(); } - void MixerAudioSource::moveSource(const MixerAudioSource::SourceIterator &pos, - const MixerAudioSource::SourceIterator &target) { + void MixerAudioSource::moveSource(const MixerAudioSource::SourceIterator &pos, const SourceIterator &first, const SourceIterator &last) { Q_D(MixerAudioSource); QMutexLocker locker(&d->mutex); - d->moveSource(pos, target); + d->moveSource(pos, first, last); } void MixerAudioSource::swapSource(const MixerAudioSource::SourceIterator &first, @@ -173,6 +172,11 @@ namespace talcs { return d->lastSource(); } + MixerAudioSource::SourceIterator MixerAudioSource::sourceAt(int index) const { + Q_D(const MixerAudioSource); + return d->sourceAt(index); + } + MixerAudioSource::SourceIterator MixerAudioSource::findSource(AudioSource *src) const { Q_D(const MixerAudioSource); return d->findSource(src); diff --git a/src/core/source/MixerAudioSource.h b/src/core/source/MixerAudioSource.h index 68f5c79..325b742 100644 --- a/src/core/source/MixerAudioSource.h +++ b/src/core/source/MixerAudioSource.h @@ -48,12 +48,13 @@ namespace talcs { void eraseSource(const SourceIterator &srcIt) override; void removeAllSources() override; - void moveSource(const SourceIterator &pos, const SourceIterator &target) override; + void moveSource(const SourceIterator &pos, const SourceIterator &first, const SourceIterator &last) override; void swapSource(const SourceIterator &first, const SourceIterator &second) override; QList sources() const override; SourceIterator firstSource() const override; SourceIterator lastSource() const override; + SourceIterator sourceAt(int index) const override; SourceIterator findSource(AudioSource *src) const override; SourceIterator nullIterator() const override; diff --git a/src/core/source/PositionableMixerAudioSource.cpp b/src/core/source/PositionableMixerAudioSource.cpp index aeb78ce..5eb304b 100644 --- a/src/core/source/PositionableMixerAudioSource.cpp +++ b/src/core/source/PositionableMixerAudioSource.cpp @@ -184,11 +184,10 @@ namespace talcs { d->removeAllSources(); } - void PositionableMixerAudioSource::moveSource(const PositionableMixerAudioSource::SourceIterator &pos, - const PositionableMixerAudioSource::SourceIterator &target) { + void PositionableMixerAudioSource::moveSource(const PositionableMixerAudioSource::SourceIterator &pos, const SourceIterator &first, const SourceIterator &last) { Q_D(PositionableMixerAudioSource); QMutexLocker locker(&d->mutex); - d->moveSource(pos, target); + d->moveSource(pos, first, last); } void PositionableMixerAudioSource::swapSource(const PositionableMixerAudioSource::SourceIterator &first, @@ -213,6 +212,11 @@ namespace talcs { return d->lastSource(); } + PositionableMixerAudioSource::SourceIterator PositionableMixerAudioSource::sourceAt(int index) const { + Q_D(const PositionableMixerAudioSource); + return d->sourceAt(index); + } + PositionableMixerAudioSource::SourceIterator PositionableMixerAudioSource::findSource(PositionableAudioSource *src) const { Q_D(const PositionableMixerAudioSource); diff --git a/src/core/source/PositionableMixerAudioSource.h b/src/core/source/PositionableMixerAudioSource.h index 745c5b7..c8bc01e 100644 --- a/src/core/source/PositionableMixerAudioSource.h +++ b/src/core/source/PositionableMixerAudioSource.h @@ -50,12 +50,13 @@ namespace talcs { void eraseSource(const SourceIterator &srcIt) override; void removeAllSources() override; - void moveSource(const SourceIterator &pos, const SourceIterator &target) override; + void moveSource(const SourceIterator &pos, const SourceIterator &first, const SourceIterator &last) override; void swapSource(const SourceIterator &first, const SourceIterator &second) override; QList sources() const override; SourceIterator firstSource() const override; SourceIterator lastSource() const override; + SourceIterator sourceAt(int index) const override; SourceIterator findSource(PositionableAudioSource *src) const override; SourceIterator nullIterator() const override; diff --git a/tests/UnitTests/IMixer/test.cpp b/tests/UnitTests/IMixer/test.cpp index d9f8c79..22a1d73 100644 --- a/tests/UnitTests/IMixer/test.cpp +++ b/tests/UnitTests/IMixer/test.cpp @@ -225,7 +225,7 @@ private slots: QCOMPARE(mixer.lastSource(), itList[3]); QCOMPARE(mixer.findSource(src + 2), itList[2]); - mixer.moveSource(itList[1], itList[3]); + mixer.moveSource(itList[1], itList[3], mixer.nullIterator()); QList expectedSrcList = {src, src + 3, src + 1, src + 2}; QCOMPARE(mixer.sources(), expectedSrcList);