annotate projects/heavy/hello-world/HvBase.h @ 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 #ifndef _HEAVY_BASE_H_
chris@160 18 #define _HEAVY_BASE_H_
chris@160 19
chris@160 20 #include "MessageQueue.h"
chris@160 21 #include "Utils.h"
chris@160 22
chris@160 23 #define Base(_x) ((HvBase *) _x)
chris@160 24
chris@160 25 typedef struct HvBase {
chris@160 26 int numInputChannels;
chris@160 27 int numOutputChannels;
chris@160 28 double sampleRate;
chris@160 29 hv_uint32_t blockStartTimestamp;
chris@160 30 unsigned int numBytes; // the total number of bytes allocated for this patch
chris@160 31 void (*f_scheduleMessageForReceiver)(struct HvBase *const, const char *, HvMessage *);
chris@160 32 struct HvTable *(*f_getTableForHash)(struct HvBase *const, hv_uint32_t);
chris@160 33 MessageQueue mq;
chris@160 34 void (*printHook)(double, const char *, const char *, void *);
chris@160 35 void (*sendHook)(double, const char *, const HvMessage *const, void *);
chris@160 36 char *basePath;
chris@160 37 void *userData;
chris@160 38 const char *name;
chris@160 39 } HvBase;
chris@160 40
chris@160 41 /**
chris@160 42 * Schedule a message in the message queue according to its timestamp.
chris@160 43 * The copy of the message added to the queue is returned.
chris@160 44 */
chris@160 45 static inline HvMessage *ctx_scheduleMessage(HvBase *_c, const HvMessage *const m,
chris@160 46 void (*sendMessage)(HvBase *, int, const HvMessage *), int outletIndex) {
chris@160 47 return mq_addMessageByTimestamp(&_c->mq, (HvMessage *) m, outletIndex, sendMessage);
chris@160 48 }
chris@160 49
chris@160 50 static inline void ctx_scheduleMessageForReceiver(HvBase *const _c,
chris@160 51 const char *name, HvMessage *m) {
chris@160 52 _c->f_scheduleMessageForReceiver(_c, name, m);
chris@160 53 }
chris@160 54
chris@160 55 void ctx_scheduleMessageForReceiverV(HvBase *const _c, const char *name,
chris@160 56 const hv_uint32_t timestamp, const char *format, ...);
chris@160 57
chris@160 58 void ctx_cancelMessage(HvBase *_c, HvMessage *m,
chris@160 59 void (*sendMessage)(HvBase *, int, const HvMessage *));
chris@160 60
chris@160 61 static inline int ctx_millisecondsToSamples(HvBase *_c, float timeInMs) {
chris@160 62 return (int) (timeInMs * _c->sampleRate / 1000.0);
chris@160 63 }
chris@160 64
chris@160 65 static inline double ctx_samplesToMilliseconds(HvBase *_c, int samples) {
chris@160 66 return 1000.0 * samples / _c->sampleRate;
chris@160 67 }
chris@160 68
chris@160 69 static inline double ctx_getSampleRate(HvBase *_c) {
chris@160 70 return _c->sampleRate;
chris@160 71 }
chris@160 72
chris@160 73 static inline int ctx_getNumInputChannels(HvBase *_c) {
chris@160 74 return _c->numInputChannels;
chris@160 75 }
chris@160 76
chris@160 77 static inline int ctx_getNumOutputChannels(HvBase *_c) {
chris@160 78 return _c->numOutputChannels;
chris@160 79 }
chris@160 80
chris@160 81 static inline const char *ctx_getName(HvBase *_c) {
chris@160 82 return _c->name;
chris@160 83 }
chris@160 84
chris@160 85 /** Returns the first sample of the block. */
chris@160 86 static inline hv_uint32_t ctx_getBlockStartTimestamp(HvBase *_c) {
chris@160 87 return _c->blockStartTimestamp;
chris@160 88 }
chris@160 89
chris@160 90 static inline void ctx_setPrintHook(HvBase *const _c, void (*f)(double,
chris@160 91 const char *, const char *, void *)) {
chris@160 92 _c->printHook = f;
chris@160 93 }
chris@160 94
chris@160 95 static inline void ctx_setSendHook(HvBase *const _c, void (*f)(double, const char *, const HvMessage *const, void *)) {
chris@160 96 _c->sendHook = f;
chris@160 97 }
chris@160 98
chris@160 99 static inline void *ctx_getUserData(HvBase *const _c) {
chris@160 100 return _c->userData;
chris@160 101 }
chris@160 102
chris@160 103 static inline void ctx_setUserData(HvBase *const _c, void *userData) {
chris@160 104 _c->userData = userData;
chris@160 105 }
chris@160 106
chris@160 107 void ctx_setBasePath(HvBase *const _c, const char *basePath);
chris@160 108
chris@160 109 static inline const char *ctx_getBasePath(HvBase *const _c) {
chris@160 110 return _c->basePath;
chris@160 111 }
chris@160 112
chris@160 113 static inline struct HvTable *ctx_getTableForHash(HvBase *const _c, hv_uint32_t h) {
chris@160 114 return _c->f_getTableForHash(_c, h);
chris@160 115 }
chris@160 116
chris@160 117 static inline struct HvTable *ctx_getTableForName(HvBase *const _c, const char *tableName) {
chris@160 118 return ctx_getTableForHash(_c, msg_symbolToHash(tableName));
chris@160 119 }
chris@160 120
chris@160 121 /** Returns the total number of bytes allocated for this patch. */
chris@160 122 static inline unsigned int ctx_getNumBytes(HvBase *_c) {
chris@160 123 return _c->numBytes;
chris@160 124 }
chris@160 125
chris@160 126 #endif // _HEAVY_BASE_H_