mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-30 06:32:36 +00:00
Added support for reading and writing replay and preamp gain settings in
musikdroid.
This commit is contained in:
parent
e047cc91c0
commit
b24c13abe2
@ -33,20 +33,20 @@ class Messages {
|
||||
AppendToPlaylist("append_to_playlist"),
|
||||
RemoveTracksFromPlaylist("remove_tracks_from_playlist"),
|
||||
ListOutputDrivers("list_output_drivers"),
|
||||
SetDefaultOutputDriver("set_default_output_driver");
|
||||
SetDefaultOutputDriver("set_default_output_driver"),
|
||||
GetGainSettings("get_gain_settings"),
|
||||
UpdateGainSettings("update_gain_settings");
|
||||
|
||||
override fun toString(): String = rawValue
|
||||
fun matches(name: String): Boolean = (rawValue == name)
|
||||
|
||||
companion object {
|
||||
|
||||
fun from(rawValue: String): Request? {
|
||||
for (value in Request.values()) {
|
||||
if (value.toString() == rawValue) {
|
||||
return value
|
||||
Request.values().forEach {
|
||||
if (it.toString() == rawValue) {
|
||||
return it
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -61,12 +61,11 @@ class Messages {
|
||||
|
||||
companion object {
|
||||
fun from(rawValue: String): Broadcast? {
|
||||
for (value in Broadcast.values()) {
|
||||
if (value.toString() == rawValue) {
|
||||
return value
|
||||
Broadcast.values().forEach {
|
||||
if (it.toString() == rawValue) {
|
||||
return it
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -102,6 +101,8 @@ class Messages {
|
||||
val SORT_ORDERS = "sort_orders"
|
||||
val DRIVER_NAME = "driver_name"
|
||||
val DEVICE_ID = "device_id"
|
||||
val REPLAYGAIN_MODE = "replaygain_mode"
|
||||
val PREAMP_GAIN = "preamp_gain"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,10 @@ class SocketMessage private constructor(val name: String, val id: String, val ty
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
fun getJsonObject(): JSONObject {
|
||||
return JSONObject(options.toString())
|
||||
}
|
||||
|
||||
@JvmOverloads fun getJsonObjectOption(key: String, defaultValue: JSONObject? = null): JSONObject? {
|
||||
if (options.has(key)) {
|
||||
try {
|
||||
|
@ -51,5 +51,8 @@ interface IDataProvider {
|
||||
fun listOutputDrivers(): Observable<List<IOutput>>
|
||||
fun setDefaultOutputDriver(driverName: String, deviceId: String = "default"): Observable<Boolean>
|
||||
|
||||
fun getGainSettings(): Observable<IGainSettings>
|
||||
fun updateGainSettings(replayGainMode: IGainSettings.ReplayGainMode, preampGain: Float): Observable<Boolean>
|
||||
|
||||
val state: State
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package io.casey.musikcube.remote.service.websocket.model
|
||||
|
||||
interface IGainSettings {
|
||||
enum class ReplayGainMode(val rawValue: String) {
|
||||
Disabled("disabled"),
|
||||
Album("album"),
|
||||
Track("track");
|
||||
|
||||
companion object {
|
||||
fun find(raw: String): ReplayGainMode {
|
||||
values().forEach {
|
||||
if (it.rawValue == raw) {
|
||||
return it
|
||||
}
|
||||
}
|
||||
return Disabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val replayGainMode: ReplayGainMode
|
||||
val preampGain: Float
|
||||
}
|
@ -423,6 +423,30 @@ class RemoteDataProvider(private val service: WebSocketService) : IDataProvider
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun getGainSettings(): Observable<IGainSettings> {
|
||||
val message = SocketMessage.Builder
|
||||
.request(Messages.Request.GetGainSettings)
|
||||
.build()
|
||||
|
||||
return service.observe(message, client)
|
||||
.flatMap<IGainSettings> { socketMessage ->
|
||||
Observable.just(RemoteGainSettings(socketMessage.getJsonObject()))
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun updateGainSettings(replayGainMode: IGainSettings.ReplayGainMode, preampGain: Float): Observable<Boolean> {
|
||||
val message = SocketMessage.Builder
|
||||
.request(Messages.Request.UpdateGainSettings)
|
||||
.addOption(Messages.Key.REPLAYGAIN_MODE, replayGainMode.rawValue)
|
||||
.addOption(Messages.Key.PREAMP_GAIN, preampGain)
|
||||
.build()
|
||||
|
||||
return service.observe(message, client)
|
||||
.flatMap<Boolean> { socketMessage -> isSuccessful(socketMessage) }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun observeState(): Observable<Pair<IDataProvider.State, IDataProvider.State>> =
|
||||
connectionStatePublisher.observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
package io.casey.musikcube.remote.service.websocket.model.impl.remote
|
||||
|
||||
import io.casey.musikcube.remote.service.websocket.Messages
|
||||
import io.casey.musikcube.remote.service.websocket.model.IGainSettings
|
||||
import org.json.JSONObject
|
||||
|
||||
class RemoteGainSettings(val json: JSONObject): IGainSettings {
|
||||
override val replayGainMode: IGainSettings.ReplayGainMode
|
||||
get() = IGainSettings.ReplayGainMode.find(json.optString(Messages.Key.REPLAYGAIN_MODE, "disabled"))
|
||||
override val preampGain: Float
|
||||
get() = json.optDouble(Messages.Key.PREAMP_GAIN, 0.0).toFloat()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user