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