Skip to content

Commit

Permalink
update classes in talcs::Core
Browse files Browse the repository at this point in the history
  • Loading branch information
CrSjimo committed Jul 20, 2024
1 parent 203da15 commit 1454fb2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/core/base/IMixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T *> 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;
Expand Down
11 changes: 9 additions & 2 deletions src/core/base/IMixer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions src/core/source/MixerAudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/core/source/MixerAudioSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioSource *> 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;
Expand Down
10 changes: 7 additions & 3 deletions src/core/source/PositionableMixerAudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/core/source/PositionableMixerAudioSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PositionableAudioSource *> 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;
Expand Down
2 changes: 1 addition & 1 deletion tests/UnitTests/IMixer/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PositionableAudioSource *> expectedSrcList = {src, src + 3, src + 1, src + 2};
QCOMPARE(mixer.sources(), expectedSrcList);

Expand Down

0 comments on commit 1454fb2

Please sign in to comment.