shithub: m8c

Download patch

ref: 5df233610e0148f6781c45c81bae74fdc2b1dba4
parent: 3e48bc9cc224023820605085aff70bff5cd30c0c
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Tue Apr 15 17:28:24 EDT 2025

Standardize function signatures and add `renderer_clear_screen`

Updated a bunch of function declarations and definitions to include `(void)` in their signatures to stop clang from nagging. Introduced `renderer_clear_screen` to reset screen state, improving graphical handling, and integrated its use in the event handling logic.

--- a/src/backends/audio_sdl.c
+++ b/src/backends/audio_sdl.c
@@ -156,7 +156,7 @@
   return 1;
 }
 
-void audio_close() {
+void audio_close(void) {
   if (!audio_initialized)
     return;
   SDL_Log("Closing audio devices");
--- a/src/backends/m8_rtmidi.c
+++ b/src/backends/m8_rtmidi.c
@@ -136,7 +136,7 @@
   midi_sysex_received = false;
 }
 
-static int initialize_rtmidi() {
+static int initialize_rtmidi(void) {
   SDL_Log("Initializing rtmidi");
   midi_in = rtmidi_in_create(RTMIDI_API_UNSPECIFIED, "m8c_in", 2048);
   midi_out = rtmidi_out_create(RTMIDI_API_UNSPECIFIED, "m8c_out");
@@ -171,7 +171,7 @@
   return m8_midi_port_number;
 }
 
-static int device_still_exists() {
+static int device_still_exists(void) {
   if (midi_in == NULL || midi_out == NULL) {
     return 0;
   };
@@ -332,13 +332,13 @@
   return DEVICE_PROCESSING;
 }
 
-int m8_close() {
+int m8_close(void) {
   const int result = disconnect();
   destroy_queue(&queue);
   return result;
 }
 
-int m8_list_devices() {
+int m8_list_devices(void) {
   if (midi_in == NULL || midi_out == NULL) {
     initialize_rtmidi();
   };
--- a/src/events.c
+++ b/src/events.c
@@ -37,6 +37,7 @@
     SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Received SDL_EVENT_DID_ENTER_FOREGROUND");
     ctx->app_suspended = 0;
     if (ctx->device_connected) {
+      renderer_clear_screen();
       m8_resume_processing();
     }
   case SDL_EVENT_WINDOW_RESIZED:
--- a/src/fx_cube.c
+++ b/src/fx_cube.c
@@ -1,8 +1,6 @@
 #include "SDL2_inprint.h"
-#include <SDL3/SDL.h>
-#include <SDL3/SDL_timer.h>
-#include <time.h>
 
+#include <SDL3/SDL.h>
 #include <math.h>
 
 // Handle screensaver cube effect
@@ -94,7 +92,7 @@
   center_y = (int)(texture_size.y / 2.0);
 }
 
-void fx_cube_destroy() {
+void fx_cube_destroy(void) {
   // Free resources
   SDL_DestroyTexture(texture_cube);
   SDL_DestroyTexture(texture_text);
@@ -106,7 +104,7 @@
 }
 
 // Update the cube texture every 16ms>. Returns 1 if cube was updated, 0 if no changes were made.
-int fx_cube_update() {
+int fx_cube_update(void) {
   static Uint64 ticks_last_update = 0;
 
   if (SDL_GetTicks() - ticks_last_update >= 16) {
@@ -119,7 +117,7 @@
     SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
     SDL_RenderClear(fx_renderer);
 
-    const unsigned int seconds = SDL_GetTicks() / 1000;
+    const Uint64 seconds = SDL_GetTicks() / 1000;
     const float scale_factor = 1 + SDL_sinf((float)seconds) * (float)0.005;
 
     scale(scale_factor, scale_factor, scale_factor);
--- a/src/fx_cube.h
+++ b/src/fx_cube.h
@@ -5,6 +5,6 @@
 void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color,
                   unsigned int texture_width, unsigned int texture_height,
                   unsigned int font_glyph_width);
-void fx_cube_destroy();
-int fx_cube_update();
+void fx_cube_destroy(void);
+int fx_cube_update(void);
 #endif
\ No newline at end of file
--- a/src/input.h
+++ b/src/input.h
@@ -4,8 +4,8 @@
 
 #ifndef INPUT_H
 #define INPUT_H
-#include "config.h"
 #include "common.h"
+#include "config.h"
 
 #include <SDL3/SDL_events.h>
 
--- a/src/render.c
+++ b/src/render.c
@@ -184,7 +184,8 @@
   SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "Font mode %i, Screen offset %i", mode, screen_offset_y);
 }
 
-void renderer_close() {
+void renderer_close(void) {
+  SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "Closing renderer");
   inline_font_close();
   SDL_DestroyTexture(main_texture);
   SDL_DestroyRenderer(rend);
@@ -191,7 +192,7 @@
   SDL_DestroyWindow(win);
 }
 
-void toggle_fullscreen() {
+void toggle_fullscreen(void) {
 
   const unsigned long fullscreen_state = SDL_GetWindowFlags(win) & SDL_WINDOW_FULLSCREEN;
 
@@ -335,7 +336,7 @@
   dirty = 1;
 }
 
-void render_screen() {
+void render_screen(void) {
   if (dirty) {
     dirty = 0;
     SDL_SetRenderTarget(rend, NULL);
@@ -358,7 +359,7 @@
   }
 }
 
-int screensaver_init() {
+int screensaver_init(void) {
   if (screensaver_initialized) {
     return 1;
   }
@@ -371,11 +372,9 @@
   return 1;
 }
 
-void screensaver_draw() {
-  dirty = fx_cube_update();
-}
+void screensaver_draw(void) { dirty = fx_cube_update(); }
 
-void screensaver_destroy() {
+void screensaver_destroy(void) {
   fx_cube_destroy();
   renderer_set_font_mode(0);
   SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Screensaver destroyed");
@@ -390,4 +389,14 @@
 
 void show_error_message(const char *message) {
   SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "m8c error", message, win);
+}
+
+void renderer_clear_screen(void) {
+  SDL_SetRenderDrawColor(rend, global_background_color.r, global_background_color.g,
+                         global_background_color.b, global_background_color.a);
+  SDL_SetRenderTarget(rend, main_texture);
+  SDL_RenderClear(rend);
+  SDL_SetRenderTarget(rend, NULL);
+
+  SDL_RenderClear(rend);
 }
\ No newline at end of file
--- a/src/render.h
+++ b/src/render.h
@@ -10,9 +10,10 @@
 #include <stdint.h>
 
 int renderer_initialize(config_params_s *conf);
-void renderer_close();
+void renderer_close(void);
 void renderer_set_font_mode(int mode);
 void renderer_fix_texture_scaling_after_window_resize(void);
+void renderer_clear_screen(void);
 
 void draw_waveform(struct draw_oscilloscope_waveform_command *command);
 void draw_rectangle(struct draw_rectangle_command *command);
@@ -20,15 +21,15 @@
 
 void set_m8_model(unsigned int model);
 
-void render_screen();
-void toggle_fullscreen();
+void render_screen(void);
+void toggle_fullscreen(void);
 void display_keyjazz_overlay(uint8_t show, uint8_t base_octave, uint8_t velocity);
 
 void show_error_message(const char *message);
 
-int screensaver_init();
-void screensaver_draw();
-void screensaver_destroy();
+int screensaver_init(void);
+void screensaver_draw(void);
+void screensaver_destroy(void);
 
 
 
--