diff options
author | Thomas White <taw@physics.org> | 2023-04-16 15:51:54 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2023-04-16 15:52:17 +0200 |
commit | 6ad376342fd56fcac702956e7046e6dc5adbd5ad (patch) | |
tree | f69ee5de787fa39353c5ef45a9b865f10f68efa2 | |
parent | a4757aef677eac2e991db7e72fecc14a68bb1770 (diff) |
Add initial (osc-send ...)
-rw-r--r-- | guile-osc.c | 39 | ||||
-rw-r--r-- | open-sound-control/api.scm | 5 | ||||
-rw-r--r-- | open-sound-control/client.scm | 24 |
3 files changed, 67 insertions, 1 deletions
diff --git a/guile-osc.c b/guile-osc.c index 5e69738..7c09637 100644 --- a/guile-osc.c +++ b/guile-osc.c @@ -28,6 +28,7 @@ static SCM osc_server_thread_type; static SCM osc_method_type; +static SCM osc_address_type; static void error_callback(int num, const char *msg, const char *path) @@ -54,6 +55,24 @@ static void finalize_osc_server_thread(SCM obj) } +static SCM make_osc_address(SCM port_obj) +{ + lo_address addr; + const char *port = scm_to_utf8_stringn(port_obj, NULL); + addr = lo_address_new(NULL, port); + return scm_make_foreign_object_1(osc_address_type, addr); +} + + +static void finalize_osc_address(SCM addr_obj) +{ + lo_address addr; + scm_assert_foreign_object_type(osc_address_type, addr_obj); + addr = scm_foreign_object_ref(addr_obj, 0); + lo_address_free(addr); +} + + struct method_callback_data { SCM proc; @@ -123,6 +142,20 @@ static SCM add_osc_method(SCM server_obj, SCM path_obj, SCM proc) } +static SCM osc_send(SCM addr_obj, SCM path_obj, SCM rest) +{ + lo_address addr; + char *path; + + scm_assert_foreign_object_type(osc_address_type, addr_obj); + addr = scm_foreign_object_ref(addr_obj, 0); + path = scm_to_utf8_stringn(path_obj, NULL); + lo_send(addr, path, ""); + + return SCM_UNSPECIFIED; +} + + void init_guile_osc() { SCM name, slots; @@ -137,8 +170,14 @@ void init_guile_osc() slots = scm_list_1(scm_from_utf8_symbol("data")); osc_method_type = scm_make_foreign_object_type(name, slots, NULL); + name = scm_from_utf8_symbol("OSCAddress"); + slots = scm_list_1(scm_from_utf8_symbol("data")); + osc_address_type = scm_make_foreign_object_type(name, slots, finalize_osc_address); + scm_c_define_gsubr("make-osc-server-thread", 1, 0, 0, make_osc_server_thread); scm_c_define_gsubr("add-osc-method", 3, 0, 0, add_osc_method); + scm_c_define_gsubr("make-osc-address", 1, 0, 0, make_osc_address); + scm_c_define_gsubr("osc-send", 2, 0, 1, osc_send); scm_add_feature("guile-osc"); } diff --git a/open-sound-control/api.scm b/open-sound-control/api.scm index abd837c..b34b874 100644 --- a/open-sound-control/api.scm +++ b/open-sound-control/api.scm @@ -20,7 +20,10 @@ ;; (define-module (open-sound-control api) #:export (make-osc-server-thread - add-osc-method)) + add-osc-method + + make-osc-address + osc-send)) (if (not (provided? 'guile-osc)) diff --git a/open-sound-control/client.scm b/open-sound-control/client.scm new file mode 100644 index 0000000..f50cfec --- /dev/null +++ b/open-sound-control/client.scm @@ -0,0 +1,24 @@ +;; +;; open-sound-control/client.scm +;; +;; Copyright © 2023 Thomas White <taw@bitwiz.me.uk> +;; +;; This file is part of Guile-OSC. +;; +;; Guile-OSC is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. +;; +(define-module (open-sound-control client) + #:use-module (open-sound-control api) + #:re-export (osc-send + make-osc-address)) |