source: roaraudio/plugins/universal/filter-slfi-static.c @ 5989:52a7d246b355

Last change on this file since 5989:52a7d246b355 was 5989:52a7d246b355, checked in by phi, 10 years ago

added SLFI filter "static"

File size: 5.1 KB
Line 
1//filter-slfi-static.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_EVENTS   8
30#define MAX_RANGES  32
31
32struct slfi_range {
33 ssize_t start;
34 ssize_t end;
35 uint8_t value;
36};
37
38struct slfi_static {
39 uint8_t event[MAX_EVENTS];
40 size_t event_len;
41 struct slfi_range range[MAX_RANGES];
42 size_t range_len;
43};
44
45static struct slfi_range __parse_range(const char * str) {
46 struct slfi_range range = {0, 0, 0};
47 char * buf = roar_mm_strdup(str);
48 char * value;
49 char * end;
50
51 if ( buf == NULL ) {
52  ROAR_ERR("__parse_range(*): Can not allocate memory. Bad.");
53  return range;
54 }
55
56 value = strstr(buf, ":");
57 if ( value != NULL ) {
58  *value = 0;
59  value++;
60  range.value = atoi(value);
61 }
62
63 end = strstr(buf, "-");
64 if ( end != NULL ) {
65  *end = 0;
66  end++;
67 }
68
69 range.start = atoi(buf);
70 if ( range.start < 0 )
71  range.start = 0;
72
73 range.end = range.start;
74
75 if ( end != NULL ) {
76  range.end = atoi(end);
77  if ( range.end < range.start )
78   range.end = range.start;
79 }
80
81 roar_mm_free(buf);
82 return range;
83}
84
85static int __init(struct roar_slfi_inst * inst, const struct roar_keyval * para, ssize_t paralen) {
86 struct slfi_static * self = roar_mm_malloc(sizeof(struct slfi_static));
87 const struct roar_keyval * kv;
88 ssize_t i;
89
90 if ( self == NULL )
91  return -1;
92
93 memset(self, 0, sizeof(*self));
94 inst->userdata = self;
95
96 for (i = 0; i < paralen; i++) {
97  kv = &(para[i]);
98  if ( kv->key == NULL || kv->value == NULL )
99   continue;
100
101  if ( !strcmp(kv->key, "event") ) {
102   if ( self->event_len == MAX_EVENTS ) {
103    ROAR_WARN("__init(*): Can not add (list is full) event: %s", kv->value);
104    continue;
105   }
106   self->event[self->event_len++] = roar_roardmx_str2event(kv->value);
107  } else if ( !strcmp(kv->key, "set") || !strcmp(kv->key, "sset") || !strcmp(kv->key, "clear") ||
108              !strcmp(kv->key, "rangeset") || !strcmp(kv->key, "rangeclear") ) {
109   if ( self->range_len == MAX_RANGES ) {
110    ROAR_WARN("__init(*): Can not add (list is full) range: %s", kv->value);
111    continue;
112   }
113   self->range[self->range_len++] = __parse_range(kv->value);
114  } else {
115   ROAR_WARN("__init(*): Unknown parameter: %s", kv->key);
116  }
117 }
118
119 return 0;
120}
121
122static 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) {
123 struct slfi_static * self = inst->userdata;
124 size_t i;
125 ssize_t j;
126
127 (void)inst, (void)usecspassed, (void)event, (void)eventlen;
128
129 for (i = 0; i < self->event_len; i++)
130  roar_slfi_event_add(inst, self->event[i]);
131
132 for (i = 0; i < self->range_len; i++) {
133  for (j = self->range[i].start; j <= self->range[i].end; j++) {
134   if ( j >= size_of_universe ) {
135    ROAR_WARN("__update(*): Universe too small for filter (range=%lu, channel=%lu).", (unsigned long int)i, (unsigned long int)j);
136    break;
137   }
138   universe[j] = self->range[i].value;
139  }
140 }
141
142 return 0;
143}
144
145static const struct roar_slfi_filter filter[1] = {
146 {
147  .name = "static",
148  .description = "Static SLFI filter",
149  .flags = ROAR_SLFI_FLAG_ON_UPDATE,
150  .init = __init,
151  .uninit = NULL,
152  .update = __update,
153  .ctl = NULL
154 }
155};
156
157ROAR_DL_PLUGIN_REG_SLFI(filter);
158
159// This is the plugin control block.
160ROAR_DL_PLUGIN_START(filter_slfi_static) {
161 // Here we set the name and vendor of our plugin.
162 // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV().
163 ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-static", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
164
165 // This sets the version of your plugin.
166 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
167
168 // This sets the license of your plugin.
169 // If there is no tag for the license you use you can just
170 // use ROAR_DL_PLUGIN_META_LICENSE().
171 ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0);
172
173 // This sets the author and contact infos.
174 // There are several other macros to do this with other parameters.
175 // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation.
176 ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org");
177
178 // This sets the description for your plugin.
179 ROAR_DL_PLUGIN_META_DESC("This plugin sets static values.");
180
181 // Load filters.
182 ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER);
183
184// This is the end of the control block.
185} ROAR_DL_PLUGIN_END
186
187//ll
Note: See TracBrowser for help on using the repository browser.