chris@163: /** chris@163: * Copyright (c) 2014, 2015, Enzien Audio Ltd. chris@163: * chris@163: * Permission to use, copy, modify, and/or distribute this software for any chris@163: * purpose with or without fee is hereby granted, provided that the above chris@163: * copyright notice and this permission notice appear in all copies. chris@163: * chris@163: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH chris@163: * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY chris@163: * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, chris@163: * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM chris@163: * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR chris@163: * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR chris@163: * PERFORMANCE OF THIS SOFTWARE. chris@163: */ chris@163: chris@163: #include "HvBase.h" chris@163: #include "HvTable.h" chris@163: chris@163: #if !HV_WIN chris@163: #pragma mark - Heavy Table chris@163: #endif chris@163: chris@163: int hv_table_resize(HvTable *o, hv_uint32_t newLength) { chris@163: return hTable_resize(o, newLength); chris@163: } chris@163: chris@163: float *hv_table_getBuffer(HvTable *o) { chris@163: return hTable_getBuffer(o); chris@163: } chris@163: chris@163: hv_size_t hv_table_getLength(HvTable *o) { chris@163: return hTable_getLength(o); chris@163: } chris@163: chris@163: chris@163: chris@163: #if !HV_WIN chris@163: #pragma mark - Heavy Message chris@163: #endif chris@163: chris@163: hv_size_t hv_msg_getByteSize (hv_uint32_t numElements) { chris@163: return msg_getByteSize(numElements); chris@163: } chris@163: chris@163: void hv_msg_init(HvMessage *m, int numElements, hv_uint32_t timestamp) { chris@163: msg_init(m, numElements, timestamp); chris@163: } chris@163: chris@163: hv_size_t hv_msg_getNumElements(const HvMessage *const m) { chris@163: return msg_getNumElements(m); chris@163: } chris@163: chris@163: double hv_msg_getTimestamp(const HvMessage *const m) { chris@163: return msg_getTimestamp(m); chris@163: } chris@163: chris@163: void hv_msg_setTimestamp(HvMessage *m, hv_uint32_t timestamp) { chris@163: msg_setTimestamp(m, timestamp); chris@163: } chris@163: chris@163: bool hv_msg_isBang(const HvMessage *const m, int i) { chris@163: return msg_isBang(m,i); chris@163: } chris@163: chris@163: void hv_msg_setBang(HvMessage *m, int i) { chris@163: msg_setBang(m,i); chris@163: } chris@163: chris@163: bool hv_msg_isFloat(const HvMessage *const m, int i) { chris@163: return msg_isFloat(m, i); chris@163: } chris@163: chris@163: float hv_msg_getFloat(const HvMessage *const m, int i) { chris@163: return msg_getFloat(m,i); chris@163: } chris@163: chris@163: void hv_msg_setFloat(HvMessage *m, int i, float f) { chris@163: msg_setFloat(m,i,f); chris@163: } chris@163: chris@163: bool hv_msg_isSymbol(const HvMessage *const m, int i) { chris@163: return msg_isSymbol(m,i); chris@163: } chris@163: chris@163: char *hv_msg_getSymbol(const HvMessage *const m, int i) { chris@163: return msg_getSymbol(m,i); chris@163: } chris@163: chris@163: void hv_msg_setSymbol(HvMessage *m, int i, char *s) { chris@163: msg_setSymbol(m,i,s); chris@163: } chris@163: chris@163: bool hv_msg_isHash(const HvMessage *const m, int i) { chris@163: return msg_isHash(m, i); chris@163: } chris@163: chris@163: unsigned int hv_msg_getHash(const HvMessage *const m, int i) { chris@163: return msg_getHash(m, i); chris@163: } chris@163: chris@163: bool hv_msg_hasFormat(const HvMessage *const m, const char *fmt) { chris@163: return msg_hasFormat(m, fmt); chris@163: } chris@163: chris@163: char *hv_msg_toString(const HvMessage *const m) { chris@163: return msg_toString(m); chris@163: } chris@163: chris@163: HvMessage *hv_msg_copy(HvMessage *m) { chris@163: return msg_copy(m); chris@163: } chris@163: chris@163: void hv_msg_free(HvMessage *m) { chris@163: msg_free(m); chris@163: } chris@163: chris@163: chris@163: chris@163: #if !HV_WIN chris@163: #pragma mark - Heavy Common chris@163: #endif chris@163: chris@163: double hv_getSampleRate(HvBase *c) { chris@163: return ctx_getSampleRate(c); chris@163: } chris@163: chris@163: int hv_getNumInputChannels(HvBase *c) { chris@163: return ctx_getNumInputChannels(c); chris@163: } chris@163: chris@163: int hv_getNumOutputChannels(HvBase *c) { chris@163: return ctx_getNumOutputChannels(c); chris@163: } chris@163: chris@163: const char *hv_getName(HvBase *c) { chris@163: return ctx_getName(c); chris@163: } chris@163: chris@163: void hv_setPrintHook(HvBase *c, void (*f)(double, const char *, const char *, void *)) { chris@163: ctx_setPrintHook(c, f); chris@163: } chris@163: chris@163: void hv_setSendHook(HvBase *c, void (*f)(double, const char *, const HvMessage *const, void *)) { chris@163: ctx_setSendHook(c, f); chris@163: } chris@163: chris@163: void hv_vscheduleMessageForReceiver(HvBase *c, const char *receiverName, const double delayMs, const char *format, ...) { chris@163: va_list ap; chris@163: va_start(ap, format); chris@163: chris@163: const int numElem = (int) hv_strlen(format); chris@163: HvMessage *m = HV_MESSAGE_ON_STACK(numElem); chris@163: msg_init(m, numElem, c->blockStartTimestamp + (hv_uint32_t) (hv_max_d(0.0, delayMs)*ctx_getSampleRate(c)/1000.0)); chris@163: for (int i = 0; i < numElem; i++) { chris@163: switch (format[i]) { chris@163: case 'b': msg_setBang(m,i); break; chris@163: case 'f': msg_setFloat(m, i, (float) va_arg(ap, double)); break; chris@163: case 's': msg_setSymbol(m, i, (char *) va_arg(ap, char *)); break; chris@163: default: break; chris@163: } chris@163: } chris@163: ctx_scheduleMessageForReceiver(c, receiverName, m); chris@163: chris@163: va_end(ap); chris@163: } chris@163: chris@163: void hv_scheduleMessageForReceiver(HvBase *c, const char *receiverName, double delayMs, HvMessage *m) { chris@163: hv_assert(delayMs >= 0.0); chris@163: msg_setTimestamp(m, c->blockStartTimestamp + (hv_uint32_t) (delayMs*ctx_getSampleRate(c)/1000.0)); chris@163: ctx_scheduleMessageForReceiver(c, receiverName, m); chris@163: } chris@163: chris@163: HvTable *hv_getTableForName(HvBase *c, const char *tableName) { chris@163: return ctx_getTableForName(c, tableName); chris@163: } chris@163: chris@163: void hv_cancelMessage(HvBase *c, HvMessage *m) { chris@163: ctx_cancelMessage(c, m, NULL); chris@163: } chris@163: chris@163: double hv_getCurrentTime(HvBase *c) { chris@163: return ((double) c->blockStartTimestamp)/c->sampleRate; chris@163: } chris@163: chris@163: void *hv_getUserData(HvBase *c) { chris@163: return ctx_getUserData(c); chris@163: } chris@163: chris@163: void hv_setUserData(HvBase *c, void *userData) { chris@163: ctx_setUserData(c, userData); chris@163: } chris@163: chris@163: void hv_setBasePath(HvBase *c, const char *basePath) { chris@163: ctx_setBasePath(c, basePath); chris@163: }