[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/osc 4b28a3c 4/8: Concatenate messages instead of using
From: |
Stefan Monnier |
Subject: |
[elpa] externals/osc 4b28a3c 4/8: Concatenate messages instead of using a temp-buffer and buffer-string |
Date: |
Tue, 1 Dec 2020 18:00:15 -0500 (EST) |
branch: externals/osc
commit 4b28a3c6a2caf0f68bc46c49fa792ddcaa0ada37
Author: Mario Lang <mlang@blind.guru>
Commit: Mario Lang <mlang@blind.guru>
Concatenate messages instead of using a temp-buffer and buffer-string
* packages/osc/osc.el: (osc-float32, osc-int32, osc-string): New functions.
* (osc-insert-float32, osc-insert-int32, osc-insert-string): Remove.
* (osc-send-message): Adjust.
---
osc.el | 59 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/osc.el b/osc.el
index 316b532..e88f135 100644
--- a/osc.el
+++ b/osc.el
@@ -51,10 +51,11 @@
(require 'cl-lib)
-(defun osc-insert-string (string)
- (insert string 0 (make-string (- 3 (% (length string) 4)) 0)))
+(defun osc-string (string)
+ (setq string (encode-coding-string string 'binary))
+ (concat string (make-string (1+ (- 3 (% (length string) 4))) 0)))
-(defun osc-insert-float32 (value)
+(defun osc-float32 (value)
(let (s (e 0) f)
(cond
((= value 0.0)
@@ -73,18 +74,17 @@
(if (= e 0) (while (< (* f (expt 2.0 e)) 1.0) (setq e (1+ e))))
(setq f (round (* (1- (* f (expt 2.0 e))) (expt 2 23)))
e (+ (* -1 e) 127))))
- (insert (+ (lsh s 7) (lsh (logand e #XFE) -1))
- (+ (lsh (logand e #X01) 7) (lsh (logand f #X7F0000) -16))
- (lsh (logand f #XFF00) -8)
- (logand f #XFF))))
+ (unibyte-string (+ (lsh s 7) (lsh (logand e #XFE) -1))
+ (+ (lsh (logand e #X01) 7) (lsh (logand f #X7F0000) -16))
+ (lsh (logand f #XFF00) -8)
+ (logand f #XFF))))
-(defun osc-insert-int32 (value)
+(defun osc-int32 (value)
(let (bytes)
(dotimes (i 4)
(push (% value 256) bytes)
(setq value (/ value 256)))
- (dolist (byte bytes)
- (insert byte))))
+ (apply 'unibyte-string bytes)))
;;;###autoload
(defun osc-make-client (host port)
@@ -99,23 +99,28 @@
;;;###autoload
(defun osc-send-message (client path &rest args)
"Send an OSC message from CLIENT to the specified PATH with ARGS."
- (with-temp-buffer
- (set-buffer-multibyte nil)
- (osc-insert-string path)
- (osc-insert-string
- (apply 'concat "," (mapcar (lambda (arg)
- (cond
- ((floatp arg) "f")
- ((integerp arg) "i")
- ((stringp arg) "s")
- (t (error "Invalid argument: %S" arg))))
- args)))
- (dolist (arg args)
- (cond
- ((floatp arg) (osc-insert-float32 arg))
- ((integerp arg) (osc-insert-int32 arg))
- ((stringp arg) (osc-insert-string arg))))
- (process-send-string client (buffer-string))))
+ (process-send-string
+ client
+ (apply
+ 'concat
+ (osc-string path)
+ (osc-string
+ (apply
+ 'concat ","
+ (mapcar (lambda (arg)
+ (cond
+ ((floatp arg) "f")
+ ((integerp arg) "i")
+ ((stringp arg) "s")
+ (t (error "Invalid argument: %S" arg))))
+ args)))
+ (mapcar
+ (lambda (arg)
+ (cond
+ ((floatp arg) (osc-float32 arg))
+ ((integerp arg) (osc-int32 arg))
+ ((stringp arg) (osc-string arg))))
+ args))))
(defun osc-read-string ()
(let ((pos (point)) string)
- [elpa] branch externals/osc created (now b927860), Stefan Monnier, 2020/12/01
- [elpa] externals/osc 869841d 1/8: Add osc.el., Stefan Monnier, 2020/12/01
- [elpa] externals/osc 4652f37 7/8: * packages/osc/osc.el: Enable lexical-binding, Stefan Monnier, 2020/12/01
- [elpa] externals/osc 4b28a3c 4/8: Concatenate messages instead of using a temp-buffer and buffer-string,
Stefan Monnier <=
- [elpa] externals/osc 8d2b124 3/8: Improve single precision floating point serialisation, Stefan Monnier, 2020/12/01
- [elpa] externals/osc 1a81753 5/8: Support for binary blobs, Stefan Monnier, 2020/12/01
- [elpa] externals/osc 092b443 6/8: Release version 0.2, Stefan Monnier, 2020/12/01
- [elpa] externals/osc 970f417 2/8: * packages/osc/osc.el (osc-filter): Fix up old `cl' name., Stefan Monnier, 2020/12/01
- [elpa] externals/osc b927860 8/8: * .gitignore: New file, Stefan Monnier, 2020/12/01