shithub: m8c

Download patch

ref: 2ffe2f98fc92726badd0de39414cafdf6d3d88d5
parent: f2de0b151ab7af35b72282ab932bd419e58ea6ea
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Mon Apr 7 18:12:04 EDT 2025

use integer scaling by default, add loop delay to rtmidi response detection, add variables for texture scaling mode

--- a/src/backends/m8_rtmidi.c
+++ b/src/backends/m8_rtmidi.c
@@ -218,6 +218,7 @@
       close_and_free_midi_ports();
       return 0;
     }
+    SDL_Delay(5);
   }
   result = m8_reset_display();
   return result;
--- a/src/config.c
+++ b/src/config.c
@@ -29,10 +29,10 @@
   }
 
   c.init_fullscreen = 0; // default fullscreen state at load
-  c.integer_scaling = 0; // use integer scaling for the user interface
+  c.integer_scaling = 1; // use integer scaling for the user interface
   c.idle_ms = 10;        // default to high performance
   c.wait_for_device = 1; // default to exit if device disconnected
-  c.wait_packets = 512; // amount of empty command queue reads before assuming device disconnected
+  c.wait_packets = 512;  // amount of empty command queue reads before assuming device disconnected
   c.audio_enabled = 0;        // route M8 audio to default output
   c.audio_buffer_size = 0; // requested audio buffer size in samples: 0 = let SDL decide
   c.audio_device_name = NULL; // Use this device, leave NULL to use the default output device
@@ -103,7 +103,8 @@
   snprintf(ini_values[initPointer++], LINELEN, "wait_for_device=%s\n",
            conf->wait_for_device ? "true" : "false");
   snprintf(ini_values[initPointer++], LINELEN, "wait_packets=%d\n", conf->wait_packets);
-  snprintf(ini_values[initPointer++], LINELEN, "integer_scaling=%s\n", conf->integer_scaling ? "true" : "false");
+  snprintf(ini_values[initPointer++], LINELEN, "integer_scaling=%s\n",
+           conf->integer_scaling ? "true" : "false");
   snprintf(ini_values[initPointer++], LINELEN, "[audio]\n");
   snprintf(ini_values[initPointer++], LINELEN, "audio_enabled=%s\n",
            conf->audio_enabled ? "true" : "false");
--- a/src/input.c
+++ b/src/input.c
@@ -198,7 +198,7 @@
       break;
 
     case SDL_EVENT_WINDOW_RESIZED:
-      fix_texture_scaling_after_window_resize();
+      renderer_fix_texture_scaling_after_window_resize();
       break;
 
     case SDL_EVENT_KEY_DOWN:
--- a/src/main.c
+++ b/src/main.c
@@ -95,8 +95,9 @@
           app_state = QUIT;
           screensaver_destroy();
 #ifdef USE_RTMIDI
-          show_error_message("Cannot initialize M8 remote display. Make sure you're running "
-                             "firmware 6.0.0 or newer. Please close and restart the application to try again.");
+          show_error_message(
+              "Cannot initialize M8 remote display. Make sure you're running "
+              "firmware 6.0.0 or newer. Please close and restart the application to try again.");
 #endif
         }
       }
@@ -123,7 +124,10 @@
   }
 
   config_params_s conf = config_initialize(*config_filename);
+#ifndef TARGET_OS_IOS
+  // It's not possible to edit the config on iOS so let's just go with the defaults
   config_read(&conf);
+#endif
   return conf;
 }
 
--- a/src/render.c
+++ b/src/render.c
@@ -23,7 +23,8 @@
 SDL_Renderer *rend;
 SDL_Texture *main_texture;
 SDL_Color global_background_color = (SDL_Color){.r = 0x00, .g = 0x00, .b = 0x00, .a = 0x00};
-SDL_RendererLogicalPresentation scaling_mode = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
+SDL_RendererLogicalPresentation window_scaling_mode = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
+SDL_ScaleMode texture_scaling_mode = SDL_SCALEMODE_NEAREST;
 
 static uint32_t ticks_fps;
 static int fps;
@@ -45,11 +46,13 @@
 
 static void use_integer_scaling(const unsigned int use_integer_scaling) {
   if (use_integer_scaling) {
-    scaling_mode = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
+    window_scaling_mode = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
+    texture_scaling_mode = SDL_SCALEMODE_NEAREST;
   } else {
-    scaling_mode = SDL_LOGICAL_PRESENTATION_LETTERBOX;
+    window_scaling_mode = SDL_LOGICAL_PRESENTATION_LETTERBOX;
+    texture_scaling_mode = SDL_SCALEMODE_LINEAR;
   }
-  fix_texture_scaling_after_window_resize();
+  renderer_fix_texture_scaling_after_window_resize();
 }
 
 // Initializes SDL and creates a renderer and required surfaces
@@ -63,15 +66,16 @@
     return false;
   }
 
-  if (!SDL_CreateWindowAndRenderer(
-          "m8c", texture_width * 2, texture_height * 2,
-          SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | conf->init_fullscreen, &win, &rend)) {
+  if (!SDL_CreateWindowAndRenderer("m8c", texture_width * 2, texture_height * 2,
+                                   SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY |
+                                       SDL_WINDOW_OPENGL | conf->init_fullscreen,
+                                   &win, &rend)) {
     SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s",
                     SDL_GetError());
     return false;
   }
 
-  if (!SDL_SetRenderLogicalPresentation(rend, texture_width, texture_height, scaling_mode)) {
+  if (!SDL_SetRenderLogicalPresentation(rend, texture_width, texture_height, window_scaling_mode)) {
     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set renderer logical presentation: %s",
                  SDL_GetError());
     return false;
@@ -86,7 +90,7 @@
     return false;
   }
 
-  SDL_SetTextureScaleMode(main_texture, SDL_SCALEMODE_NEAREST);
+  SDL_SetTextureScaleMode(main_texture, texture_scaling_mode);
   use_integer_scaling(conf->integer_scaling);
 
   SDL_SetRenderTarget(rend, main_texture);
@@ -131,10 +135,10 @@
   }
 
   SDL_DestroyTexture(main_texture);
-  SDL_SetRenderLogicalPresentation(rend, texture_width, texture_height, scaling_mode);
+  SDL_SetRenderLogicalPresentation(rend, texture_width, texture_height, window_scaling_mode);
   main_texture = SDL_CreateTexture(rend, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET,
                                    texture_width, texture_height);
-  SDL_SetTextureScaleMode(main_texture, SDL_SCALEMODE_NEAREST);
+  SDL_SetTextureScaleMode(main_texture, texture_scaling_mode);
   SDL_SetRenderTarget(rend, main_texture);
 }
 
@@ -363,9 +367,10 @@
   SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Screensaver destroyed");
 }
 
-void fix_texture_scaling_after_window_resize(void) {
+void renderer_fix_texture_scaling_after_window_resize(void) {
   SDL_SetRenderTarget(rend, NULL);
-  SDL_SetRenderLogicalPresentation(rend, texture_width, texture_height, scaling_mode);
+  SDL_SetRenderLogicalPresentation(rend, texture_width, texture_height, window_scaling_mode);
+  SDL_SetTextureScaleMode(main_texture, texture_scaling_mode);
 }
 
 void show_error_message(const char *message) {
--- a/src/render.h
+++ b/src/render.h
@@ -12,6 +12,7 @@
 int renderer_initialize(config_params_s *conf);
 void renderer_close();
 void renderer_set_font_mode(int mode);
+void renderer_fix_texture_scaling_after_window_resize(void);
 
 void draw_waveform(struct draw_oscilloscope_waveform_command *command);
 void draw_rectangle(struct draw_rectangle_command *command);
@@ -29,6 +30,6 @@
 void screensaver_draw();
 void screensaver_destroy();
 
-void fix_texture_scaling_after_window_resize(void);
+
 
 #endif
--