source: roaraudio/plugins/universal/filter-slfi-alternative.c @ 5988:8b933c4d57eb

Last change on this file since 5988:8b933c4d57eb was 5988:8b933c4d57eb, checked in by phi, 10 years ago

cleanup

File size: 5.2 KB
Line 
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
31struct 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
39static 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
44static 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 const struct roar_keyval * kv;
47 ssize_t i;
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 for (i = 0; i < paralen; i++) {
59  kv = &(para[i]);
60  if ( kv->key == NULL || kv->value == NULL )
61   continue;
62  if ( !strcmp(kv->key, "channel") ) {
63   self->channel = atoi(kv->value);
64  } else if ( !strcmp(kv->key, "event") ) {
65   self->event = roar_roardmx_str2event(kv->value);
66  } else {
67   ROAR_WARN("__init(*): Unknown parameter: %s", kv->key);
68  }
69 }
70
71 return 0;
72}
73
74static int __uninit(struct roar_slfi_inst * inst) {
75 struct slfi_alternative * self = inst->userdata;
76 size_t i;
77
78 for (i = 0; i < self->filter_len; i++) {
79  roar_slfi_unref(self->filter[i]);
80 }
81
82 return 0;
83}
84
85static 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) {
86 struct slfi_alternative * self = inst->userdata;
87 size_t i;
88
89 // Don't do anything if we have no childs:
90 if ( self->filter_len == 0 )
91  return 0;
92
93 if ( self->channel == (ssize_t)-1 ) {
94  for (i = 0; i < eventlen; i++) {
95   if ( event[i] == self->event ) {
96    self->current++;
97    if ( self->current == self->filter_len )
98     self->current = 0;
99    break;
100   }
101  }
102 } else if ( size_of_universe > self->channel ) {
103  self->current = universe[self->channel] / self->filter_len;
104  if ( self->current >= self->filter_len )
105   self->current = self->filter_len - 1;
106 } else {
107  ROAR_WARN("__update(*): Universe too small for filter (source channel=%lu).", (unsigned long int)self->channel);
108  roar_err_set(ROAR_ERROR_NOENT);
109  return -1;
110 }
111
112 return roar_slfi_update(self->filter[self->current], universe, size_of_universe, usecspassed, event, eventlen);
113}
114
115static int __ctl(struct roar_slfi_inst * inst, enum roar_slfi_command command, void * argp) {
116 struct slfi_alternative * self = inst->userdata;
117
118 switch (command) {
119  case ROAR_SLFI_CMD_PUSH:
120    if ( self->filter_len == MAX_FILTER ) {
121     roar_err_set(ROAR_ERROR_NOSPC);
122     return -1;
123    }
124    if ( roar_slfi_ref(argp) == -1 )
125     return -1;
126    roar_slfi_cb_set_event_add(argp, __cb_event_add, inst);
127    self->filter[self->filter_len++] = argp;
128    return 0;
129   break;
130#ifndef DEBUG
131  default:
132   break;
133#endif
134 }
135
136 roar_err_set(ROAR_ERROR_BADRQC);
137 return -1;
138}
139
140static const struct roar_slfi_filter filter[1] = {
141 {
142  .name = "alternative",
143  .description = "Alternative SLFI filter",
144  .flags = ROAR_SLFI_FLAG_NONE,
145  .init = __init,
146  .uninit = __uninit,
147  .update = __update,
148  .ctl = __ctl
149 }
150};
151
152ROAR_DL_PLUGIN_REG_SLFI(filter);
153
154// This is the plugin control block.
155ROAR_DL_PLUGIN_START(filter_slfi_alternative) {
156 // Here we set the name and vendor of our plugin.
157 // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV().
158 ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-alternative", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
159
160 // This sets the version of your plugin.
161 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
162
163 // This sets the license of your plugin.
164 // If there is no tag for the license you use you can just
165 // use ROAR_DL_PLUGIN_META_LICENSE().
166 ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0);
167
168 // This sets the author and contact infos.
169 // There are several other macros to do this with other parameters.
170 // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation.
171 ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org");
172
173 // This sets the description for your plugin.
174 ROAR_DL_PLUGIN_META_DESC("This is a container plugin for SLFI filter alternatives.");
175
176 // Load filters.
177 ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER);
178
179// This is the end of the control block.
180} ROAR_DL_PLUGIN_END
181
182//ll
Note: See TracBrowser for help on using the repository browser.