Class: SDL2::Mixer::Music
- Inherits:
-
Object
- Object
- SDL2::Mixer::Music
- Defined in:
- mixer.c,
mixer.c
Overview
This class represents music, a kind of sound sources.
Music is playable on MusicChannel, not on Channels.
Class Method Summary collapse
-
.decoders ⇒ Array<String>
Get the names of music decoders.
-
.load(path) ⇒ SDL2::Mixer::Music
Load a music from file.
Instance Method Summary collapse
-
#destroy ⇒ nil
Deallocate the music memory.
-
#destroy? ⇒ Boolean
Return true if the memory is deallocated by #destroy.
-
#inspect ⇒ String
Inspection string.
Class Method Details
.decoders ⇒ Array<String>
Get the names of music decoders.
1003 1004 1005 1006 1007 1008 1009 1010 1011 |
# File 'mixer.c', line 1003
static VALUE Music_s_decoders(VALUE self)
{
int num_decoders = Mix_GetNumMusicDecoders();
int i;
VALUE decoders = rb_ary_new2(num_decoders);
for (i=0; i<num_decoders; ++i)
rb_ary_push(decoders, utf8str_new_cstr(Mix_GetMusicDecoder(i)));
return decoders;
}
|
.load(path) ⇒ SDL2::Mixer::Music
1022 1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'mixer.c', line 1022
static VALUE Music_s_load(VALUE self, VALUE fname)
{
Mix_Music* music = Mix_LoadMUS(StringValueCStr(fname));
VALUE mus;
if (!music) MIX_ERROR();
mus = Music_new(music);
rb_iv_set(mus, "@filename", fname);
return mus;
}
|
Instance Method Details
#destroy ⇒ nil
Deallocate the music memory.
Normally, the memory is deallocated by ruby’s GC, but you can surely deallocate the memory with this method at any time.
1040 1041 1042 1043 1044 1045 1046 |
# File 'mixer.c', line 1040
static VALUE Music_destroy(VALUE self)
{
Music* c = Get_Music(self);
if (c) Mix_FreeMusic(c->music);
c->music = NULL;
return Qnil;
}
|
#destroy? ⇒ Boolean
Return true if the memory is deallocated by #destroy.
#inspect ⇒ String
Returns inspection string
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'mixer.c', line 1049
static VALUE Music_inspect(VALUE self)
{
VALUE filename = rb_iv_get(self, "@filename");
if (RTEST(Music_destroy_p(self)))
return rb_sprintf("<%s: destroyed>", rb_obj_classname(self));
return rb_sprintf("<%s: filename=\"%s\" type=%d>",
rb_obj_classname(self), StringValueCStr(filename),
Mix_GetMusicType(Get_Mix_Music(self)));
}
|