Skip to content

Commit

Permalink
Recon: NativeAudioPluginSettings Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Tryanks committed Dec 10, 2023
1 parent 45947cc commit c4fded9
Showing 1 changed file with 66 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package com.eimsound.dsp.native.processors

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.material.icons.filled.SettingsInputHdmi
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.eimsound.audioprocessor.NativeAudioPluginFactory
import com.eimsound.daw.components.AbsoluteElevation
import com.eimsound.daw.components.Gap
import com.eimsound.daw.components.SettingTab
import com.eimsound.daw.components.utils.clickableWithIcon
import com.eimsound.daw.utils.*
import com.eimsound.daw.components.SettingsListManager
import com.eimsound.daw.components.SettingsSection
import com.eimsound.daw.utils.CurrentWindow
import com.eimsound.daw.utils.openFolderBrowser
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.io.File
import javax.swing.JFileChooser
import javax.swing.filechooser.FileNameExtensionFilter

Expand Down Expand Up @@ -65,143 +70,63 @@ class NativeAudioPluginSettings: SettingTab {

@Composable
override fun content() {
Row(horizontalArrangement = Arrangement.spacedBy(20.dp)) {
AbsoluteElevation {
val window = CurrentWindow.current
val apm = NativeAudioPluginFactoryImpl.instance!!
Column(Modifier.width(300.dp)) {
Row {
Text(
text = "搜索路径",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(bottom = 8.dp).weight(1F),
)
IconButton(
onClick = {
openFolderBrowser(window) { file ->
if (file == null) return@openFolderBrowser
apm.scanPaths.add(file.absolutePath)
apm.saveAsync()
}
},
modifier = Modifier.clip(CircleShape).size(28.dp)
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "Add",
tint = MaterialTheme.colorScheme.outline
)
}
}
Card {
apm.scanPaths.forEach {
ListItem(
{ Text(it) },
Modifier.background(MaterialTheme.colorScheme.surface).clickableWithIcon {
if (apm.pluginIsFile) openInExplorer(File(it))
},
trailingContent = {
IconButton(
{
apm.scanPaths.remove(it)
apm.saveAsync()
},
modifier = Modifier.size(24.dp).weight(1F)
) {
Icon(Icons.Filled.Delete, contentDescription = "Delete")
}
}
)
Column {
val window = CurrentWindow.current
val apm = NativeAudioPluginFactoryImpl.instance!!

SettingsSection("搜索路径") {
SettingsListManager(
list = apm.scanPaths,
onAddButtonClick = {
openFolderBrowser(window) { file ->
if (file == null) return@openFolderBrowser
apm.scanPaths.add(file.absolutePath)
apm.saveAsync()
}
},
onDelete = {
apm.scanPaths.remove(it)
apm.saveAsync()
}
)
}

if (scanningJob != null) {
Gap(6)
Box {
Text(
text = "正在搜索... (${apm.scannedCount}/${apm.allScanCount})",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(bottom = 8.dp),
)
Gap(8)

SettingsSection("排除路径") {
SettingsListManager(
list = apm.skipList,
onAddButtonClick = {
val fileChooser = JFileChooser().apply {
isAcceptAllFileFilterUsed = false
fileFilter = FileNameExtensionFilter("Native Audio Plugin Format (${
apm.pluginExtensions.joinToString(", ") { ".$it" }
})", *apm.pluginExtensions.toTypedArray())
}
if (apm.allScanCount != 0) LinearProgressIndicator(
modifier = Modifier.padding(vertical = 4.dp).fillMaxWidth(),
progress = apm.scannedCount.toFloat() / apm.allScanCount,
)
Card {
apm.scanningPlugins.forEach { (k, v) ->
key(k) {
ListItem(
{ Text(k) },
Modifier.background(MaterialTheme.colorScheme.surface).clickableWithIcon {
if (apm.pluginIsFile) selectInExplorer(File(k))
},
trailingContent = {
IconButton(
{ v.destroy() },
modifier = Modifier.size(24.dp).weight(1F)
) {
Icon(Icons.Filled.Cancel, contentDescription = "Cancel")
}
}
)
}
}
fileChooser.showOpenDialog(window)
fileChooser.selectedFile?.let {
apm.skipList.add(it.absolutePath)
apm.saveAsync()
}
},
onDelete = {
apm.skipList.remove(it)
apm.saveAsync()
}
}
)
}

Column(Modifier.weight(1F)) {
Row {
Text(
text = "排除路径",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(bottom = 8.dp).weight(1F),
)
IconButton(
onClick = {
val fileChooser = JFileChooser().apply {
isAcceptAllFileFilterUsed = false
fileFilter = FileNameExtensionFilter("Native Audio Plugin Format (${
apm.pluginExtensions.joinToString(", ") { ".$it" }
})", *apm.pluginExtensions.toTypedArray())
}
fileChooser.showOpenDialog(window)
fileChooser.selectedFile?.let {
apm.skipList.add(it.absolutePath)
apm.saveAsync()
}
},
modifier = Modifier.clip(CircleShape).size(28.dp)
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "Add",
tint = MaterialTheme.colorScheme.outline
)
}
}
Card {
apm.skipList.forEach {
ListItem(
{ Text(it) },
Modifier.background(MaterialTheme.colorScheme.surface).clickableWithIcon {
if (apm.pluginIsFile) selectInExplorer(File(it))
},
trailingContent = {
IconButton(
{
apm.skipList.remove(it)
apm.saveAsync()
},
modifier = Modifier.size(24.dp).weight(1F)
) {
Icon(Icons.Filled.Delete, contentDescription = "Delete")
}
}
if (scanningJob != null) {
Gap(8)
SettingsSection("正在搜索... (${apm.scannedCount}/${apm.allScanCount})") {
if (apm.allScanCount != 0) LinearProgressIndicator(
modifier = Modifier.padding(vertical = 4.dp).fillMaxWidth(),
progress = apm.scannedCount.toFloat() / apm.allScanCount,
)
apm.scanningPlugins.keys.let {
if (it.isNotEmpty()) {
SettingsListManager(
list = it
)
}
}
Expand Down

0 comments on commit c4fded9

Please sign in to comment.