package net.halbear.Terrain4J.EngineCore.Audio;

import org.joml.Vector3f;

import static org.lwjgl.openal.AL10.*;

public class AudioSource {
    private final int SourceID;
    public AudioSource(boolean loop, boolean relative){
        this.SourceID = alGenSources();
        alSourcei(SourceID, AL_LOOPING, loop ? AL_TRUE: AL_FALSE);
        alSourcei(SourceID, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
    }

    public void CleanUp(){
        Stop();
        alDeleteSources(SourceID);
    }
    public void SetBuffer(int Buffer){
        Stop();
        alSourcei(SourceID, AL_BUFFER, Buffer);
    }
    public boolean isPlaying(){return alGetSourcei(SourceID, AL_SOURCE_STATE) == AL_PLAYING;}
    public void Pause(){alSourcePause(SourceID);}
    public void Play(){alSourcePlay(SourceID);}
    public void SetGain(float gain){alSourcef(SourceID, AL_GAIN, gain);}
    public void SetPosition(Vector3f position){alSource3f(SourceID, AL_POSITION, position.x,position.y,position.z);}
    public void Stop(){alSourceStop(SourceID);}
}
