Skip to content

Commit 0656f2a

Browse files
authored
Merge pull request #202 from laamaa/feature/message_console
Feature/message console
2 parents db93668 + c0d366f commit 0656f2a

8 files changed

Lines changed: 245 additions & 23 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Additional controls:
156156
* Esc = toggle keyjazz on/off
157157
* r / select+start+opt+edit = reset display (if glitches appear on the screen, use this)
158158
* F12 = toggle audio routing on / off
159+
* ` (grave) = toggle in-app log overlay
159160

160161
### Keyjazz
161162

@@ -210,6 +211,14 @@ m8c --config alternate_config.ini
210211
This looks for a config file with the given name in the same directory as the default config. If you specify a config
211212
file that does not exist, a new default config file with the specified name will be created, which you can then edit.
212213

214+
### Log overlay
215+
216+
An in-app log overlay is available for platforms where reading console output is inconvenient.
217+
218+
- Default toggle key: \` (grave). You can change it in `config.ini` under `[keyboard]` using `key_toggle_log=<SDL_SCANCODE>`.
219+
- The overlay shows recent `SDL_Log*` messages.
220+
- Long lines are wrapped to fit; the view tails the most recent output.
221+
213222
Enjoy making some nice music!
214223

215224
-----------

src/config.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ config_params_s config_initialize(char *filename) {
3333
c.idle_ms = 10; // default to high performance
3434
c.wait_for_device = 1; // default to exit if device disconnected
3535
c.wait_packets = 256; // amount of empty command queue reads before assuming device disconnected
36-
c.audio_enabled = 0; // route M8 audio to default output
37-
c.audio_buffer_size = 0; // requested audio buffer size in samples: 0 = let SDL decide
36+
c.audio_enabled = 0; // route M8 audio to default output
37+
c.audio_buffer_size = 0; // requested audio buffer size in samples: 0 = let SDL decide
3838
c.audio_device_name = NULL; // Use this device, leave NULL to use the default output device
3939

4040
c.key_up = SDL_SCANCODE_UP;
@@ -56,6 +56,7 @@ config_params_s config_initialize(char *filename) {
5656
c.key_jazz_inc_velocity = SDL_SCANCODE_KP_MINUS;
5757
c.key_jazz_dec_velocity = SDL_SCANCODE_KP_PLUS;
5858
c.key_toggle_audio = SDL_SCANCODE_F12;
59+
c.key_toggle_log = SDL_SCANCODE_GRAVE; // default to ` key
5960

6061
c.gamepad_up = SDL_GAMEPAD_BUTTON_DPAD_UP;
6162
c.gamepad_left = SDL_GAMEPAD_BUTTON_DPAD_LEFT;
@@ -90,8 +91,8 @@ void write_config(const config_params_s *conf) {
9091

9192
SDL_Log("Writing config file to %s", config_path);
9293

93-
#define INI_LINE_COUNT 50
94-
#define INI_LINE_LENGTH 50
94+
#define INI_LINE_COUNT 51
95+
#define INI_LINE_LENGTH 50
9596

9697
// Entries for the config file
9798
char ini_values[INI_LINE_COUNT][INI_LINE_LENGTH];
@@ -108,11 +109,13 @@ void write_config(const config_params_s *conf) {
108109
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "[audio]\n");
109110
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "audio_enabled=%s\n",
110111
conf->audio_enabled ? "true" : "false");
111-
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "audio_buffer_size=%d\n", conf->audio_buffer_size);
112+
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "audio_buffer_size=%d\n",
113+
conf->audio_buffer_size);
112114
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "audio_device_name=%s\n",
113115
conf->audio_device_name ? conf->audio_device_name : "Default");
114116
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "[keyboard]\n");
115-
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, ";Ref: https://wiki.libsdl.org/SDL2/SDL_Scancode\n");
117+
snprintf(ini_values[initPointer++], INI_LINE_LENGTH,
118+
";Ref: https://wiki.libsdl.org/SDL2/SDL_Scancode\n");
116119
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "key_up=%d\n", conf->key_up);
117120
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "key_left=%d\n", conf->key_left);
118121
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "key_down=%d\n", conf->key_down);
@@ -135,7 +138,9 @@ void write_config(const config_params_s *conf) {
135138
conf->key_jazz_inc_velocity);
136139
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "key_jazz_dec_velocity=%d\n",
137140
conf->key_jazz_dec_velocity);
138-
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "key_toggle_audio=%d\n", conf->key_toggle_audio);
141+
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "key_toggle_audio=%d\n",
142+
conf->key_toggle_audio);
143+
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "key_toggle_log=%d\n", conf->key_toggle_log);
139144
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "[gamepad]\n");
140145
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "gamepad_up=%d\n", conf->gamepad_up);
141146
snprintf(ini_values[initPointer++], INI_LINE_LENGTH, "gamepad_left=%d\n", conf->gamepad_left);
@@ -285,6 +290,7 @@ void read_key_config(const ini_t *ini, config_params_s *conf) {
285290
const char *key_jazz_inc_velocity = ini_get(ini, "keyboard", "key_jazz_inc_velocity");
286291
const char *key_jazz_dec_velocity = ini_get(ini, "keyboard", "key_jazz_dec_velocity");
287292
const char *key_toggle_audio = ini_get(ini, "keyboard", "key_toggle_audio");
293+
const char *key_toggle_log = ini_get(ini, "keyboard", "key_toggle_log");
288294

289295
if (key_up)
290296
conf->key_up = SDL_atoi(key_up);
@@ -324,6 +330,8 @@ void read_key_config(const ini_t *ini, config_params_s *conf) {
324330
conf->key_jazz_dec_velocity = SDL_atoi(key_jazz_dec_velocity);
325331
if (key_toggle_audio)
326332
conf->key_toggle_audio = SDL_atoi(key_toggle_audio);
333+
if (key_toggle_log)
334+
conf->key_toggle_log = SDL_atoi(key_toggle_log);
327335
}
328336

329337
void read_gamepad_config(const ini_t *ini, config_params_s *conf) {

src/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct config_params_s {
3636
unsigned int key_jazz_inc_velocity;
3737
unsigned int key_jazz_dec_velocity;
3838
unsigned int key_toggle_audio;
39+
unsigned int key_toggle_log;
3940

4041
int gamepad_up;
4142
int gamepad_left;

src/inprint2.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ static Uint16 selected_font_w, selected_font_h;
1919

2020
void inline_font_initialize(struct inline_font *font) {
2121

22-
selected_font_w = font->width;
23-
selected_font_h = font->height;
24-
selected_inline_font = font;
25-
2622
if (inline_font != NULL) {
27-
selected_font = inline_font;
2823
return;
2924
}
3025

26+
selected_font_w = font->width;
27+
selected_font_h = font->height;
28+
selected_inline_font = font;
29+
3130
SDL_IOStream *font_bmp =
3231
SDL_IOFromConstMem(selected_inline_font->image_data, selected_inline_font->image_size);
3332

@@ -119,8 +118,7 @@ void inprint(SDL_Renderer *dst, const char *str, Uint32 x, Uint32 y, const Uint3
119118

120119
if (bgcolor != fgcolor) {
121120
SDL_SetRenderDrawColor(selected_renderer, (bgcolor & 0x00FF0000) >> 16,
122-
(bgcolor & 0x0000FF00) >> 8, bgcolor & 0x000000FF,
123-
0xFF);
121+
(bgcolor & 0x0000FF00) >> 8, bgcolor & 0x000000FF, 0xFF);
124122
bg_rect = d_rect;
125123
bg_rect.w = (float)selected_inline_font->glyph_x;
126124
bg_rect.h = (float)selected_inline_font->glyph_y;

src/input.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ void input_handle_key_down_event(struct app_context *ctx, const SDL_Event *event
188188
return;
189189
}
190190

191+
// Toggle in-app log overlay using config-defined key
192+
if (event->key.scancode == ctx->conf.key_toggle_log) {
193+
renderer_toggle_log_overlay();
194+
return;
195+
}
196+
191197
if (event->key.scancode == ctx->conf.key_toggle_audio && ctx->device_connected) {
192198
ctx->conf.audio_enabled = !ctx->conf.audio_enabled;
193199
audio_toggle(ctx->conf.audio_device_name, ctx->conf.audio_buffer_size);
@@ -280,8 +286,8 @@ void input_handle_gamepad_button(struct app_context *ctx, const SDL_GamepadButto
280286
* @param negative_key The key to activate when the axis value is below a negative threshold
281287
* @param positive_key The key to activate when the axis value is above a positive threshold
282288
*/
283-
static void update_button_state_from_axis(Sint16 axis_value, int threshold,
284-
int negative_key, int positive_key) {
289+
static void update_button_state_from_axis(Sint16 axis_value, int threshold, int negative_key,
290+
int positive_key) {
285291
if (axis_value < -threshold) {
286292
gamepad_state.current_buttons |= negative_key;
287293
} else if (axis_value > threshold) {
@@ -301,7 +307,7 @@ static void update_button_state_from_axis(Sint16 axis_value, int threshold,
301307
* @param value The analog value of the axis, typically ranging from -32768 to 32767.
302308
*/
303309
void input_handle_gamepad_axis(const struct app_context *ctx, const SDL_GamepadAxis axis,
304-
const Sint16 value) {
310+
const Sint16 value) {
305311
const config_params_s *conf = &ctx->conf;
306312
gamepad_state.analog_values[axis] = value;
307313

src/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#include "gamepads.h"
1919
#include "render.h"
2020

21-
// On MacOS TARGET_OS_IOS is defined as 0, so make sure that it's consistent on other platforms as well
21+
// On MacOS TARGET_OS_IOS is defined as 0, so make sure that it's consistent on other platforms as
22+
// well
2223
#ifndef TARGET_OS_IOS
2324
#define TARGET_OS_IOS 0
2425
#endif
@@ -95,7 +96,7 @@ static config_params_s initialize_config(int argc, char *argv[], char **preferre
9596

9697
if (TARGET_OS_IOS == 1) {
9798
// Predefined settings for iOS
98-
conf.init_fullscreen=1;
99+
conf.init_fullscreen = 1;
99100
} else {
100101
// On other platforms, read config normally
101102
config_read(&conf);
@@ -166,6 +167,9 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
166167
SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
167168
char *config_filename = NULL;
168169

170+
// Initialize in-app log capture/overlay
171+
renderer_log_init();
172+
169173
// Process the application's main callback roughly at 120 Hz
170174
SDL_SetHint(SDL_HINT_MAIN_CALLBACK_RATE, "120");
171175

0 commit comments

Comments
 (0)