Module: SDL2::Mixer::MusicChannel

Defined in:
mixer.c,
mixer.c

Overview

This module provides the functions to play Music.

Class Method Summary collapse

Class Method Details

.fade_in(music, loops, ms, pos = 0) ⇒ nil

Note:

the meaning of loop is different from Channels.play.

Play music loops times with fade-in effect.

Parameters:

  • music (SDL2::Mixer::Music)

    music to play

  • loops (Integer)

    number of times to play the music. 0 plays the music zero times. -1 plays the music forever.

  • ms (Integer)

    milliseconds for the fade-in effect

  • pos (Float) (defaults to: 0)

    the position to play from. The meaning of “position” is different for the type of music sources.

Returns:

  • (nil)

See Also:



734
735
736
737
738
739
740
741
742
743
# File 'mixer.c', line 734

static VALUE MusicChannel_s_fade_in(int argc, VALUE* argv, VALUE self)
{
    VALUE music, loops, fade_in_ms, pos;
    rb_scan_args(argc, argv, "31", &music, &loops, &fade_in_ms, &pos);
    HANDLE_MIX_ERROR(Mix_FadeInMusicPos(Get_Mix_Music(music), NUM2INT(loops), 
                                        NUM2INT(fade_in_ms),
                                        pos == Qnil ? 0 : NUM2DBL(pos)));
    playing_music = music;
    return Qnil;
}

.fade_out(ms) ⇒ nil

Halt the music playback with fade-out effect.

Parameters:

  • ms (Integer)

    milliseconds of fade-out effect

Returns:

  • (nil)


839
840
841
842
# File 'mixer.c', line 839

static VALUE MusicChannel_s_fade_out(VALUE self, VALUE fade_out_ms)
{
    Mix_FadeOutMusic(NUM2INT(fade_out_ms)); return Qnil;
}

.fadingInteger

Get the fading state of the music playback.

The return value is one of the following:

Returns:

  • (Integer)

See Also:



879
880
881
882
# File 'mixer.c', line 879

static VALUE MusicChannel_s_fading(VALUE self)
{
    return INT2NUM(Mix_FadingMusic());
}

.haltnil

Halt the music playback.

Returns:

  • (nil)


827
828
829
830
# File 'mixer.c', line 827

static VALUE MusicChannel_s_halt(VALUE self)
{
    Mix_HaltMusic(); return Qnil;
}

.pausenil

Pause the playback of the music channel.

Returns:

  • (nil)

See Also:



781
782
783
784
# File 'mixer.c', line 781

static VALUE MusicChannel_s_pause(VALUE self)
{
    Mix_PauseMusic(); return Qnil;
}

.pause?Boolean

Return true if a music playback is paused.

Returns:

  • (Boolean)


859
860
861
862
# File 'mixer.c', line 859

static VALUE MusicChannel_s_pause_p(VALUE self)
{
    return INT2BOOL(Mix_PausedMusic());
}

.play(music, loops) ⇒ nil

Note:

the meaning of loop is different from Channels.play.

Play music loops times.

Parameters:

  • music (SDL2::Mixer::Music)

    music to play

  • loops (Integer)

    number of times to play the music. 0 plays the music zero times. -1 plays the music forever.

Returns:

  • (nil)

See Also:



709
710
711
712
713
714
# File 'mixer.c', line 709

static VALUE MusicChannel_s_play(VALUE self, VALUE music, VALUE loops)
{
    HANDLE_MIX_ERROR(Mix_PlayMusic(Get_Mix_Music(music), NUM2INT(loops)));
    playing_music = music;
    return Qnil;
}

.play?Boolean

Return true if a music is playing.

Returns:

  • (Boolean)


849
850
851
852
# File 'mixer.c', line 849

static VALUE MusicChannel_s_play_p(VALUE self)
{
    return INT2BOOL(Mix_PlayingMusic());
}

.playing_musicSDL2::Mixer::Music?

Get the SDL2::Mixer::Music object that most recently played.

Return nil if no music object is played yet.

Returns:



891
892
893
894
# File 'mixer.c', line 891

static VALUE MusicChannel_s_playing_music(VALUE self)
{
    return playing_music;
}

.resumenil

Resume the playback of the music channel.

Returns:

  • (nil)

See Also:



794
795
796
797
# File 'mixer.c', line 794

static VALUE MusicChannel_s_resume(VALUE self)
{
    Mix_ResumeMusic(); return Qnil;
}

.rewindnil

Rewind the music to the start.

Returns:

  • (nil)


804
805
806
807
# File 'mixer.c', line 804

static VALUE MusicChannel_s_rewind(VALUE self)
{
    Mix_RewindMusic(); return Qnil;
}

.set_position(position) ⇒ nil

Set the position of the currently playing music.

Parameters:

  • position (Float)

    the position to play from.

Returns:

  • (nil)


816
817
818
819
820
# File 'mixer.c', line 816

static VALUE MusicChannel_s_set_position(VALUE self, VALUE position)
{
    HANDLE_MIX_ERROR(Mix_SetMusicPosition(NUM2DBL(position)));
    return Qnil;
}

.volumeInteger

Get the volume of the music channel.

Returns:

  • (Integer)

See Also:



752
753
754
755
# File 'mixer.c', line 752

static VALUE MusicChannel_s_volume(VALUE self)
{
    return INT2FIX(Mix_VolumeMusic(-1));
}

.volume=(vol) ⇒ void

This method returns an undefined value.

Set the volume of the music channel.

Parameters:

See Also:



767
768
769
770
771
# File 'mixer.c', line 767

static VALUE MusicChannel_s_set_volume(VALUE self, VALUE volume)
{
    Mix_VolumeMusic(NUM2INT(volume));
    return volume;
}