//filter-slfi-trigger.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2015 * * This file is part of roard a part of RoarAudio, * a cross-platform sound system for both, home and professional use. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include #include #define MAX_FILTER 32 struct slfi_trigger { struct roar_slfi_inst * filter; uint8_t event; int active; }; static int __cb_event_add(struct roar_slfi_inst * inst, void * userdata, uint8_t event) { (void)inst; return roar_slfi_event_add(userdata, event); } static int __init(struct roar_slfi_inst * inst, const struct roar_keyval * para, ssize_t paralen) { struct slfi_trigger * self = roar_mm_malloc(sizeof(struct slfi_trigger)); const struct roar_keyval * kv; ssize_t i; if ( self == NULL ) return -1; self->filter = NULL; self->event = ROAR_ROARDMX_EVENT_STEP; self->active = 0; inst->userdata = self; for (i = 0; i < paralen; i++) { kv = &(para[i]); if ( kv->key == NULL || kv->value == NULL ) continue; if ( !strcmp(kv->key, "event") ) { self->event = roar_roardmx_str2event(kv->value); } else { ROAR_WARN("__init(*): Unknown parameter: %s", kv->key); } } return 0; } static int __uninit(struct roar_slfi_inst * inst) { struct slfi_trigger * self = inst->userdata; roar_slfi_unref(self->filter); return 0; } static int __update(struct roar_slfi_inst * inst, uint8_t * universe, ssize_t size_of_universe, int32_t usecspassed, const uint8_t * event, size_t eventlen) { struct slfi_trigger * self = inst->userdata; size_t i; int active = self->active; // Don't do anything if we have no child: if ( self->filter == NULL ) return 0; for (i = 0; i < eventlen; i++) { if ( event[i] == self->event ) { active = 1; } else if ( event[i] == (self->event|ROAR_ROARDMX_ETYPE_ON) || event[i] == (self->event|ROAR_ROARDMX_ETYPE_HOLD) ) { self->active = active = 1; } else if ( event[i] == (self->event|ROAR_ROARDMX_ETYPE_OFF) ) { self->active = active = 0; } } if ( !active ) return 0; return roar_slfi_update(self->filter, universe, size_of_universe, usecspassed, event, eventlen); } static int __ctl(struct roar_slfi_inst * inst, enum roar_slfi_command command, void * argp) { struct slfi_trigger * self = inst->userdata; switch (command) { case ROAR_SLFI_CMD_PUSH: if ( roar_slfi_ref(argp) == -1 ) return -1; roar_slfi_cb_set_event_add(argp, __cb_event_add, inst); self->filter = argp; return 0; break; #ifndef DEBUG default: break; #endif } roar_err_set(ROAR_ERROR_BADRQC); return -1; } static const struct roar_slfi_filter filter[1] = { { .name = "trigger", .description = "Trigger SLFI filter on event", .flags = ROAR_SLFI_FLAG_NONE, .init = __init, .uninit = __uninit, .update = __update, .ctl = __ctl } }; ROAR_DL_PLUGIN_REG_SLFI(filter); // This is the plugin control block. ROAR_DL_PLUGIN_START(filter_slfi_trigger) { // Here we set the name and vendor of our plugin. // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV(). ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-trigger", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); // This sets the version of your plugin. ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); // This sets the license of your plugin. // If there is no tag for the license you use you can just // use ROAR_DL_PLUGIN_META_LICENSE(). ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); // This sets the author and contact infos. // There are several other macros to do this with other parameters. // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation. ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); // This sets the description for your plugin. ROAR_DL_PLUGIN_META_DESC("This is a container plugin for SLFI filter triggers."); // Load filters. ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER); // This is the end of the control block. } ROAR_DL_PLUGIN_END //ll