2023-01-17 10:13:08 -08:00

68 lines
1.6 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnopenal.hpp"
#include "scene/SceneItemComponent.hpp"
#include "audio/AudioData.hpp"
namespace Dawn {
class AudioSource : public SceneItemComponent {
private:
ALuint source;
bool_t ready = false;
// Settings
bool_t loop = false;
bool_t playing = false;
int32_t layer = 0;
AudioData *data = nullptr;
void onTransformUpdate();
public:
/**
* Creates an Audio Source item component.
*
* @param item SceneItem that this audio source is attached to.
*/
AudioSource(SceneItem *item);
/**
* Returns whether or not the audio source is set to loop or not.
*
* @return True if the source is looping otherwise false.
*/
bool_t isLooping();
/**
* Sets whether the audio source should loop or not.
*
* @param loop Loop or not.
*/
void setLoop(bool_t loop);
bool_t isPlaying();
void play();
/**
* Returns the current audio data for this source.
*
* @return Audio data that is atached to this source.
*/
AudioData * getAudioData();
/**
* Sets the audio data for this source. Currently switching between the
* audio data during playback may have undefined behavior.
*
* @param data Data to set.
*/
void setAudioData(AudioData *data);
void onStart() override;
void onDispose() override;
};
}