| Class | Joyau::Sound |
| In: |
Drawable.cpp
|
| Parent: | Joyau::AudioObject |
Joyau’s class used for short sounds. It allows to load WAV files, and to play them at each call of play.
Creates a new Sound. If a filename is given, it is loaded. Examples :
sound = Joyau::Sound.new
sound = Joyau::Sound.new("music.wav")
/*
call-seq: Joyau::Sound.new
Joyau::Sound.new(filename)
Creates a new Sound. If a filename is given, it is loaded.
Examples :
sound = Joyau::Sound.new
sound = Joyau::Sound.new("music.wav")
*/
VALUE wrap<Sound>(int argc, VALUE *argv, VALUE info)
{
Sound *ptr = new Sound;
VALUE filename;
rb_scan_args(argc, argv, "01", &filename);
if (!NIL_P(filename)) {
try {
filename = rb_obj_as_string(filename);
ptr->loadWav(StringValuePtr(filename));
}
catch (const RubyException &e) {
e.rbRaise();
}
}
VALUE tdata = Data_Wrap_Struct(info, 0, wrapped_free<Sound>, ptr);
return tdata;
}
Loads a new WAV file. Raises a RuntimeError if something wrong occurs.
/*
call-seq: loadWav(file_name)
Loads a new WAV file.
Raises a +RuntimeError+ if something wrong occurs.
*/
VALUE Sound_loadWav(VALUE self, VALUE filename)
{
filename = rb_obj_as_string(filename);
Sound &ref = getRef<Sound>(self);
char *str = StringValuePtr(filename);
try {
ref.loadWav(str);
}
catch (const RubyException &e) {
e.rbRaise();
return Qfalse;
}
return Qtrue;
}
Plays a sound. Call it whenever you want it to be played.
/*
Plays a sound. Call it whenever you want it to be played.
*/
VALUE Sound_play(VALUE self)
{
Sound &ref = getRef<Sound>(self);
ref.play();
return Qnil;
}