comparison projects/heavy/hello-world/ControlVar.c @ 160:5bcf04234f80 heavy-updated

- added -std=c99 to Makefile for user-supplied C files (required for heavy files) - changed heavy core render.cpp file to use latest API and removed all redundant functions (e.g. foleyDesigner/touchkey stuff) - use build_pd.sh to compile and run pd files (-h for usage instructions)
author chnrx <chris.heinrichs@gmail.com>
date Thu, 05 Nov 2015 18:58:26 +0000
parents
children
comparison
equal deleted inserted replaced
159:1e7db6610600 160:5bcf04234f80
1 /**
2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include "ControlVar.h"
18
19 hv_size_t cVar_init_f(ControlVar *o, float k) {
20 o->e.type = FLOAT;
21 o->e.data.f = k;
22 return 0;
23 }
24
25 hv_size_t cVar_init_s(ControlVar *o, const char *s) {
26 o->e.type = HASH;
27 o->e.data.h = msg_symbolToHash(s);
28 return 0;
29 }
30
31 void cVar_free(ControlVar *o) {
32 // nothing to do
33 }
34
35 void cVar_onMessage(HvBase *_c, ControlVar *o, int letIn, const HvMessage *const m,
36 void (*sendMessage)(HvBase *, int, const HvMessage *const)) {
37 switch (letIn) {
38 case 0: {
39 switch (msg_getType(m,0)) {
40 case BANG: {
41 HvMessage *n = HV_MESSAGE_ON_STACK(1);
42 if (o->e.type == FLOAT) msg_initWithFloat(n, msg_getTimestamp(m), o->e.data.f);
43 else if (o->e.type == HASH) msg_initWithHash(n, msg_getTimestamp(m), o->e.data.h);
44 else return;
45 sendMessage(_c, 0, n);
46 break;
47 }
48 case FLOAT: {
49 o->e.type = FLOAT;
50 o->e.data.f = msg_getFloat(m,0);
51 sendMessage(_c, 0, m);
52 break;
53 }
54 case SYMBOL:
55 case HASH: {
56 o->e.type = HASH;
57 o->e.data.h = msg_getHash(m,0);
58 sendMessage(_c, 0, m);
59 break;
60 }
61 default: return;
62 }
63 break;
64 }
65 case 1: {
66 switch (msg_getType(m,0)) {
67 case FLOAT: {
68 o->e.type = FLOAT;
69 o->e.data.f = msg_getFloat(m,0);
70 break;
71 }
72 case SYMBOL:
73 case HASH: {
74 o->e.type = HASH;
75 o->e.data.h = msg_getHash(m,0);
76 break;
77 }
78 default: break;
79 }
80 }
81 default: return;
82 }
83 }