source: roaraudio/plugins/universal/filter-slfi-trigger.c @ 5997:9072495573dd

Last change on this file since 5997:9072495573dd was 5997:9072495573dd, checked in by phi, 10 years ago

also allow holding of events

File size: 4.6 KB
Line 
1//filter-slfi-trigger.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_trigger {
32 struct roar_slfi_inst * filter;
33 uint8_t event;
34 int active;
35};
36
37static int __cb_event_add(struct roar_slfi_inst * inst, void * userdata, uint8_t event) {
38 (void)inst;
39 return roar_slfi_event_add(userdata, event);
40}
41
42static int __init(struct roar_slfi_inst * inst, const struct roar_keyval * para, ssize_t paralen) {
43 struct slfi_trigger * self = roar_mm_malloc(sizeof(struct slfi_trigger));
44 const struct roar_keyval * kv;
45 ssize_t i;
46
47 if ( self == NULL )
48  return -1;
49
50 self->filter   = NULL;
51 self->event    = ROAR_ROARDMX_EVENT_STEP;
52 self->active   = 0;
53 inst->userdata = self;
54
55 for (i = 0; i < paralen; i++) {
56  kv = &(para[i]);
57  if ( kv->key == NULL || kv->value == NULL )
58   continue;
59  if ( !strcmp(kv->key, "event") ) {
60   self->event = roar_roardmx_str2event(kv->value);
61  } else {
62   ROAR_WARN("__init(*): Unknown parameter: %s", kv->key);
63  }
64 }
65
66 return 0;
67}
68
69static int __uninit(struct roar_slfi_inst * inst) {
70 struct slfi_trigger * self = inst->userdata;
71
72 roar_slfi_unref(self->filter);
73
74 return 0;
75}
76
77static 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) {
78 struct slfi_trigger * self = inst->userdata;
79 size_t i;
80 int active = self->active;
81
82 // Don't do anything if we have no child:
83 if ( self->filter == NULL )
84  return 0;
85
86 for (i = 0; i < eventlen; i++) {
87  if ( event[i] == self->event ) {
88   active = 1;
89  } else if ( event[i] == (self->event|ROAR_ROARDMX_ETYPE_ON)   ||
90              event[i] == (self->event|ROAR_ROARDMX_ETYPE_HOLD) ) {
91   self->active = active = 1;
92  } else if ( event[i] == (self->event|ROAR_ROARDMX_ETYPE_OFF) ) {
93   self->active = active = 0;
94  }
95 }
96
97 if ( !active )
98  return 0;
99
100 return roar_slfi_update(self->filter, universe, size_of_universe, usecspassed, event, eventlen);
101}
102
103static int __ctl(struct roar_slfi_inst * inst, enum roar_slfi_command command, void * argp) {
104 struct slfi_trigger * self = inst->userdata;
105
106 switch (command) {
107  case ROAR_SLFI_CMD_PUSH:
108    if ( roar_slfi_ref(argp) == -1 )
109     return -1;
110    roar_slfi_cb_set_event_add(argp, __cb_event_add, inst);
111    self->filter = argp;
112    return 0;
113   break;
114#ifndef DEBUG
115  default:
116   break;
117#endif
118 }
119
120 roar_err_set(ROAR_ERROR_BADRQC);
121 return -1;
122}
123
124static const struct roar_slfi_filter filter[1] = {
125 {
126  .name = "trigger",
127  .description = "Trigger SLFI filter on event",
128  .flags = ROAR_SLFI_FLAG_NONE,
129  .init = __init,
130  .uninit = __uninit,
131  .update = __update,
132  .ctl = __ctl
133 }
134};
135
136ROAR_DL_PLUGIN_REG_SLFI(filter);
137
138// This is the plugin control block.
139ROAR_DL_PLUGIN_START(filter_slfi_trigger) {
140 // Here we set the name and vendor of our plugin.
141 // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV().
142 ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-trigger", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
143
144 // This sets the version of your plugin.
145 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
146
147 // This sets the license of your plugin.
148 // If there is no tag for the license you use you can just
149 // use ROAR_DL_PLUGIN_META_LICENSE().
150 ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0);
151
152 // This sets the author and contact infos.
153 // There are several other macros to do this with other parameters.
154 // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation.
155 ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org");
156
157 // This sets the description for your plugin.
158 ROAR_DL_PLUGIN_META_DESC("This is a container plugin for SLFI filter triggers.");
159
160 // Load filters.
161 ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER);
162
163// This is the end of the control block.
164} ROAR_DL_PLUGIN_END
165
166//ll
Note: See TracBrowser for help on using the repository browser.