source: roaraudio/plugins/universal/filter-slfi-channel2event.c @ 5994:de2779f48eec

Last change on this file since 5994:de2779f48eec was 5994:de2779f48eec, checked in by phi, 10 years ago

added SLFI filter "channel2event"

File size: 5.2 KB
Line 
1//filter-slfi-channel2event.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 FLAG_BLACKOUT   0x0001
30#define FLAG_FULLON     0x0001
31
32struct slfi_channel2event {
33 ssize_t channel;
34 uint8_t lastvalue;
35 uint8_t event;
36 int flags;
37 int emitting;
38};
39
40static int __str2bool(const char * str) {
41 if ( *str == 'y' || *str == 'j' || *str == '1' || *str == 't' )
42  return 1;
43 return 0;
44}
45
46static int __init(struct roar_slfi_inst * inst, const struct roar_keyval * para, ssize_t paralen) {
47 struct slfi_channel2event * self = roar_mm_malloc(sizeof(struct slfi_channel2event));
48 const struct roar_keyval * kv;
49 ssize_t i;
50
51 if ( self == NULL )
52  return -1;
53
54 self->channel    = -1;
55 self->lastvalue  =  0;
56 self->event      = ROAR_ROARDMX_EVENT_STEP;
57 self->flags      = FLAG_BLACKOUT|FLAG_FULLON;
58 self->emitting   =  0;
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, "channel") ) {
66   self->channel = atoi(kv->value);
67   if ( self->channel < 0 )
68    self->channel = 0;
69  } else if ( !strcmp(kv->key, "event") ) {
70   self->event = roar_roardmx_str2event(kv->value);
71  } else if ( !strcmp(kv->key, "blackout") ) {
72   self->flags |= FLAG_BLACKOUT;
73   if ( !__str2bool(kv->value) )
74    self->flags -= FLAG_BLACKOUT;
75  } else if ( !strcmp(kv->key, "fullon") ) {
76   self->flags |= FLAG_BLACKOUT;
77   if ( !__str2bool(kv->value) )
78    self->flags -= FLAG_BLACKOUT;
79  } else {
80   ROAR_WARN("__init(*): Unknown parameter: %s", kv->key);
81  }
82 }
83
84 return 0;
85}
86
87static 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) {
88 struct slfi_channel2event * self = inst->userdata;
89 register uint8_t value;
90
91 (void)usecspassed, (void)event, (void)eventlen;
92
93 if ( self->channel >= size_of_universe ) {
94  ROAR_WARN("__update(*): Universe too small for filter (source channel=%lu).", (unsigned long int)self->channel);
95  roar_err_set(ROAR_ERROR_INVAL);
96  return -1;
97 }
98
99 value = universe[self->channel];
100 if ( (self->flags & FLAG_BLACKOUT) && value == 0x00 ) {
101  if ( !(self->emitting & FLAG_BLACKOUT) ) {
102   roar_slfi_event_add(inst, ROAR_ROARDMX_EVENT_BLACKOUT|ROAR_ROARDMX_ETYPE_ON);
103   self->emitting |= FLAG_BLACKOUT;
104  }
105 } else if ( (self->flags & FLAG_FULLON) && value == 0xFF ) {
106  if ( !(self->emitting & FLAG_FULLON) ) {
107   roar_slfi_event_add(inst, ROAR_ROARDMX_EVENT_FULLON|ROAR_ROARDMX_ETYPE_ON);
108   self->emitting |= FLAG_FULLON;
109  }
110 } else {
111  if ( self->emitting & FLAG_BLACKOUT ) {
112   roar_slfi_event_add(inst, ROAR_ROARDMX_EVENT_BLACKOUT|ROAR_ROARDMX_ETYPE_OFF);
113   self->emitting -= FLAG_BLACKOUT;
114  }
115
116  if ( self->emitting & FLAG_FULLON ) {
117   roar_slfi_event_add(inst, ROAR_ROARDMX_EVENT_FULLON|ROAR_ROARDMX_ETYPE_OFF);
118   self->emitting -= FLAG_FULLON;
119  }
120
121  if ( value != self->lastvalue )
122   roar_slfi_event_add(inst, self->event);
123  self->lastvalue = value;
124 }
125
126 return 0;
127}
128
129static const struct roar_slfi_filter filter[1] = {
130 {
131  .name = "channel2event",
132  .description = "SLFI filter mapping channel data to events",
133  .flags = ROAR_SLFI_FLAG_ON_UPDATE,
134  .init = __init,
135  .uninit = NULL,
136  .update = __update,
137  .ctl = NULL
138 }
139};
140
141ROAR_DL_PLUGIN_REG_SLFI(filter);
142
143// This is the plugin control block.
144ROAR_DL_PLUGIN_START(filter_slfi_channel2event) {
145 // Here we set the name and vendor of our plugin.
146 // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV().
147 ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-channel2event", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
148
149 // This sets the version of your plugin.
150 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
151
152 // This sets the license of your plugin.
153 // If there is no tag for the license you use you can just
154 // use ROAR_DL_PLUGIN_META_LICENSE().
155 ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0);
156
157 // This sets the author and contact infos.
158 // There are several other macros to do this with other parameters.
159 // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation.
160 ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org");
161
162 // This sets the description for your plugin.
163 ROAR_DL_PLUGIN_META_DESC("This plugin allows to map DMX channel data to RoarDMX events.");
164
165 // Load filters.
166 ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER);
167
168// This is the end of the control block.
169} ROAR_DL_PLUGIN_END
170
171//ll
Note: See TracBrowser for help on using the repository browser.