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.
1018 1019 1020 1021 1022 1023 1024 1025 1026 |
# File 'mixer.c', line 1018
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
1037 1038 1039 1040 1041 1042 1043 1044 1045 |
# File 'mixer.c', line 1037
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.
1055 1056 1057 1058 1059 1060 1061 |
# File 'mixer.c', line 1055
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.
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
# File 'mixer.c', line 1064
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)));
}
|