/** * @ingroup VuoText * Returns the substring of @c string starting at index @c startIndex and spanning @c length Unicode characters. * * @c startIndex is indexed from 1, not 0. * * If @a startIndex is past the end of @a string, returns the empty string. * * If @a startIndex is before the beginning of @a string, deducts the number of characters before * the beginning from @a length, and returns characters starting at the beginning of @a string. * * If @a string has fewer than @a length characters from @a startIndex to the end of @a string, * returns all characters from @a startIndex to the end of @a string. */ VuoText VuoText_substring(const VuoText string, int startIndex, int length) { if (! string || length < 0) return VuoText_make(""); int originalLength = VuoText_length(string); if (startIndex > originalLength) return VuoText_make(""); if (startIndex < 1) { length -= 1 - startIndex; startIndex = 1; } if (startIndex + length - 1 > originalLength) length = originalLength - startIndex + 1; size_t startIndexFromZero = startIndex - 1; CFStringRef s = CFStringCreateWithCString(kCFAllocatorDefault, string, kCFStringEncodingUTF8); CFStringRef ss = CFStringCreateWithSubstring(kCFAllocatorDefault, s, CFRangeMake(startIndexFromZero, length)); VuoText substring = VuoText_makeFromMacString(ss); CFRelease(s); CFRelease(ss); return substring; }
/** * @ingroup VuoText * Decodes the JSON object @c js, expected to contain a UTF-8 string, to create a new value. */ VuoText VuoText_valueFromJson(json_object * js) { const char *textString = ""; if (json_object_get_type(js) == json_type_string) textString = json_object_get_string(js); return VuoText_make(textString); }
/** * @ingroup VuoSyphonServerDescription * Decodes the JSON object @c js to create a new value. * * @eg{ * { * "serverUUID" : "Vuo" * } * } */ VuoSyphonServerDescription VuoSyphonServerDescription_makeFromJson(json_object * js) { VuoSyphonServerDescription server; json_object *o = NULL; if (json_object_object_get_ex(js, "serverUUID", &o)) server.serverUUID = VuoText_makeFromJson(o); else server.serverUUID = VuoText_make(""); if (json_object_object_get_ex(js, "serverName", &o)) server.serverName = VuoText_makeFromJson(o); else server.serverName = VuoText_make(""); if (json_object_object_get_ex(js, "applicationName", &o)) server.applicationName = VuoText_makeFromJson(o); else server.applicationName = VuoText_make(""); return server; }
/** * Returns a perspective camera at (0,0,1), facing along -z, 90 degree FOV, and clip planes at 0.1 and 10.0. */ VuoSceneObject VuoSceneObject_makeDefaultCamera(void) { VuoTransform transform = VuoTransform_makeEuler( VuoPoint3d_make(0,0,1), VuoPoint3d_make(0,0,0), VuoPoint3d_make(1,1,1) ); return VuoSceneObject_makePerspectiveCamera( VuoText_make("default camera"), transform, 90, 0.1, 10.0 ); }
/** * Decodes the JSON object @c js to create a new value. * * @eg{ * { * "id" : -1, * "name" : "" * } * } */ VuoMidiInputDevice VuoMidiInputDevice_makeFromJson(json_object * js) { VuoMidiInputDevice md = {-1,""}; json_object *o = NULL; if (json_object_object_get_ex(js, "id", &o)) md.id = VuoInteger_makeFromJson(o); if (json_object_object_get_ex(js, "name", &o)) md.name = VuoText_makeFromJson(o); else md.name = VuoText_make(""); return md; }
/** * Decodes the JSON object @c js to create a new value. * * @eg{ * { * "id" : -1, * "name" : "" * } * } */ VuoAudioOutputDevice VuoAudioOutputDevice_makeFromJson(json_object *js) { VuoAudioOutputDevice value = {-1,"",0}; json_object *o = NULL; if (json_object_object_get_ex(js, "id", &o)) value.id = VuoInteger_makeFromJson(o); if (json_object_object_get_ex(js, "name", &o)) value.name = VuoText_makeFromJson(o); else value.name = VuoText_make(""); if (json_object_object_get_ex(js, "channelCount", &o)) value.channelCount = VuoInteger_makeFromJson(o); return value; }
/** * @ingroup VuoMathExpression * Decodes the JSON object to create a new value. * * @eg{ * { * "expression" : "y = x + 4" * } * } */ VuoMathExpression VuoMathExpression_makeFromJson(json_object *js) { VuoMathExpression me; json_object *o = NULL; if (json_object_object_get_ex(js, "expression", &o)) { me.expression = VuoText_makeFromJson(o); VuoMathExpressionError error = NULL; me.parser = VuoMathExpressionParser_makeFromSingleExpression(me.expression, &error); free(error); } else { me.expression = VuoText_make(""); me.parser = NULL; } return me; }
/** * @ingroup VuoText * Creates a new UTF-8 C string from @c value, or, if it's more than 30 Unicode characters long, creates an aposiopesis. * * @eg{Hello World!} * @eg{I would like to convey my gree...} */ char * VuoText_summaryFromValue(const VuoText value) { if (!value) return strdup(""); const int maxLength = 30; if (VuoText_length(value) <= maxLength) return strdup(value); VuoText abbreviation = VuoText_substring(value, 1, maxLength); VuoText ellipsis = VuoText_make("..."); VuoText summaryParts[2] = { abbreviation, ellipsis }; VuoText summaryWhole = VuoText_append(summaryParts, 2); char *summary = strdup(summaryWhole); VuoRetain(abbreviation); VuoRelease(abbreviation); VuoRetain(ellipsis); VuoRelease(ellipsis); VuoRetain(summaryWhole); VuoRelease(summaryWhole); return summary; }
/** * Creates a VuoText value from a @c CFStringRef. */ VuoText VuoText_makeFromMacString(CFStringRef cfString) { // http://stackoverflow.com/questions/1609565/whats-the-cfstring-equiv-of-nsstrings-utf8string const char *useUTF8StringPtr = NULL; char *freeUTF8StringPtr = NULL; if ((useUTF8StringPtr = CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8)) == NULL) { CFIndex stringLength = CFStringGetLength(cfString); CFIndex maxBytes = 4 * stringLength + 1; freeUTF8StringPtr = malloc(maxBytes); CFStringGetCString(cfString, freeUTF8StringPtr, maxBytes, kCFStringEncodingUTF8); useUTF8StringPtr = freeUTF8StringPtr; } VuoText text = VuoText_make(useUTF8StringPtr); if (freeUTF8StringPtr != NULL) free(freeUTF8StringPtr); return text; }
/** * @file * vuo.midi.make.device.id node implementation. * * @copyright Copyright © 2012–2014 Kosada Incorporated. * This code may be modified and distributed under the terms of the MIT License. * For more information, see http://vuo.org/license. */ #include "node.h" #include "VuoMidiDevice.h" VuoModuleMetadata({ "title" : "Make MIDI Device from ID", "keywords" : [ "synthesizer", "sequencer", "music", "instrument" ], "version" : "1.0.0", "node": { "isInterface" : false } }); void nodeEvent ( VuoInputData(VuoInteger, {"default":0,"suggestedMin":0}) id, VuoInputData(VuoBoolean, {"default":true}) isInput, VuoOutputData(VuoMidiDevice) device ) { *device = VuoMidiDevice_make(id, VuoText_make(""), isInput); }
} static void resetController(VuoMidiOut outputManager, char cc, VuoRealRegulation controller) { VuoMidiOut_sendController(outputManager, VuoMidiController_make(1, cc, (controller.defaultValue-controller.minimumValue)/(controller.maximumValue-controller.minimumValue) * 127.)); } struct nodeInstanceData *nodeInstanceInit( VuoInputData(VuoRealRegulation) footSwitch, VuoInputData(VuoRealRegulation) footController ) { struct nodeInstanceData *context = (struct nodeInstanceData *)calloc(1,sizeof(struct nodeInstanceData)); VuoRegister(context, free); context->inputDevice = VuoMidiInputDevice_make(-1, VuoText_make("BCF2000")); VuoMidiInputDevice_retain(context->inputDevice); context->inputManager = VuoMidiIn_make(context->inputDevice); VuoRetain(context->inputManager); context->outputDevice = VuoMidiOutputDevice_make(-1, VuoText_make("BCF2000")); VuoMidiOutputDevice_retain(context->outputDevice); context->outputManager = VuoMidiOut_make(context->outputDevice); VuoRetain(context->outputManager); VuoRealRegulation controllers[2] = {footSwitch, footController}; for (int i = 0; i < 2; ++i) { context->controllerSmooth[i] = VuoSmoothInertia_make(controllers[i].defaultValue); VuoRetain(context->controllerSmooth[i]); // Output the initial position during the first time event.
#include "node.h" #include "VuoVideoInputDevice.h" VuoModuleMetadata({ "title" : "Make Video Input", "keywords" : [ "animation", "avi", "dv", "dvc", "h264", "h.264", "mjpeg", "mpeg", "m4v", "mp4", "quicktime", "qt", "aic", "prores", "video", ], "version" : "1.0.0", "node": { "isInterface" : false } }); void nodeEvent ( VuoInputData(VuoText, {"default":"", "name":"Name"}) name, VuoOutputData(VuoVideoInputDevice) device ) { *device = VuoVideoInputDevice_make(VuoText_make(""), name); }
/** * @file * vuo.audio.make.output.id node implementation. * * @copyright Copyright © 2012–2014 Kosada Incorporated. * This code may be modified and distributed under the terms of the MIT License. * For more information, see http://vuo.org/license. */ #include "node.h" #include "VuoAudioOutputDevice.h" VuoModuleMetadata({ "title" : "Make Audio Output from ID", "keywords" : [ "sound", "output", "speaker", "music", "device" ], "version" : "1.0.0", "node" : { "exampleCompositions" : [ ] } }); void nodeEvent ( VuoInputData(VuoInteger, {"default":0,"suggestedMin":0,"name":"ID"}) id, VuoOutputData(VuoAudioOutputDevice) device ) { *device = VuoAudioOutputDevice_make(id, VuoText_make(""), -1); }
"title" : "Store String", "description" : "", "version" : "1.0.0", "dependencies" : [ "VuoText" ] }); VuoText nodeInstanceInit() { return NULL; } void nodeInstanceEvent ( VuoInstanceData(VuoText) instance, VuoOutputData(VuoInteger) outEvent ) { VuoText newInstance = VuoText_make("initializer string"); *instance = newInstance; *outEvent = 0; } void nodeInstanceFini ( VuoInstanceData(VuoText) instance ) { }
"dependencies" : [ "VuoGlContext" ], "node" : { "exampleCompositions" : [ "" ] } }); void nodeEvent ( VuoInputData(VuoText, {"default": "MyFile.txt"}) filePath, VuoOutputData(VuoText) text ) { char *file_contents; long input_file_size; FILE *input_file = fopen(filePath, "rb"); fseek(input_file, 0, SEEK_END); input_file_size = ftell(input_file); rewind(input_file); file_contents = malloc((input_file_size + 1) * (sizeof(char))); fread(file_contents, sizeof(char), input_file_size, input_file); fclose(input_file); file_contents[input_file_size] = 0; *text = VuoText_make(file_contents); free(file_contents); }