summaryrefslogtreecommitdiffstats
path: root/src/sources/audiosourceproxy.h
blob: 22f78b3cb8a9acfaf8c04b8230f16ec070da41e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include "sources/audiosource.h"

namespace mixxx {

class AudioSourceProxy : public AudioSource {
  public:
    explicit AudioSourceProxy(
            AudioSourcePointer&& pAudioSource)
            : AudioSourceProxy(
                  std::move(pAudioSource),
                  pAudioSource->getSignalInfo()) {
    }
    AudioSourceProxy(
            AudioSourcePointer&& pAudioSource,
            const audio::SignalInfo& signalInfo)
            : AudioSource(*pAudioSource, signalInfo),
              m_pAudioSource(std::move(pAudioSource)) {
    }

    void close() override {
        m_pAudioSource->close();
    }

  protected:
    OpenResult tryOpen(
            OpenMode mode,
            const OpenParams& params) override {
        return tryOpenOn(*m_pAudioSource, mode, params);
    }

    ReadableSampleFrames readSampleFramesClamped(
            const WritableSampleFrames& sampleFrames) override {
        DEBUG_ASSERT(getSignalInfo() == m_pAudioSource->getSignalInfo());
        DEBUG_ASSERT(getBitrate() == m_pAudioSource->getBitrate());
        DEBUG_ASSERT(frameIndexRange() == m_pAudioSource->frameIndexRange());
        return readSampleFramesClampedOn(*m_pAudioSource, sampleFrames);
    }

    void adjustFrameIndexRange(
            IndexRange frameIndexRange) final {
        // Ugly hack to keep both sources (inherited base + inner delegate) in sync!
        AudioSource::adjustFrameIndexRange(frameIndexRange);
        adjustFrameIndexRangeOn(*m_pAudioSource, frameIndexRange);
    }

    const AudioSourcePointer m_pAudioSource;
};

} // namespace mixxx