changeset 2375:02c04196c2da

Fix mediaplayer play/pause handling
author Michael Pavone <pavone@retrodev.com>
date Fri, 17 Nov 2023 00:30:46 -0800
parents 97f164d1f0f6
children 1c09f5be285b
files mediaplayer.c mediaplayer.h
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mediaplayer.c	Wed Nov 15 23:23:52 2023 -0800
+++ b/mediaplayer.c	Fri Nov 17 00:30:46 2023 -0800
@@ -682,8 +682,16 @@
 
 static void gamepad_down(system_header *system, uint8_t pad, uint8_t button)
 {
-	if (button >= BUTTON_A && button <= BUTTON_C) {
-		media_player *player = (media_player *)system;
+	if (pad != 1) {
+		return;
+	}
+	media_player *player = (media_player *)system;
+	if (player->button_state[button]) {
+		//already pressed
+		return;
+	}
+	player->button_state[button] = 1;
+	if (button == BUTTON_A || button == BUTTON_C || button == BUTTON_START) {
 		if (player->state == STATE_PAUSED) {
 			player->state = STATE_PLAY;
 			puts("Now playing");
@@ -696,6 +704,11 @@
 
 static void gamepad_up(system_header *system, uint8_t pad, uint8_t button)
 {
+	if (pad != 1) {
+		return;
+	}
+	media_player *player = (media_player *)system;
+	player->button_state[button] = 0;
 }
 
 static void start_player(system_header *system, char *statefile)
@@ -776,7 +789,7 @@
 	player->header.request_exit = request_exit;
 	player->header.free_context = free_player;
 	player->header.gamepad_down = gamepad_down;
-	player->header.gamepad_up = gamepad_down;
+	player->header.gamepad_up = gamepad_up;
 	player->header.toggle_debug_view = toggle_debug_view;
 	player->header.type = SYSTEM_MEDIA_PLAYER;
 	player->header.info.name = strdup(media->name);
--- a/mediaplayer.h	Wed Nov 15 23:23:52 2023 -0800
+++ b/mediaplayer.h	Fri Nov 17 00:30:46 2023 -0800
@@ -8,6 +8,7 @@
 #include "flac.h"
 #include "oscilloscope.h"
 #include "render_audio.h"
+#include "io.h"
 
 typedef struct chip_info chip_info;
 typedef void (*chip_run_fun)(void *context, uint32_t cycle);
@@ -48,6 +49,7 @@
 	uint8_t             state;
 	uint8_t             media_type;
 	uint8_t             should_return;
+	uint8_t             button_state[NUM_GAMEPAD_BUTTONS];
 } media_player;
 
 media_player *alloc_media_player(system_media *media, uint32_t opts);