10 class TTRubyInstance {
26 class TTAudioInstance {
29 TTAudioGraphObject obj;
33 TTAudioInstance(
const TTValue args)
36 obj = TTAudioGraphObject(args);
39 std::cout <<
"Bogus Crap Happened Bros." << std::endl;
45 typedef VALUE (*TTRubyMethod)(...);
53 VALUE TTRubyInitialize(VALUE
self, VALUE className);
54 VALUE TTRubyGetMessages(VALUE
self);
55 VALUE TTRubySendMessage(
int argc, VALUE* argv, VALUE
self);
56 VALUE TTRubyGetAttributes(VALUE
self);
57 VALUE TTRubySetAttribute(VALUE
self, VALUE attributeName, VALUE attributeValue);
58 VALUE TTRubyGetAttribute(VALUE
self, VALUE attributeName);
59 VALUE TTRubyCalculate(VALUE
self, VALUE x);
61 VALUE TTAudioInitialize(
int argc, VALUE* argv, VALUE
self);
62 VALUE TTAudioGetMessages(VALUE
self);
63 VALUE TTAudioSendMessage(
int argc, VALUE* argv, VALUE
self);
64 VALUE TTAudioGetAttributes(VALUE
self);
65 VALUE TTAudioSetAttribute(VALUE
self, VALUE attributeName, VALUE attributeValue);
66 VALUE TTAudioGetAttribute(VALUE
self, VALUE attributeName);
67 VALUE TTAudioReset(VALUE
self);
68 VALUE TTAudioConnect(
int argc, VALUE* argv, VALUE
self);
69 VALUE TTAudioDrop(
int argc, VALUE* argv, VALUE
self);
70 VALUE TTAudioExportMax(VALUE
self, VALUE pathToExportFile);
71 VALUE TTAudioExportCpp(VALUE
self, VALUE pathToExportFile);
93 c = rb_define_class(
"TTObject", rb_cObject);
95 rb_define_method(c,
"initialize", TTRubyMethod(TTRubyInitialize), 1);
96 rb_define_method(c,
"messages?", TTRubyMethod(TTRubyGetMessages), 0);
97 rb_define_method(c,
"send", TTRubyMethod(TTRubySendMessage), -1);
98 rb_define_method(c,
"attributes?", TTRubyMethod(TTRubyGetAttributes), 0);
99 rb_define_method(c,
"set", TTRubyMethod(TTRubySetAttribute), 2);
100 rb_define_method(c,
"get", TTRubyMethod(TTRubyGetAttribute), 1);
101 rb_define_method(c,
"calculate", TTRubyMethod(TTRubyCalculate), 1);
104 gTTRubyInstances =
new TTHash;
111 c = rb_define_class(
"TTAudio", rb_cObject);
113 rb_define_method(c,
"initialize", TTRubyMethod(TTAudioInitialize), -1);
114 rb_define_method(c,
"messages?", TTRubyMethod(TTAudioGetMessages), 0);
115 rb_define_method(c,
"send", TTRubyMethod(TTAudioSendMessage), -1);
116 rb_define_method(c,
"attributes?", TTRubyMethod(TTAudioGetAttributes), 0);
117 rb_define_method(c,
"set", TTRubyMethod(TTAudioSetAttribute), 2);
118 rb_define_method(c,
"get", TTRubyMethod(TTAudioGetAttribute), 1);
119 rb_define_method(c,
"reset_audio", TTRubyMethod(TTAudioReset), 0);
120 rb_define_method(c,
"connect_audio", TTRubyMethod(TTAudioConnect), -1);
121 rb_define_method(c,
"drop_audio", TTRubyMethod(TTAudioDrop), -1);
122 rb_define_method(c,
"export_max", TTRubyMethod(TTAudioExportMax), 1);
123 rb_define_method(c,
"export_cpp", TTRubyMethod(TTAudioExportCpp), 1);
126 gTTAudioInstances =
new TTHash;
136 VALUE TTRubyInitialize(VALUE
self, VALUE className)
141 VALUE classNameStr = StringValue(className);
142 TTSymbol classNameTTStr(RSTRING_PTR(classNameStr));
147 TTRubyInstance* instance;
155 instance =
new TTRubyInstance(classNameTTStr, args);
158 std::cout <<
"Error loading object " << classNameTTStr.c_str() << std::endl;
162 instance->parameterNames =
new TTHash;
163 instance->obj.attributes(names);
165 for (
int i=0; i<n; i++) {
167 nameString = aName.
c_str();
170 instance->parameterNames->append(
TTSymbol(nameString.
c_str()), v);
174 instance->messageNames =
new TTHash;
175 instance->obj.messages(names);
177 for (
int i=0; i<n; i++) {
179 nameString = aName.
c_str();
182 instance->messageNames->append(
TTSymbol(nameString.
c_str()), v);
200 VALUE TTRubyGetMessages(VALUE
self)
202 TTRubyInstance* instance = NULL;
205 VALUE returnValue = rb_float_new(0.0);
212 instance = (TTRubyInstance*)
TTPtr(v[0]);
216 instance->messageNames->getKeys(names);
219 returnValue = rb_ary_new2(size);
222 c = (TTCString)s.
c_str();
223 rb_ary_store(returnValue, i, rb_str_new(c, strlen(c)));
230 VALUE TTRubySendMessage(
int argc, VALUE* argv, VALUE
self)
232 TTRubyInstance* instance = NULL;
234 VALUE messageNameStr;
241 std::cout <<
"ERROR -- TTRuby.send requires at least 1 argument (the name of the message to send)" << std::endl;
245 messageNameStr = StringValue(argv[0]);
246 err = gTTRubyInstances->
lookup(
TTPtr(
self), v_temp);
248 instance = (TTRubyInstance*)
TTPtr(v_temp[0]);
253 messageName = RSTRING_PTR(messageNameStr);
254 instance->messageNames->lookup(messageName, messageNameValue);
255 messageName = messageNameValue[0];
264 for (
int i=1; i<argc; i++) {
265 int t = TYPE(argv[i]);
270 v_in.
append(NUM2DBL(argv[i]));
273 v_in.
append((
int)FIX2LONG(argv[i]));
279 messageArgStr = StringValue(argv[i]);
283 std::cout <<
"TTError: Array arguments for messages not yet supported in Ruby" << std::endl;
287 std::cout <<
"TTError: Object arguments for messages not yet supported in Ruby" << std::endl;
297 err = instance->obj.send(messageName, v_in, v_out);
302 std::cout <<
"TTRubySendMessage: Error " << err << std::endl;
306 int size = v_out.
size();
308 VALUE ret = rb_ary_new2(size + 1);
310 rb_ary_store(ret, 0, err);
311 for (i=0; i<size; i++) {
321 fv = rb_float_new(f);
324 rb_ary_store(ret, i+1, fv);
327 std::cout <<
"objects as return values are not yet supported" << std::endl;
334 c = (TTCString)sp.
c_str();
335 rb_ary_store(ret, i+1, rb_str_new(c, strlen(c)));
344 rb_ary_store(ret, i+1, lv);
356 VALUE TTRubyGetAttributes(VALUE
self)
358 TTRubyInstance* instance = NULL;
361 VALUE returnValue = rb_float_new(0.0);
368 instance = (TTRubyInstance*)
TTPtr(v[0]);
372 instance->parameterNames->getKeys(names);
375 returnValue = rb_ary_new2(size);
378 c = (TTCString)s.
c_str();
379 rb_ary_store(returnValue, i, rb_str_new(c, strlen(c)));
387 VALUE TTRubySetAttribute(VALUE
self, VALUE attributeName, VALUE attributeValue)
389 TTRubyInstance* instance = NULL;
391 VALUE attributeNameStr = StringValue(attributeName);
392 VALUE attributeValueStr;
397 instance = (TTRubyInstance*)
TTPtr(v[0]);
399 int t = TYPE(attributeValue);
405 v.
append(NUM2DBL(attributeValue));
408 v.
append((
int)FIX2LONG(attributeValue));
414 attributeValueStr = StringValue(attributeValue);
418 std::cout <<
"TTError: Array arguments for attributes not yet supported in Ruby" << std::endl;
422 std::cout <<
"TTError: Object arguments for attributes not yet supported in Ruby" << std::endl;
426 std::cout <<
"TTError: Unknown type for arguments to attribute" << std::endl;
431 TTSymbol parameterName = kTTSymEmpty;
434 parameterName = RSTRING_PTR(attributeNameStr);
435 instance->parameterNames->lookup(parameterName, parameterNameValue);
436 parameterNameValue.
get(0, parameterName);
438 err = instance->obj.set(parameterName, v);
441 std::cout <<
"TTRubySetAttribute: Error " << err << std::endl;
448 VALUE TTRubyGetAttribute(VALUE
self, VALUE attributeName)
450 TTRubyInstance* instance = NULL;
452 VALUE attributeNameStr = StringValue(attributeName);
455 VALUE returnValue = rb_float_new(0.0);
461 instance = (TTRubyInstance*)
TTPtr(v[0]);
463 TTSymbol parameterName = kTTSymEmpty;
466 parameterName = RSTRING_PTR(attributeNameStr);
467 instance->parameterNames->lookup(parameterName, parameterNameValue);
468 parameterNameValue.
get(0, parameterName);
470 err = instance->obj.get(parameterName, v);
472 std::cout <<
"TTRubyGetAttribute: Error " << err << std::endl;
478 switch (v[0].type()) {
481 returnValue = rb_float_new(v);
489 returnValue = INT2NUM(v);
493 returnValue = LL2NUM((
TTInt64)v);
500 c = (TTCString)s.
c_str();
501 returnValue = rb_str_new(c, strlen(c));
509 case kNumTTDataTypes:
520 VALUE TTRubyCalculate(VALUE
self, VALUE x)
522 TTRubyInstance* instance = NULL;
525 VALUE returnValue = rb_float_new(0.0);
529 instance = (TTRubyInstance*)
TTPtr(v[0]);
534 err = instance->obj.calculate(fx, fy);
535 returnValue = rb_float_new(fy);
545 #pragma mark Audio Graph Support
549 VALUE TTAudioInitialize(
int argc, VALUE* argv, VALUE
self)
552 std::cout <<
"ERROR -- TTAudio requires at least 1 argument (the name of the object class to create)" << std::endl;
561 for (
int i=0; i<argc; i++) {
562 int t = TYPE(argv[i]);
567 args.
append(NUM2DBL(argv[i]));
570 args.
append((
int)FIX2LONG(argv[i]));
576 messageArgStr = StringValue(argv[i]);
580 std::cout <<
"TTError: Array arguments for messages not yet supported in Ruby" << std::endl;
584 std::cout <<
"TTError: Object arguments for messages not yet supported in Ruby" << std::endl;
593 TTAudioInstance* instance =
new TTAudioInstance(args);
604 instance->parameterNames =
new TTHash;
606 instance->obj.attributes(names);
608 for (
int i=0; i<n; i++) {
610 nameString = aName.
c_str();
613 instance->parameterNames->append(
TTSymbol(nameString.
c_str()), v);
617 instance->messageNames =
new TTHash;
619 instance->obj.messages(names);
621 for (
int i=0; i<n; i++) {
623 nameString = aName.
c_str();
626 instance->messageNames->append(
TTSymbol(nameString.
c_str()), v);
631 v[0] =
TTPtr(instance);
636 std::cout <<
"TTObjectBaseInstantiate failed to create object" << std::endl;
642 VALUE TTAudioGetMessages(VALUE
self)
644 TTAudioInstance* instance = NULL;
647 VALUE returnValue = rb_float_new(0.0);
654 instance = (TTAudioInstance*)
TTPtr(v[0]);
658 instance->messageNames->getKeys(names);
661 returnValue = rb_ary_new2(size);
664 c = (TTCString)s.
c_str();
665 rb_ary_store(returnValue, i, rb_str_new(c, strlen(c)));
673 VALUE TTAudioSendMessage(
int argc, VALUE* argv, VALUE
self)
675 TTAudioInstance* instance = NULL;
677 VALUE messageNameStr;
684 std::cout <<
"ERROR -- TTRuby.send requires at least 1 argument (the name of the message to send)" << std::endl;
688 messageNameStr = StringValue(argv[0]);
689 err = gTTAudioInstances->
lookup(
TTPtr(
self), v_temp);
691 instance = (TTAudioInstance*)
TTPtr(v_temp[0]);
696 messageName = RSTRING_PTR(messageNameStr);
697 instance->messageNames->lookup(messageName, messageNameValue);
698 messageNameValue.
get(0, messageName);
707 for (
int i=1; i<argc; i++) {
708 int t = TYPE(argv[i]);
713 v_in.
append(NUM2DBL(argv[i]));
716 v_in.
append((
int)FIX2LONG(argv[i]));
722 messageArgStr = StringValue(argv[i]);
726 std::cout <<
"TTError: Array arguments for messages not yet supported in Ruby" << std::endl;
730 std::cout <<
"TTError: Object arguments for messages not yet supported in Ruby" << std::endl;
740 err = instance->obj.send(messageName, v_in, v_out);
745 std::cout <<
"TTAudioSendMessage ('" << RSTRING_PTR(messageNameStr) <<
"'): Error " << err << std::endl;
749 int size = v_out.
size();
751 VALUE ret = rb_ary_new2(size + 1);
753 rb_ary_store(ret, 0, err);
754 for (i=0; i<size; i++) {
764 fv = rb_float_new(f);
767 rb_ary_store(ret, i+1, fv);
770 std::cout <<
"objects as return values are not yet supported" << std::endl;
777 c = (TTCString)sp.
c_str();
778 rb_ary_store(ret, i+1, rb_str_new(c, strlen(c)));
787 rb_ary_store(ret, i+1, lv);
799 VALUE TTAudioGetAttributes(VALUE
self)
801 TTAudioInstance* instance = NULL;
804 VALUE returnValue = rb_float_new(0.0);
811 instance = (TTAudioInstance*)
TTPtr(v[0]);
815 instance->parameterNames->getKeys(names);
819 returnValue = rb_ary_new2(size);
822 c = (TTCString)s.
c_str();
823 rb_ary_store(returnValue, i, rb_str_new(c, strlen(c)));
831 VALUE TTAudioSetAttribute(VALUE
self, VALUE attributeName, VALUE attributeValue)
833 TTAudioInstance* instance = NULL;
835 VALUE attributeNameStr = StringValue(attributeName);
836 VALUE attributeValueStr;
841 instance = (TTAudioInstance*)
TTPtr(v[0]);
843 int t = TYPE(attributeValue);
849 v.
append(NUM2DBL(attributeValue));
852 v.
append((
int)FIX2LONG(attributeValue));
858 attributeValueStr = StringValue(attributeValue);
862 std::cout <<
"TTError: Array arguments for attributes not yet supported in Ruby" << std::endl;
866 std::cout <<
"TTError: Object arguments for attributes not yet supported in Ruby" << std::endl;
870 std::cout <<
"TTError: Unknown type for arguments to attribute" << std::endl;
875 TTSymbol parameterName = kTTSymEmpty;
878 parameterName = RSTRING_PTR(attributeNameStr);
879 instance->parameterNames->lookup(parameterName, parameterNameValue);
880 parameterNameValue.
get(0, parameterName);
882 err = instance->obj.set(parameterName, v);
885 std::cout <<
"TTAudioSetAttribute: Error " << err << std::endl;
892 VALUE TTAudioGetAttribute(VALUE
self, VALUE attributeName)
894 TTAudioInstance* instance = NULL;
896 VALUE attributeNameStr = StringValue(attributeName);
899 VALUE returnValue = rb_float_new(0.0);
905 instance = (TTAudioInstance*)
TTPtr(v[0]);
907 TTSymbol parameterName = kTTSymEmpty;
910 parameterName = RSTRING_PTR(attributeNameStr);
911 instance->parameterNames->lookup(parameterName, parameterNameValue);
912 parameterNameValue.
get(0, parameterName);
914 err = instance->obj.get(parameterName, v);
916 std::cout <<
"TTAudioGetAttribute: Error " << err << std::endl;
922 switch (v[0].type()) {
925 returnValue = rb_float_new(v);
933 returnValue = INT2NUM(v);
937 returnValue = LL2NUM((
TTInt64)v);
944 c = (TTCString)s.
c_str();
945 returnValue = rb_str_new(c, strlen(c));
953 case kNumTTDataTypes:
964 VALUE TTAudioReset(VALUE
self)
966 TTAudioInstance* instance = NULL;
972 instance = (TTAudioInstance*)
TTPtr(v[0]);
974 instance->obj.resetAudio();
981 VALUE TTAudioConnect(
int argc, VALUE* argv, VALUE
self)
983 TTAudioInstance* instance = NULL;
984 TTAudioInstance* instanceToConnect = NULL;
987 TTUInt16 inletNumberToWhichToConnect = 0;
988 TTUInt16 outletNumberFromWhichToConnect = 0;
991 std::cout <<
"ERROR -- TTAudioConnect requires at least 1 argument (the object whose output should be connected to our input)" << std::endl;
995 if (TYPE(argv[0]) == T_OBJECT) {
996 err = gTTAudioInstances->
lookup(
TTPtr(argv[0]), v);
998 instanceToConnect = (TTAudioInstance*)
TTPtr(v[0]);
1002 if (!instanceToConnect) {
1003 std::cout <<
"ERROR -- TTAudioConnect cannot verify the object you would like to connect" << std::endl;
1008 inletNumberToWhichToConnect = FIX2LONG(argv[1]);
1010 outletNumberFromWhichToConnect = FIX2LONG(argv[2]);
1015 instance = (TTAudioInstance*)
TTPtr(v[0]);
1017 instance->obj.connectAudio(instanceToConnect->obj, outletNumberFromWhichToConnect, inletNumberToWhichToConnect);
1025 VALUE TTAudioDrop(
int argc, VALUE* argv, VALUE
self)
1027 TTAudioInstance* instance = NULL;
1028 TTAudioInstance* instanceToConnect = NULL;
1031 TTUInt16 inletNumberToWhichToConnect = 0;
1032 TTUInt16 outletNumberFromWhichToConnect = 0;
1035 std::cout <<
"ERROR -- TTAudioConnect requires at least 1 argument (the object whose output should be connected to our input)" << std::endl;
1039 if (TYPE(argv[0]) == T_OBJECT) {
1040 err = gTTAudioInstances->
lookup(
TTPtr(argv[0]), v);
1042 instanceToConnect = (TTAudioInstance*)
TTPtr(v[0]);
1046 if (!instanceToConnect) {
1047 std::cout <<
"ERROR -- TTAudioConnect cannot verify the object you would like to connect" << std::endl;
1052 inletNumberToWhichToConnect = FIX2LONG(argv[1]);
1054 outletNumberFromWhichToConnect = FIX2LONG(argv[2]);
1059 instance = (TTAudioInstance*)
TTPtr(v[0]);
1061 instance->obj.dropAudio(instanceToConnect->obj, outletNumberFromWhichToConnect, inletNumberToWhichToConnect);
1069 VALUE TTAudioExportMax(VALUE
self, VALUE pathToExportFile)
1071 TTAudioInstance* instance = NULL;
1075 VALUE pathToExportStr = StringValue(pathToExportFile);
1076 TTString path = RSTRING_PTR(pathToExportStr);
1080 instance = (TTAudioInstance*)
TTPtr(v[0]);
1082 instance->obj.getAudioDescription(desc);
1083 desc.exportMax(path);
1089 VALUE TTAudioExportCpp(VALUE
self, VALUE pathToExportFile)
1091 TTAudioInstance* instance = NULL;
1095 VALUE pathToExportStr = StringValue(pathToExportFile);
1096 TTString path = RSTRING_PTR(pathToExportStr);
1100 instance = (TTAudioInstance*)
TTPtr(v[0]);
1102 instance->obj.getAudioDescription(desc);
1103 desc.exportCpp(path);
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
std::uint16_t TTUInt16
16 bit unsigned integer
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
Provides all necessary definitions for AudioGraph API.
8-bit unsigned integer, range is 0 through 255.
const char * c_str() const
Return a pointer to the internal C-string.
64-bit unsigned integer, range is 0 through 18,446,744,073,709,551,615.
size_type size() const noexcept
Return the number of elements.
This object provides a description of a TTAudioGraphObject and its sources.
Wrap audio objects for convenience.
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
double TTFloat64
64 bit floating point number
This is a special type used by TTAttribute to indicate that a value is a TTValue and is locally maint...
16-bit unsigned integer, range is 0 through 65,535.
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
void * TTPtr
A generic pointer.
std::int64_t TTInt64
64 bit signed integer
16-bit signed integer, range is −32,768 through 32,767.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
void get(const TTUInt16 index, T &returnedElementValue) const
DEPRECATED.
Boolean (1/0) or (true/false) flag.
const char * c_str() const
Return a pointer to the internal string as a C-string.
std::int32_t TTInt32
32 bit signed integer
64-bit signed integer, ragne is −9,223,372,036,854,775,808 through 9,223,372,036,854,775,807
void clear()
Clear all values from the vector, leaving with size of 0.
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
32-bit signed integer, range is -2,147,483,648 through 2,147,483,647.
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
32-bit unsigned integer, range is 0 through 4,294,967,295.
8-bit signed integer, range is -128 through 127.
The TTString class is used to represent a string.
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]