Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirasawaSama committed Dec 10, 2023
1 parent 52f3137 commit 380c9eb
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface AudioPlayer : AutoCloseable {
val availableSampleRates: List<Int>
val availableBufferSizes: List<Int>
val sampleRate: Int
val bufferSize: Int

@Composable fun Controls()
fun onClose(callback: () -> Unit)
Expand All @@ -30,6 +31,7 @@ abstract class AbstractAudioPlayer(
val currentPosition: MutableCurrentPosition,
private val processor: AudioProcessor,
preferredSampleRate: Int? = null,
preferredBufferSize: Int? = null,
) : AudioPlayer {
final override var cpuLoad by mutableStateOf(0F)
private set
Expand All @@ -39,6 +41,8 @@ abstract class AbstractAudioPlayer(
private var closeCallback: (() -> Unit)? = null
override var sampleRate by mutableStateOf(preferredSampleRate ?: currentPosition.sampleRate)
protected set
override var bufferSize by mutableStateOf(preferredBufferSize ?: currentPosition.bufferSize)
protected set
override val availableSampleRates = listOf(44100, 48000, 88200, 96000)
override val availableBufferSizes = listOf(256, 512, 1024, 2048, 4096)

Expand Down Expand Up @@ -98,7 +102,7 @@ interface AudioPlayerFactory {
suspend fun getPlayers(): List<String>
fun create(
name: String, currentPosition: MutableCurrentPosition, processor: AudioProcessor,
preferredSampleRate: Int? = null,
preferredSampleRate: Int? = null, preferredBufferSize: Int? = null,
): AudioPlayer
}

Expand All @@ -113,7 +117,7 @@ interface AudioPlayerManager : Reloadable {

fun create(
factory: String, name: String, currentPosition: MutableCurrentPosition, processor: AudioProcessor,
preferredSampleRate: Int? = null,
preferredSampleRate: Int? = null, preferredBufferSize: Int? = null,
): AudioPlayer
fun createDefaultPlayer(currentPosition: MutableCurrentPosition, processor: AudioProcessor): AudioPlayer
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class AudioPlayerManagerImpl : AudioPlayerManager {
currentPosition: MutableCurrentPosition,
processor: AudioProcessor,
preferredSampleRate: Int?,
) = factories[factory]?.create(name, currentPosition, processor, preferredSampleRate)
preferredBufferSize: Int?,
) = factories[factory]?.create(name, currentPosition, processor, preferredSampleRate, preferredBufferSize)
?: throw NoSuchFactoryException(factory)

override fun createDefaultPlayer(currentPosition: MutableCurrentPosition, processor: AudioProcessor): AudioPlayer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ fun NumberInputArrows(onValueChange: (value: Int) -> Unit) {
.pointerHoverIcon(PointerIcon.Hand).clip(CircleShape).clickable { onValueChange(-1) })
}
}

@Composable
fun textFieldGrayColors() = TextFieldDefaults.colors(
unfocusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
// focusedIndicatorColor = MaterialTheme.colorScheme.outline,
)
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ class EnvelopeEditor(
val range = valueRange.range
val hoveredId = hoveredIndex

println(selectedPoints.firstOrNull())

// draw points
val tmpOffsetX = offsetX
val tmpOffsetY = offsetY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
Expand Down Expand Up @@ -128,12 +129,47 @@ fun <T : Any> OutlinedDropdownSelector(
isSelected: ((T) -> Boolean)? = null,
itemContent: (@Composable (T) -> Unit)? = null,
label: String? = null,
readonly: Boolean = false,
colors: TextFieldColors? = null,
content: (@Composable () -> Unit)? = null,
) {
@OptIn(ExperimentalFoundationApi::class)
DropdownSelector(
onSelected, items, selected, boxModifier, enabled, PointerMatcher.Primary,
isSelected, itemContent, label, true, content
isSelected, itemContent, label, true, readonly, colors, content
)
}

@Composable
fun <T : Any> AutoWidthOutlinedDropdownSelector(
onSelected: (T) -> Unit,
items: Collection<T>,
selected: T?,
boxModifier: Modifier = Modifier,
enabled: Boolean = true,
isSelected: ((T) -> Boolean)? = null,
itemContent: (@Composable (T) -> Unit)? = null,
label: String? = null,
colors: TextFieldColors? = null
) {
var modifier = boxModifier
val textMeasurer = rememberTextMeasurer()
val textWidth = remember(items, items.size) {
(items.maxOfOrNull { textMeasurer.measure(it.displayName).size.width.dp } ?: 0.dp) + 32.dp
}
val maxWidth = if (textWidth > 256.dp) 256.dp else textWidth
modifier = modifier.width(maxWidth)
OutlinedDropdownSelector(
onSelected,
items,
selected,
modifier,
enabled,
isSelected,
itemContent,
label,
readonly = true,
colors
)
}

Expand All @@ -147,12 +183,14 @@ fun <T : Any> DropdownSelector(
isSelected: ((T) -> Boolean)? = null,
itemContent: (@Composable (T) -> Unit)? = null,
label: String? = null,
readOnly: Boolean = false,
colors: TextFieldColors? = null,
content: (@Composable () -> Unit)? = null,
) {
@OptIn(ExperimentalFoundationApi::class)
DropdownSelector(
onSelected, items, selected, boxModifier, enabled, PointerMatcher.Primary,
isSelected, itemContent, label, false, content
isSelected, itemContent, label, false, readOnly, colors, content
)
}

Expand All @@ -168,6 +206,8 @@ fun <T : Any> DropdownSelector(
itemContent: (@Composable (T) -> Unit)? = null,
label: String? = null,
isOutlined: Boolean = false,
readonly: Boolean = false,
colors: TextFieldColors? = null,
content: (@Composable () -> Unit)? = null,
) {
val filter = remember { mutableStateOf<String?>(null) }
Expand Down Expand Up @@ -205,6 +245,8 @@ fun <T : Any> DropdownSelector(
boxModifier.pointerHoverIcon(PointerIcon.Hand),
label = if (label == null) null else ({ Text(label) }),
singleLine = true,
readOnly = readonly,
colors = colors ?: TextFieldDefaults.colors(),
suffix = {
Icon(
Icons.Filled.ExpandMore, "Expand",
Expand All @@ -217,6 +259,8 @@ fun <T : Any> DropdownSelector(
boxModifier.pointerHoverIcon(PointerIcon.Hand),
label = if (label == null) null else ({ Text(label) }),
singleLine = true,
readOnly = readonly,
colors = colors ?: TextFieldDefaults.colors(),
suffix = {
Icon(
Icons.Filled.ExpandMore, "Expand",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,23 @@
package com.eimsound.daw.components

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp


private val EXPANDER_PADDING_HORIZONTAL = 16.dp
private val EXPANDER_PADDING_VERTICAL = 8.dp
private val EXPANDER_CARD_GAP = 4.dp
private val LIST_HEIGHT = 36.dp
private val CARD_HEIGHT = 64.dp
private val EXPAND_ICON_SIZE = 20.dp
private val MENU_MAX_WIDTH = 256.dp

@Composable
fun <T> SettingsMenu(
items: Collection<T>?,
selected: T,
toString: (T) -> String = { it.toString() },
onSelect: (T) -> Unit
) {
if (items == null) return
val textMeasurer = rememberTextMeasurer()
val itemsMap = items.associateBy { toString(it) }
val textWidth = (items.maxOfOrNull { textMeasurer.measure(toString(it)).size.width.dp } ?: 0.dp) + EXPANDER_PADDING_HORIZONTAL * 2
val maxWidth = if (textWidth > MENU_MAX_WIDTH) MENU_MAX_WIDTH else textWidth
OutlinedDropdownSelector(
{ itemsMap[it]?.let { selected -> onSelect(selected) } },
itemsMap.keys,
selected = toString(selected),
) {
CustomOutlinedTextField(
toString(selected), { },
Modifier.width(maxWidth).height(LIST_HEIGHT).pointerHoverIcon(PointerIcon.Hand),
readOnly = true,
textStyle = MaterialTheme.typography.labelLarge.copy(LocalContentColor.current),
suffix = {
Icon(Icons.Filled.ExpandMore, "Expand",
Modifier.size(EXPAND_ICON_SIZE).pointerHoverIcon(PointerIcon.Hand).clip(CircleShape)
.clickable { }
)
},
colors = TextFieldDefaults.colors(
unfocusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
focusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
),
paddingValues = TextFieldDefaults.contentPaddingWithLabel(8.dp, 4.dp, 3.dp, 4.dp)
)
}
}

@Composable
fun SettingsSection(
Expand All @@ -89,7 +44,8 @@ fun SettingsCard(
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.background(MaterialTheme.colorScheme.surface).padding(EXPANDER_PADDING_HORIZONTAL, EXPANDER_PADDING_VERTICAL)
modifier = Modifier.background(MaterialTheme.colorScheme.surface)
.padding(16.dp, EXPANDER_PADDING_VERTICAL)
) {
Text(header)
Filled()
Expand Down
3 changes: 3 additions & 0 deletions daw/src/jvmMain/kotlin/com/eimsound/daw/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ object Configuration : JsonSerializable {
var audioDeviceFactoryName by mutableStateOf("")
var audioDeviceName by mutableStateOf("")
var preferredSampleRate by mutableStateOf(-1)
var preferredBufferSize by mutableStateOf(-1)
var autoCutOver0db by mutableStateOf(true)
var isTimeDisplayInBeats by mutableStateOf(false)
var themeMode by observableMutableStateOf(2) {
Expand Down Expand Up @@ -113,6 +114,7 @@ object Configuration : JsonSerializable {
put("audioDeviceFactoryName", audioDeviceFactoryName)
put("audioDeviceName", audioDeviceName)
put("preferredSampleRate", preferredSampleRate)
put("preferredBufferSize", preferredBufferSize)
put("autoCutOver0db", autoCutOver0db)
put("themeMode", themeMode)
put("isTimeDisplayInBeats", isTimeDisplayInBeats)
Expand All @@ -126,6 +128,7 @@ object Configuration : JsonSerializable {
json["audioDeviceFactoryName"]?.asString()?.let { audioDeviceFactoryName = it }
json["audioDeviceName"]?.asString()?.let { audioDeviceName = it }
json["preferredSampleRate"]?.asInt()?.let { preferredSampleRate = it }
json["preferredBufferSize"]?.asInt()?.let { preferredBufferSize = it }
json["autoCutOver0db"]?.asBoolean()?.let { autoCutOver0db = it }
json["themeMode"]?.asInt()?.let {
themeMode = it
Expand Down
17 changes: 4 additions & 13 deletions daw/src/jvmMain/kotlin/com/eimsound/daw/components/app/AppBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ private fun CurrentTime() {
Modifier.size(20.dp).pointerHoverIcon(PointerIcon.Hand).clip(CircleShape).clickable { }
)
},
colors = TextFieldDefaults.colors(
unfocusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
focusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
),
colors = textFieldGrayColors(),
paddingValues = TextFieldDefaults.contentPaddingWithLabel(8.dp, 4.dp, 3.dp, 4.dp)
)
}
Expand All @@ -81,7 +78,7 @@ private fun CurrentTime() {
private fun Quantification() {
DropdownSelector(
{ EchoInMirror.quantification = it },
QUANTIFICATION_UNITS, EchoInMirror.quantification,
QUANTIFICATION_UNITS, EchoInMirror.quantification, Modifier.pointerHoverIcon(PointerIcon.Hand),
isSelected = { it.getEditUnit(EchoInMirror.currentPosition) == EchoInMirror.editUnit },
itemContent = {
Text(it.name, fontWeight = if (it.isSpecial) FontWeight.Bold else null)
Expand All @@ -101,10 +98,7 @@ private fun Quantification() {
Modifier.size(20.dp).pointerHoverIcon(PointerIcon.Hand).clip(CircleShape).clickable { }
)
},
colors = TextFieldDefaults.colors(
unfocusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
focusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
),
colors = textFieldGrayColors(),
paddingValues = TextFieldDefaults.contentPaddingWithLabel(8.dp, 4.dp, 3.dp, 4.dp)
)
}
Expand Down Expand Up @@ -171,10 +165,7 @@ private fun BPM() {
EchoInMirror.currentPosition.bpm = (EchoInMirror.currentPosition.bpm + it).coerceIn(1.0, 600.0)
}
},
colors = TextFieldDefaults.colors(
unfocusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
focusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
),
colors = textFieldGrayColors(),
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),
paddingValues = TextFieldDefaults.contentPaddingWithLabel(6.dp, 6.dp, 3.dp, 4.dp)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class CurrentPositionImpl(
override var bpm by mutableStateOf(140.0)
override var timeInSeconds by mutableStateOf(0.0)
override var ppq by mutableStateOf(96)
override var bufferSize by mutableStateOf(1024)
override var sampleRate by mutableStateOf(44100)
override var bufferSize = 1024
override var sampleRate = 44100
override var timeSigNumerator by mutableStateOf(4)
override var timeSigDenominator by mutableStateOf(4)
override var loopingRange by mutableStateOf(0..0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class EchoInMirrorImpl : IEchoInMirror {
Configuration.audioDeviceFactoryName,
Configuration.audioDeviceName, currentPosition, bus!!,
if (Configuration.preferredSampleRate > 0) Configuration.preferredSampleRate
else null,
if (Configuration.preferredBufferSize > 0) Configuration.preferredBufferSize
else null
)
} catch (e: Exception) {
Expand All @@ -86,6 +88,10 @@ class EchoInMirrorImpl : IEchoInMirror {
Configuration.preferredSampleRate = -1
flag = true
}
if (Configuration.preferredBufferSize != ret.bufferSize) {
Configuration.preferredBufferSize = -1
flag = true
}
if (flag) Configuration.save()
return ret
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ fun FloatingLayerProvider.openQuickLoadDialog(onClose: ((AudioProcessorDescripti
val factory = descriptionsToFactory[it] ?: return@DescList null
setFloatingLayerShow(KEY, false)
AudioProcessorDescriptionAndFactory(it, factory)
}, onDragEnd = {
closeFloatingLayer(KEY)
println(2333)
}
}, onDragEnd = { closeFloatingLayer(KEY) }
) { desc ->
if (desc == null) return@DescList
if (onClose != null && selectedDescription == desc) {
Expand Down
Loading

0 comments on commit 380c9eb

Please sign in to comment.