mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +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,
|
||||
AudioMixer.DEFAULT_FADEOUT_LEN / 3f
|
||||
) {
|
||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
||||
ingame.musicGovernor.startMusic(this) // required for "intermittent" mode
|
||||
iHitTheStopButton = false
|
||||
stopRequested = false
|
||||
}
|
||||
@@ -376,12 +376,12 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
||||
val thisMusic = App.audioMixer.musicTrack.currentTrack
|
||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f)
|
||||
App.audioMixer.musicTrack.nextTrack = null
|
||||
ingame.musicGovernor.stopMusic()
|
||||
ingame.musicGovernor.stopMusic(this)
|
||||
thisMusic?.let { ingame.musicGovernor.queueMusicToPlayNext(it) }
|
||||
iHitTheStopButton = true
|
||||
}
|
||||
else if (!shouldPlayerBeDisabled) {
|
||||
ingame.musicGovernor.startMusic()
|
||||
ingame.musicGovernor.startMusic(this)
|
||||
iHitTheStopButton = false
|
||||
stopRequested = false
|
||||
}
|
||||
@@ -396,7 +396,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
||||
App.audioMixer.musicTrack,
|
||||
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
|
||||
stopRequested = false
|
||||
}
|
||||
@@ -448,7 +448,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
||||
// fade out
|
||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
||||
if (!shouldPlayerBeDisabled) {
|
||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
||||
ingame.musicGovernor.startMusic(this) // required for "intermittent" mode
|
||||
iHitTheStopButton = 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) {
|
||||
loadNewAlbum(albumsList[index])
|
||||
if (!shouldPlayerBeDisabled) {
|
||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
||||
ingame.musicGovernor.startMusic(this) // required for "intermittent" mode
|
||||
iHitTheStopButton = false
|
||||
stopRequested = false
|
||||
}
|
||||
@@ -490,12 +490,12 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
||||
if (shouldPlayerBeDisabled || iHitTheStopButton) {
|
||||
if (!stopRequested) {
|
||||
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
|
||||
ingame.musicGovernor.stopMusic(false, ingame.musicGovernor.getRandomMusicInterval())
|
||||
ingame.musicGovernor.stopMusic(this, false, ingame.musicGovernor.getRandomMusicInterval())
|
||||
}
|
||||
else if (App.audioMixer.musicTrack.isPlaying) {
|
||||
jukeboxStopMonitorAlert = false
|
||||
|
||||
@@ -279,7 +279,7 @@ $BULLET Foleys:
|
||||
- ambient/season/diurnal_summer.*.ogg
|
||||
- ambient/season/diurnal_winter.*.ogg
|
||||
- ambient/season/matutinal.*.ogg
|
||||
- ambient/season/nocturnal_summer.*.ogg
|
||||
- ambient/season/nocturnal.*.ogg
|
||||
|
||||
Copyright (C) 2011, 2013, 2015, 2020, 2021 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
|
||||
Sound from <https://freesound.org/people/stecman>
|
||||
|
||||
- effects/static/tape_hiss.ogg
|
||||
- effects/static/film_pops_lowpass.ogg
|
||||
|
||||
Copyright (C) 2015 Joe DeShon
|
||||
Sound from <https://freesound.org/people/joedeshon>
|
||||
|
||||
@@ -183,7 +183,10 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
|
||||
printdbg(this, "MusicTitle: ${muscon.name}")
|
||||
|
||||
muscon.songFinishedHook = { stopMusic(muscon) }
|
||||
muscon.songFinishedHook = {
|
||||
if (it == App.audioMixer.musicTrack.currentTrack?.gdxMusic)
|
||||
stopMusic(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e: GdxRuntimeException) {
|
||||
@@ -205,7 +208,7 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
fun queueDirectory(musicDir: String, shuffled: Boolean, diskJockeyingMode: String, fileToName: ((String) -> String)? = null) {
|
||||
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
|
||||
stopMusic(App.audioMixer.musicTrack.currentTrack)
|
||||
stopMusic0(App.audioMixer.musicTrack.currentTrack)
|
||||
}
|
||||
|
||||
songs.forEach { it.gdxMusic.tryDispose() }
|
||||
@@ -326,11 +329,16 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
|
||||
fun getRandomMusicInterval() = 25f + Math.random().toFloat() * 10f
|
||||
|
||||
private fun stopMusic(song: MusicContainer?, callStopMusicHook: Boolean = true, customPauseLen: Float? = null) {
|
||||
musicState = STATE_INTERMISSION
|
||||
var stopCaller: Any? = null; private set
|
||||
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
|
||||
intermissionLength = customPauseLen ?:
|
||||
if (diskJockeyingMode == "intermittent") getRandomMusicInterval() else Float.POSITIVE_INFINITY // 30s-60s
|
||||
intermissionLength = customPauseLen ?: getRandomMusicInterval()
|
||||
musicFired = false
|
||||
if (callStopMusicHook && musicStopHooks.isNotEmpty()) musicStopHooks.forEach {
|
||||
if (song != null) {
|
||||
@@ -340,19 +348,42 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
// printdbg(this, "StopMusic Intermission: $intermissionLength seconds")
|
||||
}
|
||||
|
||||
fun stopMusic(callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
|
||||
stopMusic(App.audioMixer.musicTrack.currentTrack, callStopMusicHook, pauseLen)
|
||||
// printdbg(this, "StopMusic Intermission2: $pauseLen seconds, called by:")
|
||||
fun stopMusic(caller: Any?, callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
|
||||
val timeNow = System.currentTimeMillis()
|
||||
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)
|
||||
}
|
||||
|
||||
fun startMusic() {
|
||||
startMusic(pullNextMusicTrack())
|
||||
fun startMusic(caller: Any?) {
|
||||
playCaller = caller
|
||||
startMusic0(pullNextMusicTrack())
|
||||
}
|
||||
|
||||
private fun startMusic(song: MusicContainer) {
|
||||
private fun startMusic0(song: MusicContainer) {
|
||||
stopCaller = null
|
||||
stopCallTime = null
|
||||
|
||||
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}")
|
||||
if (musicStartHooks.isNotEmpty()) musicStartHooks.forEach { it(song) }
|
||||
musicState = STATE_PLAYING
|
||||
@@ -405,18 +436,30 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
ambState = STATE_PLAYING
|
||||
}
|
||||
|
||||
var firstTime = true
|
||||
|
||||
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
|
||||
if (songs.isNotEmpty() && musicState == 0) musicState = STATE_INTERMISSION
|
||||
if (ambients.isNotEmpty() && ambState == 0) ambState = STATE_INTERMISSION
|
||||
if (firstTime) {
|
||||
firstTime = false
|
||||
if (songs.isNotEmpty()) musicState = STATE_INTERMISSION
|
||||
if (ambients.isNotEmpty()) ambState = STATE_INTERMISSION
|
||||
}
|
||||
|
||||
|
||||
when (musicState) {
|
||||
STATE_FIREPLAY -> {
|
||||
if (!musicFired) {
|
||||
musicFired = true
|
||||
startMusic(pullNextMusicTrack())
|
||||
startMusic0(pullNextMusicTrack())
|
||||
}
|
||||
}
|
||||
STATE_PLAYING -> {
|
||||
@@ -540,7 +583,7 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
|
||||
override fun dispose() {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
|
||||
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
|
||||
@@ -141,7 +141,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
*/
|
||||
fun stopGracefully() {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user