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