-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: more efficient JNI interface
- Loading branch information
1 parent
3c48d8f
commit 059b8c3
Showing
5 changed files
with
139 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/plugin/java/me/timschneeberger/rootlessjamesdsp/flavor/JamesDspBasePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package me.timschneeberger.rootlessjamesdsp.flavor | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import android.content.SharedPreferences | ||
import me.timschneeberger.rootlessjamesdsp.R | ||
import me.timschneeberger.rootlessjamesdsp.interop.JamesDspLocalEngine | ||
import me.timschneeberger.rootlessjamesdsp.interop.ProcessorMessageHandler | ||
import me.timschneeberger.rootlessjamesdsp.utils.Constants | ||
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.registerLocalReceiver | ||
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.unregisterLocalReceiver | ||
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
abstract class JamesDspBasePlugin : KoinComponent, AutoCloseable { | ||
protected val context: Context by inject() | ||
|
||
// Engine | ||
protected val engine = JamesDspLocalEngine(context, ProcessorMessageHandler()) | ||
|
||
// Preferences | ||
protected val preferences: Preferences.App by inject() | ||
private val onPreferenceChanged = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> | ||
when(key) { | ||
context.getString(R.string.key_powered_on) -> { | ||
engine.enabled = preferences.get<Boolean>(R.string.key_powered_on) | ||
} | ||
} | ||
} | ||
|
||
// General purpose broadcast receiver | ||
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() { | ||
override fun onReceive(context: Context, intent: Intent) { | ||
when (intent.action) { | ||
Constants.ACTION_SAMPLE_RATE_UPDATED -> engine.syncWithPreferences(arrayOf(Constants.PREF_CONVOLVER)) | ||
Constants.ACTION_PREFERENCES_UPDATED -> engine.syncWithPreferences() | ||
Constants.ACTION_SERVICE_RELOAD_LIVEPROG -> engine.syncWithPreferences(arrayOf(Constants.PREF_LIVEPROG)) | ||
} | ||
} | ||
} | ||
|
||
init { | ||
preferences.registerOnSharedPreferenceChangeListener(onPreferenceChanged) | ||
// Setup general-purpose broadcast receiver | ||
context.registerLocalReceiver(broadcastReceiver, IntentFilter().apply { | ||
addAction(Constants.ACTION_PREFERENCES_UPDATED) | ||
addAction(Constants.ACTION_SAMPLE_RATE_UPDATED) | ||
addAction(Constants.ACTION_SERVICE_RELOAD_LIVEPROG) | ||
addAction(Constants.ACTION_SERVICE_HARD_REBOOT_CORE) | ||
addAction(Constants.ACTION_SERVICE_SOFT_REBOOT_CORE) | ||
}) | ||
context.registerReceiver(broadcastReceiver, IntentFilter()) | ||
engine.enabled = preferences.get<Boolean>(R.string.key_powered_on) | ||
engine.syncWithPreferences() | ||
} | ||
|
||
override fun close() { | ||
context.unregisterLocalReceiver(broadcastReceiver) | ||
preferences.unregisterOnSharedPreferenceChangeListener(onPreferenceChanged) | ||
engine.close() | ||
} | ||
} |