[6015] | 1 | //filter-slfi-strobe.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2015 |
---|
[6015] | 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 | struct slfi_strobe { |
---|
| 30 | // config: |
---|
| 31 | ssize_t channel_brightness; |
---|
| 32 | ssize_t channel_frequency; |
---|
| 33 | ssize_t channel_trigger; |
---|
| 34 | uint8_t brightness; |
---|
| 35 | uint8_t frequency; |
---|
| 36 | uint8_t event; |
---|
| 37 | |
---|
| 38 | // runtime: |
---|
| 39 | uint8_t value_brightness; |
---|
| 40 | uint8_t value_frequency; |
---|
| 41 | uint8_t value_trigger; |
---|
| 42 | }; |
---|
| 43 | |
---|
| 44 | static int __init(struct roar_slfi_inst * inst, const struct roar_keyval * para, ssize_t paralen) { |
---|
| 45 | struct slfi_strobe * self = roar_mm_malloc(sizeof(struct slfi_strobe)); |
---|
| 46 | const struct roar_keyval * kv; |
---|
| 47 | ssize_t i; |
---|
| 48 | |
---|
| 49 | if ( self == NULL ) |
---|
| 50 | return -1; |
---|
| 51 | |
---|
| 52 | memset(self, 0, sizeof(*self)); |
---|
| 53 | self->channel_brightness = -1; |
---|
| 54 | self->channel_frequency = -1; |
---|
| 55 | self->channel_trigger = -1; |
---|
| 56 | self->brightness = 255; |
---|
| 57 | self->frequency = 64; |
---|
| 58 | self->event = ROAR_ROARDMX_EVENT_STROBE; |
---|
| 59 | inst->userdata = self; |
---|
| 60 | |
---|
| 61 | for (i = 0; i < paralen; i++) { |
---|
| 62 | kv = &(para[i]); |
---|
| 63 | if ( kv->key == NULL || kv->value == NULL ) |
---|
| 64 | continue; |
---|
| 65 | if ( !strcmp(kv->key, "event") ) { |
---|
| 66 | self->event = roar_roardmx_str2event(kv->value) & ROAR_ROARDMX_MASK_EVENT; |
---|
| 67 | } else if ( !strcmp(kv->key, "brightness") ) { |
---|
| 68 | self->brightness = atoi(kv->value); |
---|
| 69 | } else if ( !strcmp(kv->key, "frequency") ) { |
---|
| 70 | self->frequency = atoi(kv->value); |
---|
| 71 | } else if ( !strcmp(kv->key, "brightnesschannel") ) { |
---|
| 72 | self->channel_brightness = atoi(kv->value); |
---|
| 73 | } else if ( !strcmp(kv->key, "frequencychannel") ) { |
---|
| 74 | self->channel_frequency = atoi(kv->value); |
---|
| 75 | } else if ( !strcmp(kv->key, "triggerchannel") ) { |
---|
| 76 | self->channel_trigger = atoi(kv->value); |
---|
| 77 | } else { |
---|
| 78 | ROAR_WARN("__init(*): Unknown parameter: %s", kv->key); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return 0; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | static inline void __set_channel(uint8_t * universe, ssize_t size_of_universe, ssize_t channel, uint8_t value) { |
---|
| 86 | if ( channel < 0 ) |
---|
| 87 | return; |
---|
| 88 | if ( channel >= size_of_universe ) { |
---|
| 89 | ROAR_WARN("__set_channel(+): Universe too small for filter. Channel %llu not found.", (long long unsigned int)channel); |
---|
| 90 | return; |
---|
| 91 | } |
---|
| 92 | universe[channel] = value; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | 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) { |
---|
| 96 | struct slfi_strobe * self = inst->userdata; |
---|
| 97 | size_t i; |
---|
| 98 | |
---|
| 99 | (void)usecspassed; |
---|
| 100 | |
---|
| 101 | for (i = 0; i < eventlen; i++) { |
---|
| 102 | switch (event[i]) { |
---|
| 103 | case ROAR_ROARDMX_EVENT_STROBE|ROAR_ROARDMX_ETYPE_BEAT: |
---|
| 104 | self->value_trigger += 7; // prime value > 3 for maximum 'random' effect. |
---|
| 105 | break; |
---|
| 106 | case ROAR_ROARDMX_EVENT_STROBE|ROAR_ROARDMX_ETYPE_OFF: |
---|
| 107 | self->value_brightness = 0; |
---|
| 108 | self->value_frequency = 0; |
---|
| 109 | break; |
---|
| 110 | case ROAR_ROARDMX_EVENT_STROBE|ROAR_ROARDMX_ETYPE_ON: |
---|
| 111 | case ROAR_ROARDMX_EVENT_STROBE|ROAR_ROARDMX_ETYPE_HOLD: |
---|
| 112 | self->value_brightness = self->brightness; |
---|
| 113 | self->value_frequency = self->frequency; |
---|
| 114 | break; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | __set_channel(universe, size_of_universe, self->channel_brightness, self->value_brightness); |
---|
| 119 | __set_channel(universe, size_of_universe, self->channel_frequency, self->value_frequency); |
---|
| 120 | __set_channel(universe, size_of_universe, self->channel_trigger, self->value_trigger); |
---|
| 121 | |
---|
| 122 | return 0; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | static const struct roar_slfi_filter filter[1] = { |
---|
| 126 | { |
---|
| 127 | .name = "strobe", |
---|
| 128 | .description = "Controls strobes via events", |
---|
| 129 | .flags = ROAR_SLFI_FLAG_NONE, |
---|
| 130 | .init = __init, |
---|
| 131 | .uninit = NULL, |
---|
| 132 | .update = __update, |
---|
| 133 | .ctl = NULL |
---|
| 134 | } |
---|
| 135 | }; |
---|
| 136 | |
---|
| 137 | ROAR_DL_PLUGIN_REG_SLFI(filter); |
---|
| 138 | |
---|
| 139 | // This is the plugin control block. |
---|
| 140 | ROAR_DL_PLUGIN_START(filter_slfi_strobe) { |
---|
| 141 | // Here we set the name and vendor of our plugin. |
---|
| 142 | // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV(). |
---|
| 143 | ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-strobe", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); |
---|
| 144 | |
---|
| 145 | // This sets the version of your plugin. |
---|
| 146 | ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); |
---|
| 147 | |
---|
| 148 | // This sets the license of your plugin. |
---|
| 149 | // If there is no tag for the license you use you can just |
---|
| 150 | // use ROAR_DL_PLUGIN_META_LICENSE(). |
---|
| 151 | ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); |
---|
| 152 | |
---|
| 153 | // This sets the author and contact infos. |
---|
| 154 | // There are several other macros to do this with other parameters. |
---|
| 155 | // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation. |
---|
| 156 | ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); |
---|
| 157 | |
---|
| 158 | // This sets the description for your plugin. |
---|
| 159 | ROAR_DL_PLUGIN_META_DESC("This is a plugin allows to control common strobes via the strobe event."); |
---|
| 160 | |
---|
| 161 | // Load filters. |
---|
| 162 | ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER); |
---|
| 163 | |
---|
| 164 | // This is the end of the control block. |
---|
| 165 | } ROAR_DL_PLUGIN_END |
---|
| 166 | |
---|
| 167 | //ll |
---|