<commit_before>// Language Bindings to Make the Jamoma Runtime accessible via Ruby
// Copyright © 2009, <NAME>
// License: New BSD License -- http://creativecommons.org/licenses/BSD/

#include "TTAudioGraphAPI.h"
#include "ruby.h"


//
class TTRubyInstance {
public:
	TTAudioObjectBasePtr		obj;
	TTHashPtr				parameterNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	TTHashPtr				messageNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	
	TTRubyInstance()
	{
		obj = NULL;
	}
};


//
class TTAudioInstance {
public:
	TTAudioGraphObjectPtr	obj;
	TTHashPtr				parameterNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	TTHashPtr				messageNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	
	TTAudioInstance()
	{
		obj = NULL;
	}
};


typedef VALUE (*TTRubyMethod)(...);
//#define TTRubyMethod


// Prototypes
extern "C" {
	void Init_Jamoma();

	VALUE TTRubyInitialize(VALUE self, VALUE className);
	VALUE TTRubyGetMessages(VALUE self);
	VALUE TTRubySendMessage(int argc, VALUE* argv, VALUE self);
	VALUE TTRubyGetAttributes(VALUE self);
	VALUE TTRubySetAttribute(VALUE self, VALUE attributeName, VALUE attributeValue);
	VALUE TTRubyGetAttribute(VALUE self, VALUE attributeName);
	VALUE TTRubyCalculate(VALUE self, VALUE x);

	VALUE TTAudioInitialize(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioGetMessages(VALUE self);
	VALUE TTAudioSendMessage(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioGetAttributes(VALUE self);
	VALUE TTAudioSetAttribute(VALUE self, VALUE attributeName, VALUE attributeValue);
	VALUE TTAudioGetAttribute(VALUE self, VALUE attributeName);
	VALUE TTAudioReset(VALUE self);
	VALUE TTAudioConnect(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioDrop(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioExportMax(VALUE self, VALUE pathToExportFile);
	VALUE TTAudioExportCpp(VALUE self, VALUE pathToExportFile);
}


// Globals and Statics
VALUE		TTRuby_class;
TTHashPtr	gTTRubyInstances = NULL;
//std::unordered_map<TTPtr, TTValue> gTTRubyInstances;

VALUE		TTAudio_class;
TTHashPtr	gTTAudioInstances = NULL;


/*****************************************************************************************************/
// Class Definition

void Init_Jamoma()
{
	VALUE c;
	
	TTFoundationInit();
	
	c = rb_define_class("TTObject", rb_cObject);
	
	rb_define_method(c, "initialize",		TTRubyMethod(TTRubyInitialize), 1);		// called to initialize a new object that has been created or cloned	
	rb_define_method(c, "messages?",		TTRubyMethod(TTRubyGetMessages), 0);
	rb_define_method(c, "send",				TTRubyMethod(TTRubySendMessage), -1);	// send a message to the wrapped object
	rb_define_method(c, "attributes?",		TTRubyMethod(TTRubyGetAttributes), 0);
	rb_define_method(c, "set",				TTRubyMethod(TTRubySetAttribute), 2);	// set attribute value
	rb_define_method(c, "get",				TTRubyMethod(TTRubyGetAttribute), 1);	// get attribute value
	rb_define_method(c, "calculate",		TTRubyMethod(TTRubyCalculate), 1);
	
	TTRuby_class = c;
	gTTRubyInstances = new TTHash;
	
	
	// AUDIO
	
	TTAudioGraphInit();

	c = rb_define_class("TTAudio", rb_cObject);
	
	rb_define_method(c, "initialize",		TTRubyMethod(TTAudioInitialize),	-1);	// called to initialize a new object that has been created or cloned
	rb_define_method(c, "messages?",		TTRubyMethod(TTAudioGetMessages),	0);
	rb_define_method(c, "send",				TTRubyMethod(TTAudioSendMessage),	-1);	// send a message to the wrapped object
	rb_define_method(c, "attributes?",		TTRubyMethod(TTAudioGetAttributes), 0);
	rb_define_method(c, "set",				TTRubyMethod(TTAudioSetAttribute),	2);		// set attribute value
	rb_define_method(c, "get",				TTRubyMethod(TTAudioGetAttribute),	1);		// get attribute value
	rb_define_method(c, "reset_audio",		TTRubyMethod(TTAudioReset),			0);		// reset audio graph connections
	rb_define_method(c, "connect_audio",	TTRubyMethod(TTAudioConnect),		-1);	// connect an output of another object to our input
	rb_define_method(c, "drop_audio",		TTRubyMethod(TTAudioDrop),			-1);	// disconnect an output of another object from our input
	rb_define_method(c, "export_max",		TTRubyMethod(TTAudioExportMax),		1);		// reset audio graph connections
	rb_define_method(c, "export_cpp",		TTRubyMethod(TTAudioExportCpp),		1);		// reset audio graph connections
	
	TTAudio_class = c;
	gTTAudioInstances = new TTHash;
}


/*****************************************************************************************************/
// Life Cycle

// See pg 292 for an example of how to setup the message binding for this one
// VALUE TTRubyAlloc(VALUE ttruby_class)

VALUE TTRubyInitialize(VALUE self, VALUE className)
{	
	TTRubyInstance* instance = new TTRubyInstance;
	TTValue			v;
	TTValue			args;
	TTErr			err = kTTErrNone;
	VALUE			classNameStr = StringValue(className);
	TTSymbol		classNameTTStr(RSTRING_PTR(classNameStr));
	long			n;
	TTValue			names;
	TTSymbol		aName = kTTSymEmpty;
	TTString		nameString;
	
	args.clear();
	
	if (classNameTTStr == "environment")
		instance->obj = (TTAudioObjectBase*)ttEnvironment;
		// right now we just leak all of our instances (oops), but when we do free them correctly we don't want to free the environment!
	else
		err = TTObjectBaseInstantiate(classNameTTStr, &instance->obj, args);
		<commit_msg>post information to the console when a class fails to load, e.g. because an exception was caught internally.<commit_after>// Language Bindings to Make the Jamoma Runtime accessible via Ruby
// Copyright © 2009, <NAME>
// License: New BSD License -- http://creativecommons.org/licenses/BSD/

#include "TTAudioGraphAPI.h"
#include "ruby.h"


//
class TTRubyInstance {
public:
	TTAudioObjectBasePtr		obj;
	TTHashPtr				parameterNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	TTHashPtr				messageNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	
	TTRubyInstance()
	{
		obj = NULL;
	}
};


//
class TTAudioInstance {
public:
	TTAudioGraphObjectPtr	obj;
	TTHashPtr				parameterNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	TTHashPtr				messageNames;		// cache of parameter names, mapped from lowercase (ruby) to uppercase (TT)
	
	TTAudioInstance()
	{
		obj = NULL;
	}
};


typedef VALUE (*TTRubyMethod)(...);
//#define TTRubyMethod


// Prototypes
extern "C" {
	void Init_Jamoma();

	VALUE TTRubyInitialize(VALUE self, VALUE className);
	VALUE TTRubyGetMessages(VALUE self);
	VALUE TTRubySendMessage(int argc, VALUE* argv, VALUE self);
	VALUE TTRubyGetAttributes(VALUE self);
	VALUE TTRubySetAttribute(VALUE self, VALUE attributeName, VALUE attributeValue);
	VALUE TTRubyGetAttribute(VALUE self, VALUE attributeName);
	VALUE TTRubyCalculate(VALUE self, VALUE x);

	VALUE TTAudioInitialize(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioGetMessages(VALUE self);
	VALUE TTAudioSendMessage(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioGetAttributes(VALUE self);
	VALUE TTAudioSetAttribute(VALUE self, VALUE attributeName, VALUE attributeValue);
	VALUE TTAudioGetAttribute(VALUE self, VALUE attributeName);
	VALUE TTAudioReset(VALUE self);
	VALUE TTAudioConnect(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioDrop(int argc, VALUE* argv, VALUE self);
	VALUE TTAudioExportMax(VALUE self, VALUE pathToExportFile);
	VALUE TTAudioExportCpp(VALUE self, VALUE pathToExportFile);
}


// Globals and Statics
VALUE		TTRuby_class;
TTHashPtr	gTTRubyInstances = NULL;
//std::unordered_map<TTPtr, TTValue> gTTRubyInstances;

VALUE		TTAudio_class;
TTHashPtr	gTTAudioInstances = NULL;


/*****************************************************************************************************/
// Class Definition

void Init_Jamoma()
{
	VALUE c;
	
	TTFoundationInit();
	
	c = rb_define_class("TTObject", rb_cObject);
	
	rb_define_method(c, "initialize",		TTRubyMethod(TTRubyInitialize), 1);		// called to initialize a new object that has been created or cloned	
	rb_define_method(c, "messages?",		TTRubyMethod(TTRubyGetMessages), 0);
	rb_define_method(c, "send",				TTRubyMethod(TTRubySendMessage), -1);	// send a message to the wrapped object
	rb_define_method(c, "attributes?",		TTRubyMethod(TTRubyGetAttributes), 0);
	rb_define_method(c, "set",				TTRubyMethod(TTRubySetAttribute), 2);	// set attribute value
	rb_define_method(c, "get",				TTRubyMethod(TTRubyGetAttribute), 1);	// get attribute value
	rb_define_method(c, "calculate",		TTRubyMethod(TTRubyCalculate), 1);
	
	TTRuby_class = c;
	gTTRubyInstances = new TTHash;
	
	
	// AUDIO
	
	TTAudioGraphInit();

	c = rb_define_class("TTAudio", rb_cObject);
	
	rb_define_method(c, "initialize",		TTRubyMethod(TTAudioInitialize),	-1);	// called to initialize a new object that has been created or cloned
	rb_define_method(c, "messages?",		TTRubyMethod(TTAudioGetMessages),	0);
	rb_define_method(c, "send",				TTRubyMethod(TTAudioSendMessage),	-1);	// send a message to the wrapped object
	rb_define_method(c, "attributes?",		TTRubyMethod(TTAudioGetAttributes), 0);
	rb_define_method(c, "set",				TTRubyMethod(TTAudioSetAttribute),	2);		// set attribute value
	rb_define_method(c, "get",				TTRubyMethod(TTAudioGetAttribute),	1);		// get attribute value
	rb_define_method(c, "reset_audio",		TTRubyMethod(TTAudioReset),			0);		// reset audio graph connections
	rb_define_method(c, "connect_audio",	TTRubyMethod(TTAudioConnect),		-1);	// connect an output of another object to our input
	rb_define_method(c, "drop_audio",		TTRubyMethod(TTAudioDrop),			-1);	// disconnect an output of another object from our input
	rb_define_method(c, "export_max",		TTRubyMethod(TTAudioExportMax),		1);		// reset audio graph connections
	rb_define_method(c, "export_cpp",		TTRubyMethod(TTAudioExportCpp),		1);		// reset audio graph connections
	
	TTAudio_class = c;
	gTTAudioInstances = new TTHash;
}


/*****************************************************************************************************/
// Life Cycle

// See pg 292 for an example of how to setup the message binding for this one
// VALUE TTRubyAlloc(VALUE ttruby_class)

VALUE TTRubyInitialize(VALUE self, VALUE className)
{	
	TTRubyInstance* instance = new TTRubyInstance;
	TTValue			v;
	TTValue			args;
	TTErr			err = kTTErrNone;
	VALUE			classNameStr = StringValue(className);
	TTSymbol		classNameTTStr(RSTRING_PTR(classNameStr));
	long			n;
	TTValue			names;
	TTSymbol		aName = kTTSymEmpty;
	TTString		nameString;
	
	args.clear();
	
	if (classNameTTStr == "environment")
		instance->obj = (TTAudioObjectBase*)ttEnvironment;
		// right now we just leak all of our instances (oops), but when we do free them correctly we don't want to free the environment!
	else
		err = TTObjectBaseInstantiate(classNameTTStr, &instance->obj, args);
	
	if (err)
		std::cout << "Error " << err << " for object " << classNameTTStr.c_str() << std::endl;
		
{'fraction_non_alphanumeric': 0.13660599374885088, 'fraction_numerical': 0.004596433167861739, 'mean_word_length': 5.339743589743589, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3173192', 'n_tokens_mistral': 3924, 'n_tokens_neox': 3674, 'n_words': 976}