From 602e45a6de90ec9ab4caea2f2bdd2e3ee60edf22 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 9 Jun 2021 18:12:59 +0200 Subject: Compile libguile-ola using Meson --- compile.sh | 7 --- guile-ola.cpp | 157 ------------------------------------------------------ meson.build | 10 +++- src/guile-ola.cpp | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 165 deletions(-) delete mode 100755 compile.sh delete mode 100644 guile-ola.cpp create mode 100644 src/guile-ola.cpp diff --git a/compile.sh b/compile.sh deleted file mode 100755 index ec5c1c7..0000000 --- a/compile.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -g++ guile-ola.cpp -o libguile-ola.so -lola --shared -fPIC \ - `pkg-config --cflags --libs guile-3.0` - -echo Now run: sudo cp libguile-ola.so /usr/local/lib64/ -echo Then: sudo ldconfig diff --git a/guile-ola.cpp b/guile-ola.cpp deleted file mode 100644 index 63622d0..0000000 --- a/guile-ola.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * guile-ola.cpp - * - * Copyright © 2020-2021 Thomas White - * - * This file is part of Starlet. - * - * Starlet 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 . - * - */ - -#include -#include -#include -#include -#include - -using ola::client::StreamingClient; - - -static SCM dmxbuffer_type; -static SCM streamingclient_type; - - -static SCM make_ola_dmx_buffer() -{ - ola::DmxBuffer *buf = new ola::DmxBuffer; - buf->Blackout(); - return scm_make_foreign_object_1(dmxbuffer_type, buf); -} - - -static void finalize_dmxbuffer(SCM obj) -{ - void *vp; - scm_assert_foreign_object_type(dmxbuffer_type, obj); - vp = scm_foreign_object_ref(obj, 0); - ola::DmxBuffer *buf = static_cast(vp); - delete buf; -} - - -static SCM set_ola_dmx_buffer(SCM obj1, SCM obj2, SCM obj3) -{ - void *vp; - scm_assert_foreign_object_type(dmxbuffer_type, obj1); - vp = scm_foreign_object_ref(obj1, 0); - ola::DmxBuffer *buf = static_cast(vp); - buf->SetChannel(scm_to_int(obj2), scm_to_int(obj3)); - return obj3; -} - - -static SCM ola_dmx_buffers_equal_p(SCM obj1, SCM obj2) -{ - void *vp1; - void *vp2; - scm_assert_foreign_object_type(dmxbuffer_type, obj1); - scm_assert_foreign_object_type(dmxbuffer_type, obj2); - vp1 = scm_foreign_object_ref(obj1, 0); - vp2 = scm_foreign_object_ref(obj2, 0); - ola::DmxBuffer *buf1 = static_cast(vp1); - ola::DmxBuffer *buf2 = static_cast(vp2); - return scm_from_bool(*buf1 == *buf2); -} - - -static SCM make_ola_streaming_client() -{ - StreamingClient *cl; - StreamingClient::Options *opts; - - ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR); - opts = new StreamingClient::Options; - cl = new StreamingClient(opts); - - if ( !cl->Setup() ) { - std::cerr << "Setup failed" << std::endl; - return SCM_BOOL_F; - } else { - std::cerr << "Setup OK" << std::endl; - return scm_make_foreign_object_1(streamingclient_type, cl); - } -} - - -static void finalize_streamingclient(SCM obj) -{ - void *vp; - scm_assert_foreign_object_type(streamingclient_type, obj); - vp = scm_foreign_object_ref(obj, 0); - StreamingClient *cl = static_cast(vp); - delete cl; -} - - -static SCM send_streaming_dmx_data(SCM obj1, SCM obj2, SCM obj3) -{ - void *vp1; - void *vp3; - scm_assert_foreign_object_type(streamingclient_type, obj1); - scm_assert_foreign_object_type(dmxbuffer_type, obj3); - vp1 = scm_foreign_object_ref(obj1, 0); - vp3 = scm_foreign_object_ref(obj3, 0); - StreamingClient *cl = static_cast(vp1); - ola::DmxBuffer *buf = static_cast(vp3); - if ( !cl->SendDmx(scm_to_int(obj2), *buf) ) { - std::cerr << "DMX send failed" << std::endl; - } - return SCM_UNSPECIFIED; -} - - -extern "C" void init_guile_ola() -{ - SCM name, slots; - - name = scm_from_utf8_symbol("OlaDmxBuffer"); - slots = scm_list_1(scm_from_utf8_symbol("data")); - dmxbuffer_type = scm_make_foreign_object_type(name, - slots, - finalize_dmxbuffer); - scm_c_define_gsubr("make-ola-dmx-buffer", - 0, 0, 0, - reinterpret_cast(make_ola_dmx_buffer)); - scm_c_define_gsubr("set-ola-dmx-buffer!", - 3, 0, 0, - reinterpret_cast(set_ola_dmx_buffer)); - scm_c_define_gsubr("ola-dmx-buffers-equal?", - 2, 0, 0, - reinterpret_cast(ola_dmx_buffers_equal_p)); - - name = scm_from_utf8_symbol("OlaStreamingClient"); - slots = scm_list_1(scm_from_utf8_symbol("data")); - streamingclient_type = scm_make_foreign_object_type(name, - slots, - finalize_streamingclient); - scm_c_define_gsubr("make-ola-streaming-client", - 0, 0, 0, - reinterpret_cast(make_ola_streaming_client)); - scm_c_define_gsubr("send-streaming-dmx-data!", - 3, 0, 0, - reinterpret_cast(send_streaming_dmx_data)); - - scm_add_feature("guile-ola"); -} diff --git a/meson.build b/meson.build index f9ca007..be089d8 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ # Meson file for Starlet -project('starlet', 'c', +project('starlet', ['c', 'cpp'], version : '0.1.0', license : 'GPL3+', default_options : ['buildtype=debugoptimized']) @@ -18,6 +18,14 @@ gtk_dep = dependency('gtk+-3.0', required : true) cairo_dep = dependency('cairo', required : true) pango_dep = dependency('pango', required : true) pangocairo_dep = dependency('pangocairo', required : true) +guile_dep = dependency('guile-3.0', required : true) +ola_dep = dependency('libola', required : true) + + +# Guile OLA library +library('guile-ola', ['src/guile-ola.cpp'], + dependencies : [guile_dep, ola_dep], + install: true) # Fixture display tool diff --git a/src/guile-ola.cpp b/src/guile-ola.cpp new file mode 100644 index 0000000..63622d0 --- /dev/null +++ b/src/guile-ola.cpp @@ -0,0 +1,157 @@ +/* + * guile-ola.cpp + * + * Copyright © 2020-2021 Thomas White + * + * This file is part of Starlet. + * + * Starlet 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 . + * + */ + +#include +#include +#include +#include +#include + +using ola::client::StreamingClient; + + +static SCM dmxbuffer_type; +static SCM streamingclient_type; + + +static SCM make_ola_dmx_buffer() +{ + ola::DmxBuffer *buf = new ola::DmxBuffer; + buf->Blackout(); + return scm_make_foreign_object_1(dmxbuffer_type, buf); +} + + +static void finalize_dmxbuffer(SCM obj) +{ + void *vp; + scm_assert_foreign_object_type(dmxbuffer_type, obj); + vp = scm_foreign_object_ref(obj, 0); + ola::DmxBuffer *buf = static_cast(vp); + delete buf; +} + + +static SCM set_ola_dmx_buffer(SCM obj1, SCM obj2, SCM obj3) +{ + void *vp; + scm_assert_foreign_object_type(dmxbuffer_type, obj1); + vp = scm_foreign_object_ref(obj1, 0); + ola::DmxBuffer *buf = static_cast(vp); + buf->SetChannel(scm_to_int(obj2), scm_to_int(obj3)); + return obj3; +} + + +static SCM ola_dmx_buffers_equal_p(SCM obj1, SCM obj2) +{ + void *vp1; + void *vp2; + scm_assert_foreign_object_type(dmxbuffer_type, obj1); + scm_assert_foreign_object_type(dmxbuffer_type, obj2); + vp1 = scm_foreign_object_ref(obj1, 0); + vp2 = scm_foreign_object_ref(obj2, 0); + ola::DmxBuffer *buf1 = static_cast(vp1); + ola::DmxBuffer *buf2 = static_cast(vp2); + return scm_from_bool(*buf1 == *buf2); +} + + +static SCM make_ola_streaming_client() +{ + StreamingClient *cl; + StreamingClient::Options *opts; + + ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR); + opts = new StreamingClient::Options; + cl = new StreamingClient(opts); + + if ( !cl->Setup() ) { + std::cerr << "Setup failed" << std::endl; + return SCM_BOOL_F; + } else { + std::cerr << "Setup OK" << std::endl; + return scm_make_foreign_object_1(streamingclient_type, cl); + } +} + + +static void finalize_streamingclient(SCM obj) +{ + void *vp; + scm_assert_foreign_object_type(streamingclient_type, obj); + vp = scm_foreign_object_ref(obj, 0); + StreamingClient *cl = static_cast(vp); + delete cl; +} + + +static SCM send_streaming_dmx_data(SCM obj1, SCM obj2, SCM obj3) +{ + void *vp1; + void *vp3; + scm_assert_foreign_object_type(streamingclient_type, obj1); + scm_assert_foreign_object_type(dmxbuffer_type, obj3); + vp1 = scm_foreign_object_ref(obj1, 0); + vp3 = scm_foreign_object_ref(obj3, 0); + StreamingClient *cl = static_cast(vp1); + ola::DmxBuffer *buf = static_cast(vp3); + if ( !cl->SendDmx(scm_to_int(obj2), *buf) ) { + std::cerr << "DMX send failed" << std::endl; + } + return SCM_UNSPECIFIED; +} + + +extern "C" void init_guile_ola() +{ + SCM name, slots; + + name = scm_from_utf8_symbol("OlaDmxBuffer"); + slots = scm_list_1(scm_from_utf8_symbol("data")); + dmxbuffer_type = scm_make_foreign_object_type(name, + slots, + finalize_dmxbuffer); + scm_c_define_gsubr("make-ola-dmx-buffer", + 0, 0, 0, + reinterpret_cast(make_ola_dmx_buffer)); + scm_c_define_gsubr("set-ola-dmx-buffer!", + 3, 0, 0, + reinterpret_cast(set_ola_dmx_buffer)); + scm_c_define_gsubr("ola-dmx-buffers-equal?", + 2, 0, 0, + reinterpret_cast(ola_dmx_buffers_equal_p)); + + name = scm_from_utf8_symbol("OlaStreamingClient"); + slots = scm_list_1(scm_from_utf8_symbol("data")); + streamingclient_type = scm_make_foreign_object_type(name, + slots, + finalize_streamingclient); + scm_c_define_gsubr("make-ola-streaming-client", + 0, 0, 0, + reinterpret_cast(make_ola_streaming_client)); + scm_c_define_gsubr("send-streaming-dmx-data!", + 3, 0, 0, + reinterpret_cast(send_streaming_dmx_data)); + + scm_add_feature("guile-ola"); +} -- cgit v1.2.3