shithub: m8c

Download patch

ref: 0f9a123966b919ddfdc157b193446fdd4946d5d7
parent: bc1d81fca142dde8561e4ef89faf1caad83f120c
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Tue May 4 11:04:14 EDT 2021

correct bg color for oscilloscope

--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # m8c
 
-m8c is a Linux client for Dirtywave M8 tracker's headless mode. It is intended for use with lower end systems like RPi zero. The application should be cross-platform ready and can be built in Mac OS and Windows (with MSYS2/MINGW64).
+m8c is a client for Dirtywave M8 tracker's headless mode. The application should be cross-platform ready and can be built in Linux, Windows (with MSYS2/MINGW64) and Mac OS.
 
 Please note that routing the headless M8 USB audio isn't in the scope of this program -- if this is needed, it can be achieved with tools like jackd, alsa\_in and alsa\_out for example. Check out the guide in file AUDIOGUIDE.md for some instructions on routing the audio.
 
@@ -80,7 +80,9 @@
 Keyjazz allows to enter notes with keyboard, oldschool tracker-style. The layout is two octaves, starting from keys Z and Q.
 When keyjazz is active, regular a/s/z/x keys are disabled.
 
-There is also a so-called gamepad support, currently it's working only if there's only one pad connected and it's a Retrobit NES-style controller, since the settings are hardcoded.
+## Gamepads
+
+The program uses SDL's game controller system, which should make it work automagically with most gamepads.
 
 Enjoy making some nice music!
 
--- a/main.c
+++ b/main.c
@@ -60,28 +60,6 @@
   // main loop
   while (run) {
 
-    // read serial port
-    size_t bytes_read = sp_nonblocking_read(port, serial_buf, serial_read_size);
-    if (bytes_read < 0) {
-      SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "Error %zu reading serial. \n",
-                      bytes_read);
-      run = 0;
-    }
-    if (bytes_read > 0) {
-      for (int i = 0; i < bytes_read; i++) {
-        uint8_t rx = serial_buf[i];
-        // process the incoming bytes into commands and draw them
-        int n = slip_read_byte(&slip, rx);
-        if (n != SLIP_NO_ERROR) {
-          SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SLIP error %d\n", n);
-        }
-      }
-      usleep(10);
-    } else {
-      render_screen();
-      usleep(100);
-    }
-
     // get current inputs
     input_msg_s input = get_input_msg();
 
@@ -109,11 +87,32 @@
         break;
       }
       break;
+    }    
+
+    // read serial port
+    size_t bytes_read = sp_nonblocking_read(port, serial_buf, serial_read_size);
+    if (bytes_read < 0) {
+      SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "Error %zu reading serial. \n",
+                      bytes_read);
+      run = 0;
     }
+    if (bytes_read > 0) {
+      for (int i = 0; i < bytes_read; i++) {
+        uint8_t rx = serial_buf[i];
+        // process the incoming bytes into commands and draw them
+        int n = slip_read_byte(&slip, rx);
+        if (n != SLIP_NO_ERROR) {
+          SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SLIP error %d\n", n);
+        }
+      }
+    } else {
+      render_screen();
+    }
+    usleep(100);
   }
 
   // exit, clean up
-  SDL_Log("\nShutting down\n");
+  SDL_Log("Shutting down\n");
   close_game_controllers();
   close_renderer();
   disconnect(port);
--- a/render.c
+++ b/render.c
@@ -5,6 +5,8 @@
 
 #include <SDL2/SDL.h>
 #include <SDL2/SDL_log.h>
+#include <SDL2/SDL_pixels.h>
+#include <SDL2/SDL_render.h>
 #include <stdio.h>
 
 #include "SDL2_inprint.h"
@@ -13,6 +15,7 @@
 SDL_Window *win;
 SDL_Renderer *rend;
 SDL_Texture *maintexture;
+SDL_Color background_color = (SDL_Color){0, 0, 0, 0};
 
 static uint32_t ticks;
 #ifdef SHOW_FPS
@@ -98,6 +101,15 @@
   render_rect.h = command->size.height;
   render_rect.w = command->size.width;
 
+  // Background color changed
+  if (render_rect.x == 0 && render_rect.y == 0 && render_rect.w == 320 &&
+      render_rect.h == 240) {
+    background_color.r = command->color.r;
+    background_color.g = command->color.g;
+    background_color.b = command->color.b;
+    background_color.a = 0xFF;
+  }
+
   SDL_SetRenderDrawColor(rend, command->color.r, command->color.g,
                          command->color.b, 0xFF);
   SDL_RenderFillRect(rend, &render_rect);
@@ -107,7 +119,8 @@
 
   const SDL_Rect wf_rect = {0, 0, 320, 21};
 
-  SDL_SetRenderDrawColor(rend, 0, 0, 0, 0xFF);
+  SDL_SetRenderDrawColor(rend, background_color.r, background_color.g,
+                         background_color.b, background_color.a);
   SDL_RenderFillRect(rend, &wf_rect);
 
   SDL_SetRenderDrawColor(rend, command->color.r, command->color.g,
@@ -163,7 +176,7 @@
 void render_screen() {
 
   // process every 16ms (roughly 60fps)
-  if (SDL_GetTicks() - ticks > 16) {
+  if (SDL_GetTicks() - ticks > 15) {
     ticks = SDL_GetTicks();
     SDL_SetRenderTarget(rend, NULL);
     SDL_SetRenderDrawColor(rend, 0, 0, 0, 0);
--