#include "beeps/ruby/sound.h" #include "defs.h" RUCY_DEFINE_VALUE_FROM_TO(BEEPS_EXPORT, Beeps::Sound) #define THIS to(self) #define CHECK RUCY_CHECK_OBJ(Beeps::Sound, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE setup(VALUE self, VALUE processor, VALUE seconds, VALUE nchannels, VALUE sample_rate) { CHECK; *THIS = Beeps::Sound( to(processor), to(seconds), to(nchannels), to(sample_rate)); return self; } static VALUE play(VALUE self) { CHECK; return value(THIS->play()); } static VALUE get_sample_rate(VALUE self) { CHECK; return value(THIS->sample_rate()); } static VALUE get_nchannels(VALUE self) { CHECK; return value(THIS->nchannels()); } static VALUE get_seconds(VALUE self) { CHECK; return value(THIS->seconds()); } static VALUE set_gain(VALUE self, VALUE gain) { CHECK; THIS->set_gain(to(gain)); return gain; } static VALUE get_gain(VALUE self) { CHECK; return value(THIS->gain()); } static VALUE set_loop(VALUE self, VALUE loop) { CHECK; THIS->set_loop(to(loop)); return loop; } static VALUE get_loop(VALUE self) { CHECK; return value(THIS->loop()); } static VALUE save(VALUE self, VALUE path) { CHECK; THIS->save(path.c_str()); return self; } static VALUE load(VALUE self, VALUE path) { return value(Beeps::load_sound(to(path))); } static Class cSound; void Init_beeps_sound () { Module mBeeps = rb_define_module("Beeps"); cSound = rb_define_class_under(mBeeps, "Sound", rb_cObject); rb_define_alloc_func(cSound, alloc); rb_define_private_method(cSound, "setup", RUBY_METHOD_FUNC(setup), 4); cSound.define_private_method("play!", play); rb_define_method(cSound, "sample_rate", RUBY_METHOD_FUNC(get_sample_rate), 0); rb_define_method(cSound, "nchannels", RUBY_METHOD_FUNC(get_nchannels), 0); rb_define_method(cSound, "seconds", RUBY_METHOD_FUNC(get_seconds), 0); rb_define_method(cSound, "gain=", RUBY_METHOD_FUNC(set_gain), 1); rb_define_method(cSound, "gain", RUBY_METHOD_FUNC(get_gain), 0); rb_define_method(cSound, "loop=", RUBY_METHOD_FUNC(set_loop), 1); rb_define_method(cSound, "loop", RUBY_METHOD_FUNC(get_loop), 0); rb_define_method(cSound, "save", RUBY_METHOD_FUNC(save), 1); rb_define_singleton_method(cSound, "load", RUBY_METHOD_FUNC(load), 1); } namespace Beeps { Class sound_class () { return cSound; } }// Beeps