commit 29/01/2026
This commit is contained in:
71
src/Main.kt
71
src/Main.kt
@@ -1,4 +1,5 @@
|
||||
import audio.AudioPlayer
|
||||
|
||||
import audio.ContentCache
|
||||
import audio.TCPReceiver
|
||||
import audio.UDPReceiver
|
||||
@@ -7,6 +8,7 @@ import barix.TCP_Barix_Command_Server
|
||||
import codes.Somecodes
|
||||
import codes.configFile
|
||||
import codes.configKeys
|
||||
import com.sun.jna.Native
|
||||
import com.sun.jna.Platform
|
||||
import commandServer.TCP_Android_Command_Server
|
||||
import content.Category
|
||||
@@ -24,10 +26,12 @@ import org.tinylog.provider.ProviderRegistry
|
||||
import oshi.util.GlobalConfig
|
||||
import securedonglex.DongleChecker
|
||||
import web.WebApp
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import kotlin.concurrent.fixedRateTimer
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
lateinit var db: MariaDB
|
||||
@@ -35,7 +39,7 @@ lateinit var audioPlayer: AudioPlayer
|
||||
val StreamerOutputs: MutableMap<String, BarixConnection> = HashMap()
|
||||
lateinit var udpreceiver: UDPReceiver
|
||||
lateinit var tcpreceiver: TCPReceiver
|
||||
const val version = "0.0.17 (26/01/2026)"
|
||||
const val version = "0.0.23 (29/01/2026)"
|
||||
// AAS 64 channels
|
||||
const val max_channel = 64
|
||||
|
||||
@@ -73,45 +77,55 @@ fun folder_preparation(){
|
||||
|
||||
}
|
||||
|
||||
private fun Extract_Libraries() {
|
||||
// extract from source root folder to current user dir
|
||||
val libs = listOf("bass", "bassenc", "bassenc_mp3","bassenc_ogg","bassenc_opus","bassmix","bassopus","sdx")
|
||||
try{
|
||||
val targetfolder = File(Somecodes.current_directory)
|
||||
Logger.info {"target to extract libraries : $targetfolder"}
|
||||
libs.forEach { ff ->
|
||||
|
||||
val x = Native.extractFromResourcePath(ff)
|
||||
val y = System.mapLibraryName(ff)
|
||||
val z = x.copyTo(targetfolder.resolve(y),overwrite = true)
|
||||
Logger.info {"Extracted libraries : $z"}
|
||||
}
|
||||
} catch (e : Exception){
|
||||
Logger.error { "Error extracting libraries, msg : ${e.message}" }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract necessary wav files from classpath to soundbank directory
|
||||
* and Load them
|
||||
*/
|
||||
fun files_preparation(){
|
||||
val list = listOf("chimeup.wav", "chimedown.wav", "silence1s.wav", "silencehalf.wav")
|
||||
list.forEach {
|
||||
Somecodes.ExtractFilesFromClassPath("/$it", Somecodes.Soundbank_directory)
|
||||
val pp = Somecodes.Soundbank_directory.resolve(it)
|
||||
if (Files.isRegularFile(pp)){
|
||||
val afi = audioPlayer.LoadAudioFile(pp.absolutePathString())
|
||||
list.forEach { ff ->
|
||||
Somecodes.extractWav(ff)
|
||||
val fd = Somecodes.Soundbank_directory.resolve(ff)
|
||||
if (fd.exists()){
|
||||
Logger.info{"File ${fd.absolutePathString()} found, processing to content cache" }
|
||||
val afi = audioPlayer.LoadAudioFile(fd.absolutePathString())
|
||||
if (afi.isValid()){
|
||||
Logger.info { "Common audio $it loaded from ${pp.toAbsolutePath()}" }
|
||||
val key = it.substring(0, it.length - 4) // buang .wav
|
||||
contentCache.addAudioFile(key, afi)
|
||||
val key = Somecodes.FilenameWithoutExtension(fd.toFile())
|
||||
contentCache.addAudioFile(Somecodes.FilenameWithoutExtension(fd.toFile()), afi)
|
||||
Logger.info{"Loaded file ${fd.absolutePathString()} to content cache as $key" }
|
||||
} else {
|
||||
Logger.error { "Failed to load common audio $it from ${pp.toAbsolutePath()}" }
|
||||
Logger.error{"Failed to load file ${fd.absolutePathString()} to content cache" }
|
||||
}
|
||||
} else {
|
||||
Logger.error { "Common audio $it not found at ${pp.toAbsolutePath()}" }
|
||||
Logger.error{"File ${fd.absolutePathString()} not found after extraction" }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lateinit var config : configFile
|
||||
val sdx = DongleChecker()
|
||||
//val sdx = DongleChecker()
|
||||
// Application start here
|
||||
fun main() {
|
||||
if (!sdx.CheckDongle()){
|
||||
Logger.error { "Dongle check failed. Application will exit." }
|
||||
exitProcess(1)
|
||||
} else {
|
||||
sdx.startChecking {
|
||||
Logger.error { "Dongle removed. Application will exit." }
|
||||
exitProcess(1)
|
||||
sdx.stopChecking()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -124,6 +138,17 @@ fun main() {
|
||||
|
||||
config = configFile()
|
||||
folder_preparation()
|
||||
Extract_Libraries()
|
||||
|
||||
// if (!sdx.CheckDongle()){
|
||||
// Logger.error { "Dongle check failed. Application will exit." }
|
||||
// exitProcess(1)
|
||||
// } else {
|
||||
// sdx.startChecking {
|
||||
// Logger.error { "Dongle removed. Application will exit." }
|
||||
// exitProcess(1)
|
||||
// }
|
||||
// }
|
||||
|
||||
audioPlayer = AudioPlayer(44100) // 44100 Hz sampling rate
|
||||
audioPlayer.InitAudio(1)
|
||||
@@ -262,7 +287,7 @@ fun main() {
|
||||
StreamerOutputs.values.forEach { it.close() }
|
||||
audioPlayer.Close()
|
||||
db.close()
|
||||
sdx.stopChecking()
|
||||
//sdx.stopChecking()
|
||||
|
||||
Logger.info { "All services stopped, exiting application." }
|
||||
ProviderRegistry.getLoggingProvider().shutdown()
|
||||
|
||||
Reference in New Issue
Block a user