#include "beeps/ruby/sound.h" #include "defs.h" RUCY_DEFINE_VALUE_FROM_TO(Beeps::SoundPlayer) #define THIS to(self) #define CHECK RUCY_CHECK_OBJ(Beeps::SoundPlayer, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE play(VALUE self) { CHECK; THIS->play(); return self; } static VALUE pause(VALUE self) { CHECK; THIS->pause(); return self; } static VALUE rewind(VALUE self) { CHECK; THIS->rewind(); return self; } static VALUE stop(VALUE self) { CHECK; THIS->stop(); return self; } static VALUE get_state(VALUE self) { CHECK; return value(THIS->state()); } 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 stop_all(VALUE self) { Beeps::stop_all_sound_players(); } static Class cSoundPlayer; void Init_beeps_sound_player () { Module mBeeps = rb_define_module("Beeps"); cSoundPlayer = rb_define_class_under(mBeeps, "SoundPlayer", rb_cObject); rb_define_alloc_func(cSoundPlayer, alloc); rb_define_method(cSoundPlayer, "play", RUBY_METHOD_FUNC(play), 0); rb_define_method(cSoundPlayer, "pause", RUBY_METHOD_FUNC(pause), 0); rb_define_method(cSoundPlayer, "rewind", RUBY_METHOD_FUNC(rewind), 0); rb_define_method(cSoundPlayer, "stop", RUBY_METHOD_FUNC(stop), 0); rb_define_method(cSoundPlayer, "state", RUBY_METHOD_FUNC(get_state), 0); rb_define_method(cSoundPlayer, "gain=", RUBY_METHOD_FUNC(set_gain), 1); rb_define_method(cSoundPlayer, "gain", RUBY_METHOD_FUNC(get_gain), 0); rb_define_method(cSoundPlayer, "loop=", RUBY_METHOD_FUNC(set_loop), 1); rb_define_method(cSoundPlayer, "loop", RUBY_METHOD_FUNC(get_loop), 0); rb_define_singleton_method(cSoundPlayer, "stop_all", RUBY_METHOD_FUNC(stop_all), 0); cSoundPlayer.define_const("STATE_UNKNOWN", Beeps::SoundPlayer::STATE_UNKNOWN); cSoundPlayer.define_const("PLAYING", Beeps::SoundPlayer::PLAYING); cSoundPlayer.define_const("PAUSED", Beeps::SoundPlayer::PAUSED); cSoundPlayer.define_const("STOPPED", Beeps::SoundPlayer::STOPPED); } namespace Beeps { Class sound_player_class () { return cSoundPlayer; } }// Beeps