Subject: [bug#61594] [PATCH][WIP] gnu: Add norns.

From: Antero Mejr <[email-masked]>
Date: Sat, 18 Feb 2023 05:05:10 +0000

* gnu/packages/music.scm (norns): New variable.
---
Launches OK, can't fully test because Supercollider/Jack don't work on my
machine currently. I will try to report back with test results and/or a V2
patch, but not sure when that will happen.
Please apply the libmonome patch first when everything is ready.

 gnu/local.mk                                  |   1 +
 gnu/packages/music.scm                        | 109 ++++++++++++++++++
 .../patches/norns-remove-nonfree-fonts.patch  |  41 +++++++
 3 files changed, 151 insertions(+)
 create mode 100644 gnu/packages/patches/norns-remove-nonfree-fonts.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index aaf125ce7b..4f6ce69e85 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1579,6 +1579,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/network-manager-meson.patch		\
   %D%/packages/patches/nginx-socket-cloexec.patch		\
   %D%/packages/patches/nnpack-system-libraries.patch		\
+  %D%/packages/patches/norns-remove-nonfree-fonts.patch		\
   %D%/packages/patches/nsis-env-passthru.patch			\
   %D%/packages/patches/nss-getcwd-nonnull.patch			\
   %D%/packages/patches/nss-increase-test-timeout.patch		\
diff --git a/gnu/packages/music.scm b/gnu/packages/music.scm
index 7f0e9dd793..9de4faca32 100644
--- a/gnu/packages/music.scm
+++ b/gnu/packages/music.scm
@@ -95,6 +95,7 @@ (define-module (gnu packages music)
   #:use-module (gnu packages audio)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages assembly)
+  #:use-module (gnu packages avahi)
   #:use-module (gnu packages backup)
   #:use-module (gnu packages base) ;libbdf
   #:use-module (gnu packages bash)
@@ -151,6 +152,7 @@ (define-module (gnu packages music)
   #:use-module (gnu packages mpd)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages netpbm)
+  #:use-module (gnu packages networking)
   #:use-module (gnu packages pcre)
   #:use-module (gnu packages pdf)
   #:use-module (gnu packages perl)
@@ -7115,6 +7117,113 @@ (define-public libmonome
 FFI.")
     (license license:isc)))
 
+(define-public norns
+  (package
+    (name "norns")
+    (version "2.7.3")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/monome/norns")
+             (commit (string-append "v" version))
+             (recursive? #t)))
+       (file-name (git-file-name name version))
+       (patches (search-patches
+                 "norns-remove-nonfree-fonts.patch"))
+       (modules '((guix build utils)))
+       (snippet #~(begin (delete-file-recursively "third-party")
+                         (delete-file "sc/install.sh") ;do this manually
+                         (for-each delete-file ;remove non-free vera font
+                                   (find-files "resources" "[V|v]era*"))
+                         (substitute* "wscript"
+                           (("'VERSION_HASH', get_version_hash\\(\\)")
+                            "'VERSION_HASH', ''")
+                           (("lua53") "lua-5.3")
+                           (("bld\\.recurse\\('third-party'\\)") ""))
+                         (substitute* "matron/wscript"
+                           (("matron_libs = \\[")
+                            "matron_libs = ['lua', 'abl_link',"))
+                         (substitute* "matronrc.lua" ;run SDL version
+                           (("-- _boot\\.add_io\\('input:sdl', \\{\\}\\)")
+                            "_boot.add_io('input:sdl', {})")
+                           (("^init_norns")
+                            "init_desktop"))))
+       (sha256
+        (base32 "1y8hiy0dlv7c66q874znfsgl0ndlddfm81dgyvd5rz8f8g8iqavp"))))
+    (build-system waf-build-system)
+    (arguments
+     (list #:tests? #f ;no target
+           #:configure-flags #~(list "--desktop")
+           #:phases #~(modify-phases %standard-phases
+                        (add-after 'unpack 'patch-src
+                          (lambda _
+                            (substitute* "sc/norns-config.sc"
+                              (("Platform\\.userHomeDir")
+                               (string-append #$output "/share/norns/sc")))
+                            (substitute* "matron/src/hardware/screen.c"
+                              (("%s/norns/resources/%s\", getenv\\(\"HOME\"\\),")
+                               (string-append
+                                #$output "/share/norns/resources/%s\",")))
+                            (substitute* "matron/wscript"
+                              (("\\.\\./third-party/link/extensions/abl_link/include")
+                               (string-append
+                                #$(this-package-input "ableton-link")
+                                "/include/extensions/abl_link")))))
+                        (add-before 'build 'set-desktop-env
+                          (lambda _
+                            (setenv "NORNS_DESKTOP" "true")))
+                        (add-after 'install 'install-resources
+                          (lambda _
+                            (let ((scdir (string-append
+                                          #$output "/share/norns/sc"))
+                                  (fontdir (string-append
+                                            #$output "/share/norns/resources")))
+                              (mkdir-p scdir)
+                              (copy-recursively "sc" scdir)
+                              (mkdir-p fontdir)
+                              (copy-recursively "resources" fontdir)
+                              (install-file
+                               "matronrc.lua"
+                               (string-append #$output "/share/norns")))))
+                        (add-after 'install 'install-docs
+                          (lambda _
+                            ;; TODO: build docs using ldoc, luarocks
+                            (copy-recursively "doc" (string-append
+                                                     #$output "/share/doc")))))))
+    (native-inputs (list pkg-config))
+    (inputs (list ableton-link
+                  alsa-lib
+                  avahi
+                  cairo
+                  eudev
+                  jack-2
+                  libevdev
+                  liblo
+                  libmonome
+                  libsndfile
+                  lua
+                  nanomsg
+                  ncurses
+                  readline
+                  sdl2))
+    (home-page "https://monome.org/docs/norns/")
+    (synopsis "Desktop version of the norns sound computer")
+    (description "The package provides a SDL implementation of norns, the sound
+computer that dynamically runs scripts and
+@acronym{DSP, Digital Signal Processors}, such as:
+@itemize
+@item sample-cutter
+@item polysynth
+@item algorithmic drum machine
+@item drone box
+@item granulator
+@item asynchronous looper
+@item polyphasic sequencer
+@end itemize")
+    (license (list license:gpl3 ;code
+                   license:asl2.0)))) ;Roboto font
+
 ;;;
 ;;; Avoid adding new packages to the end of this file. To reduce the chances
 ;;; of a merge conflict, place them above by existing packages with similar
diff --git a/gnu/packages/patches/norns-remove-nonfree-fonts.patch b/gnu/packages/patches/norns-remove-nonfree-fonts.patch
new file mode 100644
index 0000000000..716fd435be
--- /dev/null
+++ b/gnu/packages/patches/norns-remove-nonfree-fonts.patch
@@ -0,0 +1,41 @@
+Author: Antero Mejr <[email-masked]>
+Notes: It appears that the Bitstream Vera license restricts commercial
+redistribution so patch those fonts out.
+
+diff --git a/matron/src/hardware/screen.c b/matron/src/hardware/screen.c
+index d0cf86e0..1fe494ec 100644
+--- a/matron/src/hardware/screen.c
++++ b/matron/src/hardware/screen.c
+@@ -31,7 +31,7 @@
+     }
+ #endif
+ 
+-#define NUM_FONTS 67
++#define NUM_FONTS 57
+ #define NUM_OPS 29
+ 
+ static char font_path[NUM_FONTS][32];
+@@ -107,21 +107,11 @@ void screen_init(void) {
+     strcpy(font_path[11], "Roboto-MediumItalic.ttf");
+     strcpy(font_path[12], "Roboto-BoldItalic.ttf");
+     strcpy(font_path[13], "Roboto-BlackItalic.ttf");
+-    strcpy(font_path[14], "VeraBd.ttf");
+-    strcpy(font_path[15], "VeraBI.ttf");
+-    strcpy(font_path[16], "VeraIt.ttf");
+-    strcpy(font_path[17], "VeraMoBd.ttf");
+-    strcpy(font_path[18], "VeraMoBI.ttf");
+-    strcpy(font_path[19], "VeraMoIt.ttf");
+-    strcpy(font_path[20], "VeraMono.ttf");
+-    strcpy(font_path[21], "VeraSeBd.ttf");
+-    strcpy(font_path[22], "VeraSe.ttf");
+-    strcpy(font_path[23], "Vera.ttf");
+     //------------------
+     // bitmap fonts
+-    strcpy(font_path[24], "bmp/tom-thumb.bdf");
++    strcpy(font_path[14], "bmp/tom-thumb.bdf");
+     // FIXME: this is totally silly...
+-    int i = 25;
++    int i = 15;
+     strcpy(font_path[i++], "bmp/creep.bdf");
+     strcpy(font_path[i++], "bmp/ctrld-fixed-10b.bdf");
+     strcpy(font_path[i++], "bmp/ctrld-fixed-10r.bdf");
-- 
2.38.1