Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add microphone toggle button #1214

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/src/main/cpp/MelonDSAndroidJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,17 @@ Java_me_magnum_melonds_MelonEmulator_setFastForwardEnabled(JNIEnv* env, jobject
}
}

JNIEXPORT void JNICALL
Java_me_magnum_melonds_MelonEmulator_setMicrophoneEnabled(JNIEnv* env, jobject thiz, jboolean enabled)
{
if(enabled)
{
MelonDSAndroid::enableMic();
} else {
MelonDSAndroid::disableMic();
}
}

JNIEXPORT void JNICALL
Java_me_magnum_melonds_MelonEmulator_updateEmulatorConfiguration(JNIEnv* env, jobject thiz, jobject emulatorConfiguration, jobject frameBuffer)
{
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/me/magnum/melonds/MelonEmulator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,7 @@ object MelonEmulator {

external fun setFastForwardEnabled(enabled: Boolean)

external fun setMicrophoneEnabled(enabled: Boolean)

external fun updateEmulatorConfiguration(emulatorConfiguration: EmulatorConfiguration, frameBuffer: ByteBuffer)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ControllerConfiguration(configList: List<InputConfig>) {
Input.HINGE,
Input.PAUSE,
Input.FAST_FORWARD,
Input.MICROPHONE,
Input.RESET,
Input.SWAP_SCREENS,
Input.QUICK_SAVE,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/me/magnum/melonds/domain/model/Input.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class Input(val keyCode: Int) {
HINGE(16 + 7),
PAUSE(-1),
FAST_FORWARD(-1),
MICROPHONE(-1),
RESET(-1),
TOGGLE_SOFT_INPUT(-1),
SWAP_SCREENS(-1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ enum class LayoutComponent {
BUTTON_SWAP_SCREENS,
BUTTON_QUICK_SAVE,
BUTTON_QUICK_LOAD,
BUTTON_REWIND;
BUTTON_REWIND,
BUTTON_MICROPHONE_TOGGLE;

fun isScreen(): Boolean {
return this == TOP_SCREEN || this == BOTTOM_SCREEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class DefaultLayoutProvider(private val context: Context, private val screenUnit
PositionedLayoutComponent(Rect(width - lrButtonsSize, screenHeight, lrButtonsSize, lrButtonsSize), LayoutComponent.BUTTON_R),
PositionedLayoutComponent(Rect(width / 2 - smallButtonsSize - spacing4dp / 2, height - smallButtonsSize, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_SELECT),
PositionedLayoutComponent(Rect(width / 2 + spacing4dp / 2, height - smallButtonsSize, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_START),
PositionedLayoutComponent(Rect(width / 2 - (smallButtonsSize * 1.5).toInt() - spacing4dp * 2, screenHeight, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_HINGE),
PositionedLayoutComponent(Rect(width / 2 - (smallButtonsSize * 0.5).toInt(), screenHeight, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_TOGGLE_SOFT_INPUT),
PositionedLayoutComponent(Rect(width / 2 + (smallButtonsSize * 0.5).toInt() + spacing4dp * 2, screenHeight, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_FAST_FORWARD_TOGGLE),
PositionedLayoutComponent(Rect(width / 2 - (smallButtonsSize * 2.0).toInt() - spacing4dp * 2, screenHeight, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_HINGE),
PositionedLayoutComponent(Rect(width / 2 - smallButtonsSize, screenHeight, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_TOGGLE_SOFT_INPUT),
PositionedLayoutComponent(Rect(width / 2 + spacing4dp * 2, screenHeight, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_FAST_FORWARD_TOGGLE),
PositionedLayoutComponent(Rect(width / 2 + smallButtonsSize + spacing4dp * 4, screenHeight, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_MICROPHONE_TOGGLE),
)
)
}
Expand Down Expand Up @@ -97,9 +98,10 @@ class DefaultLayoutProvider(private val context: Context, private val screenUnit
PositionedLayoutComponent(Rect(width - lrButtonsSize, 0, lrButtonsSize, lrButtonsSize), LayoutComponent.BUTTON_R),
PositionedLayoutComponent(Rect((width - spacing4dp) / 2 - smallButtonsSize, height - smallButtonsSize, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_SELECT),
PositionedLayoutComponent(Rect((width + spacing4dp) / 2, height - smallButtonsSize, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_START),
PositionedLayoutComponent(Rect(width / 2 - (smallButtonsSize * 1.5).toInt() - spacing4dp * 2, 0, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_HINGE),
PositionedLayoutComponent(Rect(width / 2 - (smallButtonsSize * 0.5).toInt(), 0, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_TOGGLE_SOFT_INPUT),
PositionedLayoutComponent(Rect(width / 2 + (smallButtonsSize * 0.5).toInt() + spacing4dp * 2, 0, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_FAST_FORWARD_TOGGLE),
PositionedLayoutComponent(Rect(width / 2 - (smallButtonsSize * 2.0).toInt() - spacing4dp * 2, 0, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_HINGE),
PositionedLayoutComponent(Rect(width / 2 - smallButtonsSize, 0, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_TOGGLE_SOFT_INPUT),
PositionedLayoutComponent(Rect(width / 2 + spacing4dp * 2, 0, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_FAST_FORWARD_TOGGLE),
PositionedLayoutComponent(Rect(width / 2 + smallButtonsSize + spacing4dp * 4, 0, smallButtonsSize, smallButtonsSize), LayoutComponent.BUTTON_MICROPHONE_TOGGLE),
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SingleButtonLayoutComponentViewBuilder(private val layoutComponent: Layout
LayoutComponent.BUTTON_QUICK_SAVE -> R.drawable.button_quick_save
LayoutComponent.BUTTON_QUICK_LOAD -> R.drawable.button_quick_load
LayoutComponent.BUTTON_REWIND -> R.drawable.button_rewind
LayoutComponent.BUTTON_MICROPHONE_TOGGLE -> R.drawable.button_microphone
else -> -1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class EmulatorActivity : AppCompatActivity() {
private lateinit var nativeInputListener: INativeInputListener
private val frontendInputHandler = object : FrontendInputHandler() {
private var fastForwardEnabled = false
private var microphoneEnabled = true

override fun onSoftInputTogglePressed() {
binding.viewLayoutControls.toggleSoftInputVisibility()
Expand All @@ -163,6 +164,11 @@ class EmulatorActivity : AppCompatActivity() {
MelonEmulator.setFastForwardEnabled(fastForwardEnabled)
}

override fun onMicrophonePressed() {
microphoneEnabled = !microphoneEnabled
MelonEmulator.setMicrophoneEnabled(microphoneEnabled)
}

override fun onResetPressed() {
viewModel.resetEmulator()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class RuntimeLayoutView(context: Context, attrs: AttributeSet?) : LayoutView(con
getLayoutComponentView(LayoutComponent.BUTTON_RESET)?.view?.setOnTouchListener(SingleButtonInputHandler(it, Input.RESET, enableHapticFeedback, touchVibrator))
getLayoutComponentView(LayoutComponent.BUTTON_PAUSE)?.view?.setOnTouchListener(SingleButtonInputHandler(it, Input.PAUSE, enableHapticFeedback, touchVibrator))
getLayoutComponentView(LayoutComponent.BUTTON_FAST_FORWARD_TOGGLE)?.view?.setOnTouchListener(SingleButtonInputHandler(it, Input.FAST_FORWARD, enableHapticFeedback, touchVibrator))
getLayoutComponentView(LayoutComponent.BUTTON_MICROPHONE_TOGGLE)?.view?.setOnTouchListener(SingleButtonInputHandler(it, Input.MICROPHONE, enableHapticFeedback, touchVibrator))
getLayoutComponentView(LayoutComponent.BUTTON_TOGGLE_SOFT_INPUT)?.view?.setOnTouchListener(SingleButtonInputHandler(it, Input.TOGGLE_SOFT_INPUT, enableHapticFeedback, touchVibrator))
getLayoutComponentView(LayoutComponent.BUTTON_SWAP_SCREENS)?.view?.setOnTouchListener(SingleButtonInputHandler(it, Input.SWAP_SCREENS, enableHapticFeedback, touchVibrator))
getLayoutComponentView(LayoutComponent.BUTTON_QUICK_SAVE)?.view?.setOnTouchListener(SingleButtonInputHandler(it, Input.QUICK_SAVE, enableHapticFeedback, touchVibrator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ abstract class FrontendInputHandler : IInputListener {
when (key) {
Input.PAUSE -> onPausePressed()
Input.FAST_FORWARD -> onFastForwardPressed()
Input.MICROPHONE -> onMicrophonePressed()
Input.TOGGLE_SOFT_INPUT -> onSoftInputTogglePressed()
Input.RESET -> onResetPressed()
Input.SWAP_SCREENS -> onSwapScreens()
Expand All @@ -26,6 +27,7 @@ abstract class FrontendInputHandler : IInputListener {

abstract fun onPausePressed()
abstract fun onFastForwardPressed()
abstract fun onMicrophonePressed()
abstract fun onSoftInputTogglePressed()
abstract fun onResetPressed()
abstract fun onSwapScreens()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class InputSetupActivity : AppCompatActivity() {
Input.HINGE -> R.string.input_lid
Input.PAUSE -> R.string.input_pause
Input.FAST_FORWARD -> R.string.input_fast_forward
Input.MICROPHONE -> R.string.input_microphone
Input.RESET -> R.string.input_reset
Input.SWAP_SCREENS -> R.string.input_swap_screens
Input.QUICK_SAVE -> R.string.input_quick_save
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/me/magnum/melonds/utils/InputUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fun getLayoutComponentName(layoutComponent: LayoutComponent): Int {
LayoutComponent.BUTTON_HINGE -> R.string.input_lid
LayoutComponent.BUTTON_PAUSE -> R.string.input_pause
LayoutComponent.BUTTON_FAST_FORWARD_TOGGLE -> R.string.input_fast_forward
LayoutComponent.BUTTON_MICROPHONE_TOGGLE -> R.string.input_microphone
LayoutComponent.BUTTON_TOGGLE_SOFT_INPUT -> R.string.input_toggle_soft_input
LayoutComponent.BUTTON_RESET -> R.string.reset
LayoutComponent.BUTTON_SWAP_SCREENS -> R.string.input_swap_screens
Expand Down
Binary file added app/src/main/res/drawable/button_microphone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
<string name="input_lid">Toggle Lid</string>
<string name="input_pause">Pause</string>
<string name="input_fast_forward">Fast Forward (Toggle)</string>
<string name="input_microphone">Toggle Microphone</string>
<string name="input_toggle_soft_input">Toggle Soft Input</string>
<string name="input_reset">@string/reset</string>
<string name="input_dpad">DPAD</string>
Expand Down
2 changes: 1 addition & 1 deletion melonDS-android-lib