[5986] | 1 | //filter-slfi-alternative.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
| 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <roaraudio.h> |
---|
| 27 | #include <libroarlight/libroarlight.h> |
---|
| 28 | |
---|
| 29 | #define MAX_FILTER 32 |
---|
| 30 | |
---|
| 31 | struct slfi_alternative { |
---|
| 32 | struct roar_slfi_inst * filter[MAX_FILTER]; |
---|
| 33 | size_t filter_len; |
---|
| 34 | size_t current; |
---|
| 35 | ssize_t channel; |
---|
| 36 | uint8_t event; |
---|
| 37 | }; |
---|
| 38 | |
---|
| 39 | static int __cb_event_add(struct roar_slfi_inst * inst, void * userdata, uint8_t event) { |
---|
| 40 | (void)inst; |
---|
| 41 | return roar_slfi_event_add(userdata, event); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | static int __init(struct roar_slfi_inst * inst, const struct roar_keyval * para, ssize_t paralen) { |
---|
| 45 | struct slfi_alternative * self = roar_mm_malloc(sizeof(struct slfi_alternative)); |
---|
| 46 | |
---|
| 47 | (void)para, (void)paralen; |
---|
| 48 | |
---|
| 49 | if ( self == NULL ) |
---|
| 50 | return -1; |
---|
| 51 | |
---|
| 52 | self->filter_len = 0; |
---|
| 53 | self->current = 0; |
---|
| 54 | self->channel = -1; |
---|
| 55 | self->event = ROAR_ROARDMX_EVENT_STEP; |
---|
| 56 | inst->userdata = self; |
---|
| 57 | |
---|
| 58 | return 0; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | static int __uninit(struct roar_slfi_inst * inst) { |
---|
| 62 | struct slfi_alternative * self = inst->userdata; |
---|
| 63 | size_t i; |
---|
| 64 | |
---|
| 65 | for (i = 0; i < self->filter_len; i++) { |
---|
| 66 | roar_slfi_unref(self->filter[i]); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | return 0; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | 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) { |
---|
| 73 | struct slfi_alternative * self = inst->userdata; |
---|
| 74 | size_t i; |
---|
| 75 | |
---|
| 76 | // Don't do anything if we have no childs: |
---|
| 77 | if ( self->filter_len == 0 ) |
---|
| 78 | return 0; |
---|
| 79 | |
---|
| 80 | if ( self->channel == (ssize_t)-1 ) { |
---|
| 81 | for (i = 0; i < eventlen; i++) { |
---|
| 82 | if ( event[i] == self->event ) { |
---|
| 83 | self->current++; |
---|
| 84 | if ( self->current == self->filter_len ) |
---|
| 85 | self->current = 0; |
---|
| 86 | break; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | } else if ( size_of_universe > self->channel ) { |
---|
| 90 | self->current = universe[self->channel] / self->filter_len; |
---|
| 91 | if ( self->current >= self->filter_len ) |
---|
| 92 | self->current = self->filter_len - 1; |
---|
| 93 | } else { |
---|
| 94 | ROAR_WARN("__update(*): Universe too small for filter (source channel=%lu).", (unsigned long int)self->channel); |
---|
| 95 | roar_err_set(ROAR_ERROR_NOENT); |
---|
| 96 | return -1; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | return roar_slfi_update(self->filter[self->current], universe, size_of_universe, usecspassed, event, eventlen); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | static int __ctl(struct roar_slfi_inst * inst, enum roar_slfi_command command, void * argp) { |
---|
| 103 | struct slfi_alternative * self = inst->userdata; |
---|
| 104 | |
---|
| 105 | switch (command) { |
---|
| 106 | case ROAR_SLFI_CMD_PUSH: |
---|
| 107 | if ( self->filter_len == MAX_FILTER ) { |
---|
| 108 | roar_err_set(ROAR_ERROR_NOSPC); |
---|
| 109 | return -1; |
---|
| 110 | } |
---|
| 111 | if ( roar_slfi_ref(argp) == -1 ) |
---|
| 112 | return -1; |
---|
| 113 | roar_slfi_cb_set_event_add(argp, __cb_event_add, inst); |
---|
| 114 | self->filter[self->filter_len++] = argp; |
---|
| 115 | return 0; |
---|
| 116 | break; |
---|
| 117 | #ifndef DEBUG |
---|
| 118 | default: |
---|
| 119 | break; |
---|
| 120 | #endif |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | roar_err_set(ROAR_ERROR_BADRQC); |
---|
| 124 | return -1; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | static const struct roar_slfi_filter filter[1] = { |
---|
| 128 | { |
---|
| 129 | .name = "chain", |
---|
| 130 | .description = "Chain SLFI filter", |
---|
| 131 | .flags = ROAR_SLFI_FLAG_NONE, |
---|
| 132 | .init = __init, |
---|
| 133 | .uninit = __uninit, |
---|
| 134 | .update = __update, |
---|
| 135 | .ctl = __ctl |
---|
| 136 | } |
---|
| 137 | }; |
---|
| 138 | |
---|
| 139 | ROAR_DL_PLUGIN_REG_SLFI(filter); |
---|
| 140 | |
---|
| 141 | // This is the plugin control block. |
---|
| 142 | ROAR_DL_PLUGIN_START(filter_slfi_alternative) { |
---|
| 143 | // Here we set the name and vendor of our plugin. |
---|
| 144 | // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV(). |
---|
| 145 | ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-alternative", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); |
---|
| 146 | |
---|
| 147 | // This sets the version of your plugin. |
---|
| 148 | ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); |
---|
| 149 | |
---|
| 150 | // This sets the license of your plugin. |
---|
| 151 | // If there is no tag for the license you use you can just |
---|
| 152 | // use ROAR_DL_PLUGIN_META_LICENSE(). |
---|
| 153 | ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); |
---|
| 154 | |
---|
| 155 | // This sets the author and contact infos. |
---|
| 156 | // There are several other macros to do this with other parameters. |
---|
| 157 | // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation. |
---|
| 158 | ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); |
---|
| 159 | |
---|
| 160 | // This sets the description for your plugin. |
---|
| 161 | ROAR_DL_PLUGIN_META_DESC("This is a container plugin for SLFI filter alternatives."); |
---|
| 162 | |
---|
| 163 | // Load filters. |
---|
| 164 | ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER); |
---|
| 165 | |
---|
| 166 | // This is the end of the control block. |
---|
| 167 | } ROAR_DL_PLUGIN_END |
---|
| 168 | |
---|
| 169 | //ll |
---|