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