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 "HvBase.h"
|
chris@160
|
18 #include "HvTable.h"
|
chris@160
|
19
|
chris@160
|
20 #if !HV_WIN
|
chris@160
|
21 #pragma mark - Heavy Table
|
chris@160
|
22 #endif
|
chris@160
|
23
|
chris@160
|
24 int hv_table_resize(HvTable *o, hv_uint32_t newLength) {
|
chris@160
|
25 return hTable_resize(o, newLength);
|
chris@160
|
26 }
|
chris@160
|
27
|
chris@160
|
28 float *hv_table_getBuffer(HvTable *o) {
|
chris@160
|
29 return hTable_getBuffer(o);
|
chris@160
|
30 }
|
chris@160
|
31
|
chris@160
|
32 hv_size_t hv_table_getLength(HvTable *o) {
|
chris@160
|
33 return hTable_getLength(o);
|
chris@160
|
34 }
|
chris@160
|
35
|
chris@160
|
36
|
chris@160
|
37
|
chris@160
|
38 #if !HV_WIN
|
chris@160
|
39 #pragma mark - Heavy Message
|
chris@160
|
40 #endif
|
chris@160
|
41
|
chris@160
|
42 hv_size_t hv_msg_getByteSize (hv_uint32_t numElements) {
|
chris@160
|
43 return msg_getByteSize(numElements);
|
chris@160
|
44 }
|
chris@160
|
45
|
chris@160
|
46 void hv_msg_init(HvMessage *m, int numElements, hv_uint32_t timestamp) {
|
chris@160
|
47 msg_init(m, numElements, timestamp);
|
chris@160
|
48 }
|
chris@160
|
49
|
chris@160
|
50 hv_size_t hv_msg_getNumElements(const HvMessage *const m) {
|
chris@160
|
51 return msg_getNumElements(m);
|
chris@160
|
52 }
|
chris@160
|
53
|
chris@160
|
54 double hv_msg_getTimestamp(const HvMessage *const m) {
|
chris@160
|
55 return msg_getTimestamp(m);
|
chris@160
|
56 }
|
chris@160
|
57
|
chris@160
|
58 void hv_msg_setTimestamp(HvMessage *m, hv_uint32_t timestamp) {
|
chris@160
|
59 msg_setTimestamp(m, timestamp);
|
chris@160
|
60 }
|
chris@160
|
61
|
chris@160
|
62 bool hv_msg_isBang(const HvMessage *const m, int i) {
|
chris@160
|
63 return msg_isBang(m,i);
|
chris@160
|
64 }
|
chris@160
|
65
|
chris@160
|
66 void hv_msg_setBang(HvMessage *m, int i) {
|
chris@160
|
67 msg_setBang(m,i);
|
chris@160
|
68 }
|
chris@160
|
69
|
chris@160
|
70 bool hv_msg_isFloat(const HvMessage *const m, int i) {
|
chris@160
|
71 return msg_isFloat(m, i);
|
chris@160
|
72 }
|
chris@160
|
73
|
chris@160
|
74 float hv_msg_getFloat(const HvMessage *const m, int i) {
|
chris@160
|
75 return msg_getFloat(m,i);
|
chris@160
|
76 }
|
chris@160
|
77
|
chris@160
|
78 void hv_msg_setFloat(HvMessage *m, int i, float f) {
|
chris@160
|
79 msg_setFloat(m,i,f);
|
chris@160
|
80 }
|
chris@160
|
81
|
chris@160
|
82 bool hv_msg_isSymbol(const HvMessage *const m, int i) {
|
chris@160
|
83 return msg_isSymbol(m,i);
|
chris@160
|
84 }
|
chris@160
|
85
|
chris@160
|
86 char *hv_msg_getSymbol(const HvMessage *const m, int i) {
|
chris@160
|
87 return msg_getSymbol(m,i);
|
chris@160
|
88 }
|
chris@160
|
89
|
chris@160
|
90 void hv_msg_setSymbol(HvMessage *m, int i, char *s) {
|
chris@160
|
91 msg_setSymbol(m,i,s);
|
chris@160
|
92 }
|
chris@160
|
93
|
chris@160
|
94 bool hv_msg_isHash(const HvMessage *const m, int i) {
|
chris@160
|
95 return msg_isHash(m, i);
|
chris@160
|
96 }
|
chris@160
|
97
|
chris@160
|
98 unsigned int hv_msg_getHash(const HvMessage *const m, int i) {
|
chris@160
|
99 return msg_getHash(m, i);
|
chris@160
|
100 }
|
chris@160
|
101
|
chris@160
|
102 bool hv_msg_hasFormat(const HvMessage *const m, const char *fmt) {
|
chris@160
|
103 return msg_hasFormat(m, fmt);
|
chris@160
|
104 }
|
chris@160
|
105
|
chris@160
|
106 char *hv_msg_toString(const HvMessage *const m) {
|
chris@160
|
107 return msg_toString(m);
|
chris@160
|
108 }
|
chris@160
|
109
|
chris@160
|
110 HvMessage *hv_msg_copy(HvMessage *m) {
|
chris@160
|
111 return msg_copy(m);
|
chris@160
|
112 }
|
chris@160
|
113
|
chris@160
|
114 void hv_msg_free(HvMessage *m) {
|
chris@160
|
115 msg_free(m);
|
chris@160
|
116 }
|
chris@160
|
117
|
chris@160
|
118
|
chris@160
|
119
|
chris@160
|
120 #if !HV_WIN
|
chris@160
|
121 #pragma mark - Heavy Common
|
chris@160
|
122 #endif
|
chris@160
|
123
|
chris@160
|
124 double hv_getSampleRate(HvBase *c) {
|
chris@160
|
125 return ctx_getSampleRate(c);
|
chris@160
|
126 }
|
chris@160
|
127
|
chris@160
|
128 int hv_getNumInputChannels(HvBase *c) {
|
chris@160
|
129 return ctx_getNumInputChannels(c);
|
chris@160
|
130 }
|
chris@160
|
131
|
chris@160
|
132 int hv_getNumOutputChannels(HvBase *c) {
|
chris@160
|
133 return ctx_getNumOutputChannels(c);
|
chris@160
|
134 }
|
chris@160
|
135
|
chris@160
|
136 const char *hv_getName(HvBase *c) {
|
chris@160
|
137 return ctx_getName(c);
|
chris@160
|
138 }
|
chris@160
|
139
|
chris@160
|
140 void hv_setPrintHook(HvBase *c, void (*f)(double, const char *, const char *, void *)) {
|
chris@160
|
141 ctx_setPrintHook(c, f);
|
chris@160
|
142 }
|
chris@160
|
143
|
chris@160
|
144 void hv_setSendHook(HvBase *c, void (*f)(double, const char *, const HvMessage *const, void *)) {
|
chris@160
|
145 ctx_setSendHook(c, f);
|
chris@160
|
146 }
|
chris@160
|
147
|
chris@160
|
148 void hv_vscheduleMessageForReceiver(HvBase *c, const char *receiverName, const double delayMs, const char *format, ...) {
|
chris@160
|
149 va_list ap;
|
chris@160
|
150 va_start(ap, format);
|
chris@160
|
151
|
chris@160
|
152 const int numElem = (int) hv_strlen(format);
|
chris@160
|
153 HvMessage *m = HV_MESSAGE_ON_STACK(numElem);
|
chris@160
|
154 msg_init(m, numElem, c->blockStartTimestamp + (hv_uint32_t) (hv_max_d(0.0, delayMs)*ctx_getSampleRate(c)/1000.0));
|
chris@160
|
155 for (int i = 0; i < numElem; i++) {
|
chris@160
|
156 switch (format[i]) {
|
chris@160
|
157 case 'b': msg_setBang(m,i); break;
|
chris@160
|
158 case 'f': msg_setFloat(m, i, (float) va_arg(ap, double)); break;
|
chris@160
|
159 case 's': msg_setSymbol(m, i, (char *) va_arg(ap, char *)); break;
|
chris@160
|
160 default: break;
|
chris@160
|
161 }
|
chris@160
|
162 }
|
chris@160
|
163 ctx_scheduleMessageForReceiver(c, receiverName, m);
|
chris@160
|
164
|
chris@160
|
165 va_end(ap);
|
chris@160
|
166 }
|
chris@160
|
167
|
chris@160
|
168 void hv_scheduleMessageForReceiver(HvBase *c, const char *receiverName, double delayMs, HvMessage *m) {
|
chris@160
|
169 hv_assert(delayMs >= 0.0);
|
chris@160
|
170 msg_setTimestamp(m, c->blockStartTimestamp + (hv_uint32_t) (delayMs*ctx_getSampleRate(c)/1000.0));
|
chris@160
|
171 ctx_scheduleMessageForReceiver(c, receiverName, m);
|
chris@160
|
172 }
|
chris@160
|
173
|
chris@160
|
174 HvTable *hv_getTableForName(HvBase *c, const char *tableName) {
|
chris@160
|
175 return ctx_getTableForName(c, tableName);
|
chris@160
|
176 }
|
chris@160
|
177
|
chris@160
|
178 void hv_cancelMessage(HvBase *c, HvMessage *m) {
|
chris@160
|
179 ctx_cancelMessage(c, m, NULL);
|
chris@160
|
180 }
|
chris@160
|
181
|
chris@160
|
182 double hv_getCurrentTime(HvBase *c) {
|
chris@160
|
183 return ((double) c->blockStartTimestamp)/c->sampleRate;
|
chris@160
|
184 }
|
chris@160
|
185
|
chris@160
|
186 void *hv_getUserData(HvBase *c) {
|
chris@160
|
187 return ctx_getUserData(c);
|
chris@160
|
188 }
|
chris@160
|
189
|
chris@160
|
190 void hv_setUserData(HvBase *c, void *userData) {
|
chris@160
|
191 ctx_setUserData(c, userData);
|
chris@160
|
192 }
|
chris@160
|
193
|
chris@160
|
194 void hv_setBasePath(HvBase *c, const char *basePath) {
|
chris@160
|
195 ctx_setBasePath(c, basePath);
|
chris@160
|
196 }
|