mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
who knew playing around the music player can be so hard
This commit is contained in:
@@ -351,7 +351,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
App.audioMixer.musicTrack,
|
App.audioMixer.musicTrack,
|
||||||
AudioMixer.DEFAULT_FADEOUT_LEN / 3f
|
AudioMixer.DEFAULT_FADEOUT_LEN / 3f
|
||||||
) {
|
) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
ingame.musicGovernor.startMusic(this) // required for "intermittent" mode
|
||||||
iHitTheStopButton = false
|
iHitTheStopButton = false
|
||||||
stopRequested = false
|
stopRequested = false
|
||||||
}
|
}
|
||||||
@@ -376,12 +376,12 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
val thisMusic = App.audioMixer.musicTrack.currentTrack
|
val thisMusic = App.audioMixer.musicTrack.currentTrack
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f)
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f)
|
||||||
App.audioMixer.musicTrack.nextTrack = null
|
App.audioMixer.musicTrack.nextTrack = null
|
||||||
ingame.musicGovernor.stopMusic()
|
ingame.musicGovernor.stopMusic(this)
|
||||||
thisMusic?.let { ingame.musicGovernor.queueMusicToPlayNext(it) }
|
thisMusic?.let { ingame.musicGovernor.queueMusicToPlayNext(it) }
|
||||||
iHitTheStopButton = true
|
iHitTheStopButton = true
|
||||||
}
|
}
|
||||||
else if (!shouldPlayerBeDisabled) {
|
else if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic()
|
ingame.musicGovernor.startMusic(this)
|
||||||
iHitTheStopButton = false
|
iHitTheStopButton = false
|
||||||
stopRequested = false
|
stopRequested = false
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
App.audioMixer.musicTrack,
|
App.audioMixer.musicTrack,
|
||||||
AudioMixer.DEFAULT_FADEOUT_LEN / 3f
|
AudioMixer.DEFAULT_FADEOUT_LEN / 3f
|
||||||
) {
|
) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode, does seemingly nothing on "continuous" mode
|
ingame.musicGovernor.startMusic(this) // required for "intermittent" mode, does seemingly nothing on "continuous" mode
|
||||||
iHitTheStopButton = false
|
iHitTheStopButton = false
|
||||||
stopRequested = false
|
stopRequested = false
|
||||||
}
|
}
|
||||||
@@ -448,7 +448,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
// fade out
|
// fade out
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
||||||
if (!shouldPlayerBeDisabled) {
|
if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
ingame.musicGovernor.startMusic(this) // required for "intermittent" mode
|
||||||
iHitTheStopButton = false
|
iHitTheStopButton = false
|
||||||
stopRequested = false
|
stopRequested = false
|
||||||
}
|
}
|
||||||
@@ -469,7 +469,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
||||||
loadNewAlbum(albumsList[index])
|
loadNewAlbum(albumsList[index])
|
||||||
if (!shouldPlayerBeDisabled) {
|
if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
ingame.musicGovernor.startMusic(this) // required for "intermittent" mode
|
||||||
iHitTheStopButton = false
|
iHitTheStopButton = false
|
||||||
stopRequested = false
|
stopRequested = false
|
||||||
}
|
}
|
||||||
@@ -490,12 +490,12 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
if (shouldPlayerBeDisabled || iHitTheStopButton) {
|
if (shouldPlayerBeDisabled || iHitTheStopButton) {
|
||||||
if (!stopRequested) {
|
if (!stopRequested) {
|
||||||
stopRequested = true
|
stopRequested = true
|
||||||
ingame.musicGovernor.stopMusic()
|
ingame.musicGovernor.stopMusic(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!jukeboxStopMonitorAlert && !App.audioMixer.musicTrack.isPlaying) {
|
else if (ingame.musicGovernor.playCaller is PlaysMusic && !jukeboxStopMonitorAlert && !App.audioMixer.musicTrack.isPlaying) {
|
||||||
jukeboxStopMonitorAlert = true
|
jukeboxStopMonitorAlert = true
|
||||||
ingame.musicGovernor.stopMusic(false, ingame.musicGovernor.getRandomMusicInterval())
|
ingame.musicGovernor.stopMusic(this, false, ingame.musicGovernor.getRandomMusicInterval())
|
||||||
}
|
}
|
||||||
else if (App.audioMixer.musicTrack.isPlaying) {
|
else if (App.audioMixer.musicTrack.isPlaying) {
|
||||||
jukeboxStopMonitorAlert = false
|
jukeboxStopMonitorAlert = false
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ $BULLET Foleys:
|
|||||||
- ambient/season/diurnal_summer.*.ogg
|
- ambient/season/diurnal_summer.*.ogg
|
||||||
- ambient/season/diurnal_winter.*.ogg
|
- ambient/season/diurnal_winter.*.ogg
|
||||||
- ambient/season/matutinal.*.ogg
|
- ambient/season/matutinal.*.ogg
|
||||||
- ambient/season/nocturnal_summer.*.ogg
|
- ambient/season/nocturnal.*.ogg
|
||||||
|
|
||||||
Copyright (C) 2011, 2013, 2015, 2020, 2021 Klankbeeld
|
Copyright (C) 2011, 2013, 2015, 2020, 2021 Klankbeeld
|
||||||
Sound from <https://www.freesound.org/people/klankbeeld>
|
Sound from <https://www.freesound.org/people/klankbeeld>
|
||||||
@@ -305,7 +305,7 @@ Sound from <https://freesound.org/people/veezay>
|
|||||||
Copyright (C) 2017 Stephen Holdaway
|
Copyright (C) 2017 Stephen Holdaway
|
||||||
Sound from <https://freesound.org/people/stecman>
|
Sound from <https://freesound.org/people/stecman>
|
||||||
|
|
||||||
- effects/static/tape_hiss.ogg
|
- effects/static/film_pops_lowpass.ogg
|
||||||
|
|
||||||
Copyright (C) 2015 Joe DeShon
|
Copyright (C) 2015 Joe DeShon
|
||||||
Sound from <https://freesound.org/people/joedeshon>
|
Sound from <https://freesound.org/people/joedeshon>
|
||||||
|
|||||||
@@ -183,7 +183,10 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
|
|
||||||
printdbg(this, "MusicTitle: ${muscon.name}")
|
printdbg(this, "MusicTitle: ${muscon.name}")
|
||||||
|
|
||||||
muscon.songFinishedHook = { stopMusic(muscon) }
|
muscon.songFinishedHook = {
|
||||||
|
if (it == App.audioMixer.musicTrack.currentTrack?.gdxMusic)
|
||||||
|
stopMusic(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e: GdxRuntimeException) {
|
catch (e: GdxRuntimeException) {
|
||||||
@@ -205,7 +208,7 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
fun queueDirectory(musicDir: String, shuffled: Boolean, diskJockeyingMode: String, fileToName: ((String) -> String)? = null) {
|
fun queueDirectory(musicDir: String, shuffled: Boolean, diskJockeyingMode: String, fileToName: ((String) -> String)? = null) {
|
||||||
if (musicState != STATE_INIT && musicState != STATE_INTERMISSION) {
|
if (musicState != STATE_INIT && musicState != STATE_INTERMISSION) {
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.fadeBus, AudioMixer.DEFAULT_FADEOUT_LEN) // explicit call for fade-out when the game instance quits
|
App.audioMixer.requestFadeOut(App.audioMixer.fadeBus, AudioMixer.DEFAULT_FADEOUT_LEN) // explicit call for fade-out when the game instance quits
|
||||||
stopMusic(App.audioMixer.musicTrack.currentTrack)
|
stopMusic0(App.audioMixer.musicTrack.currentTrack)
|
||||||
}
|
}
|
||||||
|
|
||||||
songs.forEach { it.gdxMusic.tryDispose() }
|
songs.forEach { it.gdxMusic.tryDispose() }
|
||||||
@@ -326,11 +329,16 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
|
|
||||||
fun getRandomMusicInterval() = 25f + Math.random().toFloat() * 10f
|
fun getRandomMusicInterval() = 25f + Math.random().toFloat() * 10f
|
||||||
|
|
||||||
private fun stopMusic(song: MusicContainer?, callStopMusicHook: Boolean = true, customPauseLen: Float? = null) {
|
var stopCaller: Any? = null; private set
|
||||||
musicState = STATE_INTERMISSION
|
var playCaller: Any? = null; private set
|
||||||
|
var stopCallTime: Long? = null; private set
|
||||||
|
|
||||||
|
private fun stopMusic0(song: MusicContainer?, callStopMusicHook: Boolean = true, customPauseLen: Float? = null) {
|
||||||
|
musicState = if (customPauseLen == Float.POSITIVE_INFINITY) STATE_INIT else STATE_INTERMISSION
|
||||||
|
// printdbg(this, "stopMusic1 customLen=$customPauseLen, stateNow: $musicState, called by")
|
||||||
|
// printStackTrace(this)
|
||||||
intermissionAkku = 0f
|
intermissionAkku = 0f
|
||||||
intermissionLength = customPauseLen ?:
|
intermissionLength = customPauseLen ?: getRandomMusicInterval()
|
||||||
if (diskJockeyingMode == "intermittent") getRandomMusicInterval() else Float.POSITIVE_INFINITY // 30s-60s
|
|
||||||
musicFired = false
|
musicFired = false
|
||||||
if (callStopMusicHook && musicStopHooks.isNotEmpty()) musicStopHooks.forEach {
|
if (callStopMusicHook && musicStopHooks.isNotEmpty()) musicStopHooks.forEach {
|
||||||
if (song != null) {
|
if (song != null) {
|
||||||
@@ -340,19 +348,42 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
// printdbg(this, "StopMusic Intermission: $intermissionLength seconds")
|
// printdbg(this, "StopMusic Intermission: $intermissionLength seconds")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopMusic(callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
|
fun stopMusic(caller: Any?, callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
|
||||||
stopMusic(App.audioMixer.musicTrack.currentTrack, callStopMusicHook, pauseLen)
|
val timeNow = System.currentTimeMillis()
|
||||||
// printdbg(this, "StopMusic Intermission2: $pauseLen seconds, called by:")
|
val trackThis = App.audioMixer.musicTrack.currentTrack
|
||||||
|
|
||||||
|
if (caller is TerrarumMusicGovernor) {
|
||||||
|
if (stopCaller == null) {
|
||||||
|
// printdbg(this, "Caller: this, prev caller: $stopCaller, len: $pauseLen, obliging stop request")
|
||||||
|
stopMusic0(trackThis, callStopMusicHook, pauseLen)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// printdbg(this, "Caller: this, prev caller: $stopCaller, len: $pauseLen, ignoring stop request")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// printdbg(this, "Caller: $caller, prev caller: <doesn't matter>, len: $pauseLen, obliging stop request")
|
||||||
|
stopMusic0(trackThis, callStopMusicHook, pauseLen)
|
||||||
|
}
|
||||||
|
|
||||||
|
stopCaller = caller?.javaClass?.canonicalName
|
||||||
|
stopCallTime = System.currentTimeMillis()
|
||||||
|
|
||||||
// printStackTrace(this)
|
// printStackTrace(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startMusic() {
|
fun startMusic(caller: Any?) {
|
||||||
startMusic(pullNextMusicTrack())
|
playCaller = caller
|
||||||
|
startMusic0(pullNextMusicTrack())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startMusic(song: MusicContainer) {
|
private fun startMusic0(song: MusicContainer) {
|
||||||
|
stopCaller = null
|
||||||
|
stopCallTime = null
|
||||||
|
|
||||||
App.audioMixer.startMusic(song)
|
App.audioMixer.startMusic(song)
|
||||||
printdbg(this, "startMusic Now playing: ${song.name}")
|
// printdbg(this, "startMusic Now playing: ${song.name}, called by:")
|
||||||
|
// printStackTrace(this)
|
||||||
// INGAME.sendNotification("Now Playing $EMDASH ${song.name}")
|
// INGAME.sendNotification("Now Playing $EMDASH ${song.name}")
|
||||||
if (musicStartHooks.isNotEmpty()) musicStartHooks.forEach { it(song) }
|
if (musicStartHooks.isNotEmpty()) musicStartHooks.forEach { it(song) }
|
||||||
musicState = STATE_PLAYING
|
musicState = STATE_PLAYING
|
||||||
@@ -405,18 +436,30 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
ambState = STATE_PLAYING
|
ambState = STATE_PLAYING
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var firstTime = true
|
||||||
|
|
||||||
override fun update(ingame: IngameInstance, delta: Float) {
|
override fun update(ingame: IngameInstance, delta: Float) {
|
||||||
|
val timeNow = System.currentTimeMillis()
|
||||||
|
val callerRecordExpired = (timeNow - (stopCallTime ?: 0L) > 1000)
|
||||||
|
|
||||||
|
if (callerRecordExpired && stopCaller != null) {
|
||||||
|
stopCaller = null
|
||||||
|
stopCallTime = null
|
||||||
|
}
|
||||||
|
|
||||||
// start the song queueing if there is one to play
|
// start the song queueing if there is one to play
|
||||||
if (songs.isNotEmpty() && musicState == 0) musicState = STATE_INTERMISSION
|
if (firstTime) {
|
||||||
if (ambients.isNotEmpty() && ambState == 0) ambState = STATE_INTERMISSION
|
firstTime = false
|
||||||
|
if (songs.isNotEmpty()) musicState = STATE_INTERMISSION
|
||||||
|
if (ambients.isNotEmpty()) ambState = STATE_INTERMISSION
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
when (musicState) {
|
when (musicState) {
|
||||||
STATE_FIREPLAY -> {
|
STATE_FIREPLAY -> {
|
||||||
if (!musicFired) {
|
if (!musicFired) {
|
||||||
musicFired = true
|
musicFired = true
|
||||||
startMusic(pullNextMusicTrack())
|
startMusic0(pullNextMusicTrack())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATE_PLAYING -> {
|
STATE_PLAYING -> {
|
||||||
@@ -540,7 +583,7 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.fadeBus, AudioMixer.DEFAULT_FADEOUT_LEN) // explicit call for fade-out when the game instance quits
|
App.audioMixer.requestFadeOut(App.audioMixer.fadeBus, AudioMixer.DEFAULT_FADEOUT_LEN) // explicit call for fade-out when the game instance quits
|
||||||
stopMusic(App.audioMixer.musicTrack.currentTrack)
|
stopMusic0(App.audioMixer.musicTrack.currentTrack)
|
||||||
stopAmbient()
|
stopAmbient()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
|||||||
|
|
||||||
printdbg(this, "Stop music $title - $artist")
|
printdbg(this, "Stop music $title - $artist")
|
||||||
|
|
||||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = (INGAME.musicGovernor as TerrarumMusicGovernor).getRandomMusicInterval())
|
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(this, pauseLen = (INGAME.musicGovernor as TerrarumMusicGovernor).getRandomMusicInterval())
|
||||||
}
|
}
|
||||||
|
|
||||||
discCurrentlyPlaying = index
|
discCurrentlyPlaying = index
|
||||||
@@ -141,7 +141,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
|||||||
*/
|
*/
|
||||||
fun stopGracefully() {
|
fun stopGracefully() {
|
||||||
stopDiscPlayback()
|
stopDiscPlayback()
|
||||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = (INGAME.musicGovernor as TerrarumMusicGovernor).getRandomMusicInterval())
|
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(this, pauseLen = (INGAME.musicGovernor as TerrarumMusicGovernor).getRandomMusicInterval())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
||||||
|
|||||||
Reference in New Issue
Block a user