mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2026-03-25 08:52:47 +01:00
Add some more "is audio disabled" checks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ocelot.desktop.audio
|
||||
|
||||
import ocelot.desktop.Settings
|
||||
import ocelot.desktop.ui.UiHandler
|
||||
import ocelot.desktop.util.{Logging, Resource, ResourceManager}
|
||||
import org.lwjgl.openal.AL10
|
||||
|
||||
@@ -10,15 +11,17 @@ class SoundSource(soundBuffer: SoundBuffer, looping: Boolean = false) extends Re
|
||||
ResourceManager.registerResource(this)
|
||||
|
||||
override def initResource(): Unit = {
|
||||
if (soundBuffer.getBufferId != -1) {
|
||||
sourceId = AL10.alGenSources()
|
||||
AL10.alSourcei(sourceId, AL10.AL_BUFFER, soundBuffer.getBufferId)
|
||||
AL10.alSourcef(sourceId, AL10.AL_PITCH, 1f)
|
||||
AL10.alSourcef(sourceId, AL10.AL_GAIN, Settings.get.volumeEnvironment * Settings.get.volumeMaster)
|
||||
AL10.alSource3f(sourceId, AL10.AL_POSITION, 0f, 0f, 0f)
|
||||
AL10.alSourcei(sourceId, AL10.AL_LOOPING, if (looping) AL10.AL_TRUE else AL10.AL_FALSE)
|
||||
} else {
|
||||
logger.error("Unable to create sound source: sound buffer is missing!")
|
||||
if (!UiHandler.audioDisabled) {
|
||||
if (soundBuffer.getBufferId != -1) {
|
||||
sourceId = AL10.alGenSources()
|
||||
AL10.alSourcei(sourceId, AL10.AL_BUFFER, soundBuffer.getBufferId)
|
||||
AL10.alSourcef(sourceId, AL10.AL_PITCH, 1f)
|
||||
AL10.alSourcef(sourceId, AL10.AL_GAIN, Settings.get.volumeEnvironment * Settings.get.volumeMaster)
|
||||
AL10.alSource3f(sourceId, AL10.AL_POSITION, 0f, 0f, 0f)
|
||||
AL10.alSourcei(sourceId, AL10.AL_LOOPING, if (looping) AL10.AL_TRUE else AL10.AL_FALSE)
|
||||
} else {
|
||||
logger.error("Unable to create sound source: sound buffer is missing!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +32,9 @@ class SoundSource(soundBuffer: SoundBuffer, looping: Boolean = false) extends Re
|
||||
def isPaused: Boolean = getStatus == AL10.AL_PAUSED
|
||||
def isStopped: Boolean = getStatus == AL10.AL_STOPPED
|
||||
|
||||
def play(): Unit = if (!isPlaying) AL10.alSourcePlay(sourceId)
|
||||
def pause(): Unit = if (isPlaying) AL10.alSourcePause(sourceId)
|
||||
def stop(): Unit = if (isPlaying || isPaused) AL10.alSourceStop(sourceId)
|
||||
def play(): Unit = if (!UiHandler.audioDisabled && !isPlaying) AL10.alSourcePlay(sourceId)
|
||||
def pause(): Unit = if (!UiHandler.audioDisabled && isPlaying) AL10.alSourcePause(sourceId)
|
||||
def stop(): Unit = if (!UiHandler.audioDisabled && isPlaying || isPaused) AL10.alSourceStop(sourceId)
|
||||
|
||||
def setVolume(value: Float): Unit = {
|
||||
if (sourceId != -1) {
|
||||
|
||||
Reference in New Issue
Block a user