source: roaraudio/plugins/universal/filter-slfi-trigger.c @ 5996:9334f80dfef2

Last change on this file since 5996:9334f80dfef2 was 5996:9334f80dfef2, checked in by phi, 10 years ago

added SLFI filter "trigger"

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   self->active = active = 1;
91  } else if ( event[i] == (self->event|ROAR_ROARDMX_ETYPE_OFF) ) {
92   self->active = active = 0;
93  }
94 }
95
96 if ( !active )
97  return 0;
98
99 return roar_slfi_update(self->filter, universe, size_of_universe, usecspassed, event, eventlen);
100}
101
102static int __ctl(struct roar_slfi_inst * inst, enum roar_slfi_command command, void * argp) {
103 struct slfi_trigger * self = inst->userdata;
104
105 switch (command) {
106  case ROAR_SLFI_CMD_PUSH:
107    if ( roar_slfi_ref(argp) == -1 )
108     return -1;
109    roar_slfi_cb_set_event_add(argp, __cb_event_add, inst);
110    self->filter = argp;
111    return 0;
112   break;
113#ifndef DEBUG
114  default:
115   break;
116#endif
117 }
118
119 roar_err_set(ROAR_ERROR_BADRQC);
120 return -1;
121}
122
123static const struct roar_slfi_filter filter[1] = {
124 {
125  .name = "trigger",
126  .description = "Trigger SLFI filter on event",
127  .flags = ROAR_SLFI_FLAG_NONE,
128  .init = __init,
129  .uninit = __uninit,
130  .update = __update,
131  .ctl = __ctl
132 }
133};
134
135ROAR_DL_PLUGIN_REG_SLFI(filter);
136
137// This is the plugin control block.
138ROAR_DL_PLUGIN_START(filter_slfi_trigger) {
139 // Here we set the name and vendor of our plugin.
140 // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV().
141 ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-trigger", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
142
143 // This sets the version of your plugin.
144 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
145
146 // This sets the license of your plugin.
147 // If there is no tag for the license you use you can just
148 // use ROAR_DL_PLUGIN_META_LICENSE().
149 ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0);
150
151 // This sets the author and contact infos.
152 // There are several other macros to do this with other parameters.
153 // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation.
154 ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org");
155
156 // This sets the description for your plugin.
157 ROAR_DL_PLUGIN_META_DESC("This is a container plugin for SLFI filter triggers.");
158
159 // Load filters.
160 ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER);
161
162// This is the end of the control block.
163} ROAR_DL_PLUGIN_END
164
165//ll
Note: See TracBrowser for help on using the repository browser.