shithub: m8c

Download patch

ref: 060978e75697f26b4b5340d1526d0bdf826f5cb0
parent: f305482566eac11144636213f537b79f892320a2
parent: 393a3e1397be03d7e34bcc65829dcebec18f2146
author: Jorge Molero <jmolerocalafell@gmail.com>
date: Tue Apr 23 14:00:05 EDT 2024

Merge remote-tracking branch 'origin/main' into feat/jazzkeys-keys-config

--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -27,7 +27,7 @@
       shell: bash
 
     - name: 'Checkout'
-      uses: actions/checkout@v3
+      uses: actions/checkout@v4
       with:
         fetch-depth: 0
 
@@ -58,7 +58,7 @@
         unix2dos README.md LICENSE AUDIOGUIDE.md
     - name: 'Upload artifact (win32)'
       if: matrix.win == 'win32'
-      uses: actions/upload-artifact@v3
+      uses: actions/upload-artifact@v4
       with:
         name: m8c-${{ env.NOW }}-${{ matrix.win }}
         path: |
@@ -73,7 +73,7 @@
           AUDIOGUIDE.md
     - name: 'Upload artifact (win64)'
       if: matrix.win == 'win64'
-      uses: actions/upload-artifact@v3
+      uses: actions/upload-artifact@v4
       with:
         name: m8c-${{ env.NOW }}-${{ matrix.win }}
         path: |
@@ -94,7 +94,7 @@
           sudo apt-get update
           sudo apt-get install --fix-missing build-essential libsdl2-dev libserialport-dev zip
       - name: 'Checkout'
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
 
       - name: Set current date as env variable
         run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
@@ -103,7 +103,7 @@
         run: |
           make
       - name: 'Upload artifact'
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: m8c-${{ env.NOW }}-linux
           path: |
@@ -121,7 +121,7 @@
         run: brew install cmake sdl2 libserialport pkg-config
 
       - name: 'Checkout'
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
 
       - name: Set current date as env variable
         run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV        
@@ -138,7 +138,7 @@
           cp -r /tmp/m8c.app .
           zip -r m8c.zip m8c.app LICENSE README.md AUDIOGUIDE.md gamecontrollerdb.txt
       - name: 'Upload artifact'
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: m8c-${{ env.NOW }}-macos
           path: m8c.zip           
--- a/.github/workflows/nix-package.yml
+++ b/.github/workflows/nix-package.yml
@@ -12,9 +12,10 @@
 
     steps:
       - name: Checkout code
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
         with:
           fetch-depth: 0
+          ref: ${{ github.event.push.head.ref }}
 
       - name: Set up Nix
         uses: cachix/install-nix-action@v22
@@ -52,4 +53,4 @@
           git config user.email "github-actions@github.com"
           git config user.name "GitHub Actions"
           git commit -am "Update version and hash in default.nix to $latest_annotated_tag_without_v"
-          git push
+          git push origin HEAD:main
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
 DEPS = src/serial.h src/slip.h src/command.h src/render.h src/ini.h src/config.h src/input.h src/fx_cube.h src/audio.h src/ringbuffer.h src/inline_font.h
 
 #Any special libraries you are using in your project (e.g. -lbcm2835 -lrt `pkg-config --libs gtk+-3.0` ), or leave blank
-INCLUDES = $(shell pkg-config --libs sdl2 libserialport)
+INCLUDES = $(shell pkg-config --libs sdl2 libserialport | sed 's/-mwindows//')
 
 #Set any compiler flags you want to use (e.g. -I/usr/include/somefolder `pkg-config --cflags gtk+-3.0` ), or leave blank
 local_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags sdl2 libserialport) -Wall -O2 -pipe -I.
--- a/README.md
+++ b/README.md
@@ -85,6 +85,23 @@
 
 If the stars are aligned correctly, you should see the M8 screen.
 
+#### Choosing a preferred device
+
+When you have multiple M8 devices connected and you want to choose a specific one or launch m8c multiple times, you can get the list of devices by running
+
+```
+./m8c --list
+
+2024-02-25 18:39:27.806 m8c[99838:4295527] INFO: Found M8 device: /dev/cu.usbmodem124709801
+2024-02-25 18:39:27.807 m8c[99838:4295527] INFO: Found M8 device: /dev/cu.usbmodem121136001
+```
+
+And you can specify the preferred device by using
+
+```
+./m8c --dev /dev/cu.usbmodem124709801
+```
+
 -----------
 
 ## Keyboard mappings
--- a/default.nix
+++ b/default.nix
@@ -25,7 +25,7 @@
 
   let
     pname = "m8c";
-    version = "1.5.5";
+    version = "1.6.0";
   in
     stdenv.mkDerivation {
       inherit pname version;
@@ -34,7 +34,7 @@
         owner = "laamaa";
         repo = pname;
         rev = "v${version}";
-        hash = "sha256:04rn7b18xy5z03mlsb55nm1kn1k0ynqycs0km9w1yzrlq6rwrcn5";
+        hash = "sha256:1sv1d419mgymh2xcrisnk26qqr77ldb3xp7k1qm3s6cvlil42n0n";
       };
 
       installFlags = [ "PREFIX=$(out)" ];
--- a/package/rpm/m8c.spec
+++ b/package/rpm/m8c.spec
@@ -1,5 +1,5 @@
 Name:           m8c
-Version:        1.5.5
+Version:        1.6.0
 Release:        1%{?dist}
 Summary:        m8c is a client for Dirtywave M8 music tracker's headless mode
 
--- a/src/input.c
+++ b/src/input.c
@@ -487,7 +487,7 @@
   // Query for SDL events
   handle_sdl_events(conf);
 
-  if (keycode == (key_start | key_select | key_opt | key_edit)) {
+  if (!keyjazz_enabled && keycode == (key_start | key_select | key_opt | key_edit)) {
     key = (input_msg_s){special, msg_reset_display};
   }
 
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,17 @@
 void close_serial_port() { disconnect(); }
 
 int main(int argc, char *argv[]) {
+
+  if(argc == 2 && strcmp(argv[1], "--list") == 0) {
+    return list_devices();
+  }
+
+  char *preferred_device = NULL;
+  if (argc == 3 && strcmp(argv[1], "--dev") == 0) {
+    preferred_device = argv[2];
+    SDL_Log("Using preferred device %s.\n", preferred_device);
+  }
+
   // Initialize the config to defaults read in the params from the
   // configfile if present
   config_params_s conf = init_config();
@@ -66,7 +77,7 @@
   // First device detection to avoid SDL init if it isn't necessary. To be run
   // only if we shouldn't wait for M8 to be connected.
   if (conf.wait_for_device == 0) {
-    if (init_serial(1) == 0) {
+    if (init_serial(1, preferred_device) == 0) {
       SDL_free(serial_buf);
       return -1;
     }
@@ -86,7 +97,7 @@
   // main loop begin
   do {
     // try to init serial port
-    int port_inited = init_serial(1);
+    int port_inited = init_serial(1, preferred_device);
     // if port init was successful, try to enable and reset display
     if (port_inited == 1 && enable_and_reset_display() == 1) {
       // if audio routing is enabled, try to initialize audio devices
@@ -132,7 +143,7 @@
         // Poll for M8 device every second
         if (port_inited == 0 && (SDL_GetTicks() - ticks_poll_device > 1000)) {
           ticks_poll_device = SDL_GetTicks();
-          if (run == WAIT_FOR_DEVICE && init_serial(0) == 1) {
+          if (run == WAIT_FOR_DEVICE && init_serial(0, preferred_device) == 1) {
 
             if (conf.audio_enabled == 1) {
               if (audio_init(conf.audio_buffer_size, conf.audio_device_name) ==
--- a/src/serial.c
+++ b/src/serial.c
@@ -35,6 +35,27 @@
   return 0;
 }
 
+int list_devices() {
+  struct sp_port **port_list;
+  enum sp_return result = sp_list_ports(&port_list);
+
+  if (result != SP_OK) {
+    SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "sp_list_ports() failed!\n");
+    abort();
+  }
+
+  for (int i = 0; port_list[i] != NULL; i++) {
+    struct sp_port *port = port_list[i];
+
+    if (detect_m8_serial_device(port)) {
+      SDL_Log("Found M8 device: %s", sp_get_port_name(port));
+    }
+  }
+
+  sp_free_port_list(port_list);
+  return 0;
+}
+
 // Checks for connected devices and whether the specified device still exists
 int check_serial_port() {
 
@@ -68,7 +89,7 @@
   return device_found;
 }
 
-int init_serial(int verbose) {
+int init_serial(int verbose, char *preferred_device) {
   if (m8_port != NULL) {
     // Port is already initialized
     return 1;
@@ -95,8 +116,13 @@
     struct sp_port *port = port_list[i];
 
     if (detect_m8_serial_device(port)) {
-      SDL_Log("Found M8 in %s.\n", sp_get_port_name(port));
+      char *port_name = sp_get_port_name(port);
+      SDL_Log("Found M8 in %s.\n", port_name);
       sp_copy_port(port, &m8_port);
+      if (preferred_device != NULL && strcmp(preferred_device, port_name) == 0) {
+        SDL_Log("Found preferred device, breaking");
+        break;
+      }
     }
   }
 
--- a/src/serial.h
+++ b/src/serial.h
@@ -14,7 +14,8 @@
 #define serial_read_size 512
 #endif
 
-int init_serial(int verbose);
+int init_serial(int verbose, char *preferred_device);
+int list_devices();
 int check_serial_port();
 int reset_display();
 int enable_and_reset_display();
--