Skip to content

File Channel.h

File List > Amplitude > Core > Playback > Channel.h

Go to the documentation of this file

// Copyright (c) 2021-present Sparky Studios. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#ifndef _AM_CORE_PLAYBACK_CHANNEL_H
#define _AM_CORE_PLAYBACK_CHANNEL_H

#include <SparkyStudios/Audio/Amplitude/Core/Common.h>
#include <SparkyStudios/Audio/Amplitude/Core/Entity.h>
#include <SparkyStudios/Audio/Amplitude/Core/Listener.h>
#include <SparkyStudios/Audio/Amplitude/Core/Playback/ChannelEventListener.h>
#include <SparkyStudios/Audio/Amplitude/Core/Playback/ChannelInstance.h>
#include <SparkyStudios/Audio/Amplitude/Core/Room.h>

namespace SparkyStudios::Audio::Amplitude
{
    class ChannelInternalState;

    enum eChannelPlaybackState : AmUInt8
    {
        eChannelPlaybackState_Stopped = 0,

        eChannelPlaybackState_Playing = 1,

        eChannelPlaybackState_FadingIn = 2,

        eChannelPlaybackState_FadingOut = 3,

        eChannelPlaybackState_SwitchingState = 4,

        eChannelPlaybackState_Paused = 5,

        eChannelPlaybackState_Pending = 6,
    };

    enum eChannelEvent : AmUInt8
    {
        eChannelEvent_Begin = 0,

        eChannelEvent_End = 1,

        eChannelEvent_Resume = 2,

        eChannelEvent_Pause = 3,

        eChannelEvent_Stop = 4,

        eChannelEvent_Loop = 5
    };

    class AM_API_PUBLIC Channel
    {
    public:
        Channel();

        explicit Channel(ChannelInternalState* state);

        void Clear();

        [[nodiscard]] bool Valid() const;

        [[nodiscard]] AmChannelID GetId() const;

        [[nodiscard]] bool Playing() const;

        void Stop(AmTime duration = kMinFadeDuration) const;

        void Pause(AmTime duration = kMinFadeDuration) const;

        void Resume(AmTime duration = kMinFadeDuration) const;

        [[nodiscard]] const AmVector3& GetLocation() const;

        void SetLocation(const AmVector3& location) const;

        void SetGain(AmReal32 gain) const;

        [[nodiscard]] AmReal32 GetGain() const;

        [[nodiscard]] eChannelPlaybackState GetPlaybackState() const;

        [[nodiscard]] Entity GetEntity() const;

        [[nodiscard]] Listener GetListener() const;

        [[nodiscard]] Room GetRoom() const;

        [[nodiscard]] ChannelInternalState* GetState() const;

        void On(eChannelEvent event, ChannelEventCallback callback, void* userData = nullptr) const;

        void EnableInstancing(eChannelInstanceMode mode) const;

        void DisableInstancing() const;

        [[nodiscard]] bool IsInstancingEnabled() const;

        [[nodiscard]] eChannelInstanceMode GetInstancingMode() const;

        [[nodiscard]] ChannelInstance AddInstance(const AmVector3& location) const;

        void RemoveInstance(AmChannelInstanceID instanceId) const;

        void ClearInstances() const;

        [[nodiscard]] ChannelInstance GetInstance(AmChannelInstanceID instanceId) const;

        [[nodiscard]] AmSize GetInstanceCount() const;

    private:
        Channel(ChannelInternalState* state, AmUInt64 id);

        [[nodiscard]] bool IsValidStateId() const;

        ChannelInternalState* _state;

        AmUInt64 _stateId;
    };
} // namespace SparkyStudios::Audio::Amplitude

#endif // _AM_CORE_PLAYBACK_CHANNEL_H