annotate 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
rev   line source
chris@160 1 /**
chris@160 2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
chris@160 3 *
chris@160 4 * Permission to use, copy, modify, and/or distribute this software for any
chris@160 5 * purpose with or without fee is hereby granted, provided that the above
chris@160 6 * copyright notice and this permission notice appear in all copies.
chris@160 7 *
chris@160 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
chris@160 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
chris@160 10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
chris@160 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
chris@160 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
chris@160 13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
chris@160 14 * PERFORMANCE OF THIS SOFTWARE.
chris@160 15 */
chris@160 16
chris@160 17 #include "ControlVar.h"
chris@160 18
chris@160 19 hv_size_t cVar_init_f(ControlVar *o, float k) {
chris@160 20 o->e.type = FLOAT;
chris@160 21 o->e.data.f = k;
chris@160 22 return 0;
chris@160 23 }
chris@160 24
chris@160 25 hv_size_t cVar_init_s(ControlVar *o, const char *s) {
chris@160 26 o->e.type = HASH;
chris@160 27 o->e.data.h = msg_symbolToHash(s);
chris@160 28 return 0;
chris@160 29 }
chris@160 30
chris@160 31 void cVar_free(ControlVar *o) {
chris@160 32 // nothing to do
chris@160 33 }
chris@160 34
chris@160 35 void cVar_onMessage(HvBase *_c, ControlVar *o, int letIn, const HvMessage *const m,
chris@160 36 void (*sendMessage)(HvBase *, int, const HvMessage *const)) {
chris@160 37 switch (letIn) {
chris@160 38 case 0: {
chris@160 39 switch (msg_getType(m,0)) {
chris@160 40 case BANG: {
chris@160 41 HvMessage *n = HV_MESSAGE_ON_STACK(1);
chris@160 42 if (o->e.type == FLOAT) msg_initWithFloat(n, msg_getTimestamp(m), o->e.data.f);
chris@160 43 else if (o->e.type == HASH) msg_initWithHash(n, msg_getTimestamp(m), o->e.data.h);
chris@160 44 else return;
chris@160 45 sendMessage(_c, 0, n);
chris@160 46 break;
chris@160 47 }
chris@160 48 case FLOAT: {
chris@160 49 o->e.type = FLOAT;
chris@160 50 o->e.data.f = msg_getFloat(m,0);
chris@160 51 sendMessage(_c, 0, m);
chris@160 52 break;
chris@160 53 }
chris@160 54 case SYMBOL:
chris@160 55 case HASH: {
chris@160 56 o->e.type = HASH;
chris@160 57 o->e.data.h = msg_getHash(m,0);
chris@160 58 sendMessage(_c, 0, m);
chris@160 59 break;
chris@160 60 }
chris@160 61 default: return;
chris@160 62 }
chris@160 63 break;
chris@160 64 }
chris@160 65 case 1: {
chris@160 66 switch (msg_getType(m,0)) {
chris@160 67 case FLOAT: {
chris@160 68 o->e.type = FLOAT;
chris@160 69 o->e.data.f = msg_getFloat(m,0);
chris@160 70 break;
chris@160 71 }
chris@160 72 case SYMBOL:
chris@160 73 case HASH: {
chris@160 74 o->e.type = HASH;
chris@160 75 o->e.data.h = msg_getHash(m,0);
chris@160 76 break;
chris@160 77 }
chris@160 78 default: break;
chris@160 79 }
chris@160 80 }
chris@160 81 default: return;
chris@160 82 }
chris@160 83 }