-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.kt
93 lines (80 loc) · 3.4 KB
/
Application.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package application
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toAwtImage
import androidx.compose.ui.res.loadSvgPainter
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.singleWindowApplication
import com.github.numq.klarity.core.loader.Klarity
import decoration.DecorationBox
import navigation.Navigation
import theme.KlarityTheme
import java.awt.Dimension
import java.awt.FileDialog
import java.io.File
import java.nio.file.Paths
import kotlin.system.exitProcess
fun main() {
val appName = "Klarity"
val decoderPath = Paths.get("example\\bin\\decoder").toAbsolutePath().toString()
Klarity.loadDecoder(
ffmpegPath = "$decoderPath\\ffmpeg", klarityPath = "$decoderPath\\klarity", jniPath = "$decoderPath\\jni"
).getOrThrow()
val samplerPath = Paths.get("example\\bin\\sampler").toAbsolutePath().toString()
Klarity.loadSampler(
portAudioPath = "$samplerPath\\portaudio", klarityPath = "$samplerPath\\klarity", jniPath = "$samplerPath\\jni"
).getOrThrow()
val windowState = WindowState(position = WindowPosition(Alignment.Center), size = DpSize(700.dp, 700.dp))
singleWindowApplication(state = windowState, undecorated = true) {
val iconSvg = remember {
File("media/logo.svg").inputStream().use {
loadSvgPainter(it, Density(1f))
}
}
SideEffect {
window.iconImage = iconSvg.toAwtImage(Density(1f), LayoutDirection.Ltr)
window.minimumSize = Dimension(700, 700)
}
val isSystemInDarkTheme = isSystemInDarkTheme()
val (isDarkTheme, setIsDarkTheme) = remember(isSystemInDarkTheme) {
mutableStateOf(isSystemInDarkTheme)
}
KlarityTheme(isDarkTheme = isDarkTheme) {
Column(
modifier = Modifier.fillMaxSize().background(MaterialTheme.colors.background),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceBetween
) {
DecorationBox(window = window,
isDarkTheme = isDarkTheme,
changeTheme = setIsDarkTheme,
close = { exitProcess(0) }) {
Box(modifier = Modifier.padding(4.dp), contentAlignment = Alignment.Center) {
Image(iconSvg, "icon")
}
Text(appName, color = MaterialTheme.colors.primary)
}
Navigation(openFileChooser = {
FileDialog(window, "Upload media", FileDialog.LOAD).apply {
isMultipleMode = true
isVisible = true
}.files.toList()
})
}
}
}
}