Class: SDL2::Mixer::Music

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.decodersArray<String>

Get the names of music decoders.

Returns:

  • (Array<String>)

    the names of decorders (supported sound formats), such as: “OGG”, “WAVE”, “MP3”



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

Load a music from file.

Parameters:

  • path (String)

    the file path

Returns:

Raises:



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

#destroynil

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.

Returns:

  • (nil)


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.

Returns:

  • (Boolean)

#inspectString

Returns inspection string

Returns:

  • (String)

    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)));
}