MusicController

class MusicController

Play, choose, fade-in/out and generally manage music track playback.

Main methods: chooseTrack, pause, resume, setModList, isPlaying, gracefulShutdown

Constructors

MusicController
Link copied to clipboard
fun MusicController()

Types

Companion
Link copied to clipboard
object Companion
ControllerState
Link copied to clipboard
private enum ControllerState : Enum<MusicController.ControllerState>

Functions

chooseFile
Link copied to clipboard
private fun chooseFile(prefix: String, suffix: String, flags: EnumSet<MusicTrackChooserFlags>): FileHandle?

Choose adequate entry from getAllMusicFiles

chooseTrack
Link copied to clipboard
fun chooseTrack(prefix: String = "", suffix: String = "Ambient", flags: EnumSet<MusicTrackChooserFlags> = EnumSet.noneOf(MusicTrackChooserFlags::class.java)): Boolean

Chooses and plays a music track using an adaptable approach - for details see the wiki. Called without parameters it will choose a new ambient music track and start playing it with fade-in/out. Will do nothing when no music files exist or the master volume is zero.

fun chooseTrack(prefix: String = "", suffixes: List<String>, flags: EnumSet<MusicTrackChooserFlags> = EnumSet.noneOf(MusicTrackChooserFlags::class.java)): Boolean

Variant of chooseTrack that tries several moods (suffixes) until a match is chosen

clearCurrent
Link copied to clipboard
private fun clearCurrent()
currentlyPlaying
Link copied to clipboard
private fun currentlyPlaying(): String
downloadDefaultFile
Link copied to clipboard
fun downloadDefaultFile()
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
fadeoutToSilence
Link copied to clipboard
fun fadeoutToSilence(duration: Float = 4.0f)

Fade out then shutdown with a given duration in seconds

fireOnChange
Link copied to clipboard
private fun fireOnChange()
private fun fireOnChange(trackLabel: String)
getAllMusicFiles
Link copied to clipboard
private fun getAllMusicFiles(): Sequence<FileHandle>

Get sequence of all existing music files

getMusicFolders
Link copied to clipboard
private fun getMusicFolders(): Sequence<FileHandle>

Get sequence of potential music locations

gracefulShutdown
Link copied to clipboard
fun gracefulShutdown()

Soft shutdown of music playback, with fadeout

hashCode
Link copied to clipboard
open fun hashCode(): Int
isMusicAvailable
Link copied to clipboard
fun isMusicAvailable(): Boolean

Determines whether any music tracks are available for the options menu

isPlaying
Link copied to clipboard
fun isPlaying(): Boolean
musicTimerTask
Link copied to clipboard
private fun musicTimerTask()
onChange
Link copied to clipboard
fun onChange(listener: (String) -> Unit?)

Registers a callback that will be called with the new track name every time it changes. The track name will be prettified ("Modname: Track" instead of "mods/Modname/music/Track.ogg").

pause
Link copied to clipboard
fun pause(speedFactor: Float = 1f)

Pause playback with fade-out

resume
Link copied to clipboard
fun resume(speedFactor: Float = 1f)

Resume playback with fade-in - from a pause will resume where playback left off, otherwise it will start a new ambient track choice.

setModList
Link copied to clipboard
fun setModList(newMods: HashSet<String>)

This tells the music controller about active mods - all are allowed to provide tracks

setVolume
Link copied to clipboard
fun setVolume(volume: Float)

Update playback volume, to be called from options popup

shutdown
Link copied to clipboard
private fun shutdown()

Forceful shutdown of music playback and timers - see gracefulShutdown

toString
Link copied to clipboard
open fun toString(): String

Properties

baseVolume
Link copied to clipboard
var baseVolume: Float

mirrors GameSettings.musicVolume - use setVolume to update

current
Link copied to clipboard
var current: MusicTrackController? = null

Simple two-entry only queue, for smooth fade-overs from one track to another

mods
Link copied to clipboard
private var mods: HashSet<String>
musicHistory
Link copied to clipboard
private val musicHistory: ArrayDeque<String>

Keeps paths of recently played track to reduce repetition

musicTimer
Link copied to clipboard
private var musicTimer: Timer? = null
next
Link copied to clipboard
var next: MusicTrackController? = null
onTrackChangeListener
Link copied to clipboard
private var onTrackChangeListener: (String) -> Unit? = null

One potential listener gets notified when track changes

silenceLength
Link copied to clipboard
var silenceLength: Float

Pause in seconds between tracks unless chooseTrack is called to force a track change

silenceLengthInTicks
Link copied to clipboard
private var silenceLengthInTicks: Int
state
Link copied to clipboard
private var state: MusicController.ControllerState
ticksOfSilence
Link copied to clipboard
private var ticksOfSilence: Int = 0

Sources

jvm source
Link copied to clipboard