Module: SDL2::Mixer::MusicChannel

Defined in:
mixer.c

Class Method Summary (collapse)

Class Method Details

+ (nil) fade_in(music, loops, ms, pos = 0)

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:

  • {{.play}


627
628
629
630
631
632
633
634
635
636
# File 'mixer.c', line 627

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

+ (nil) fade_out(ms)

Halt the music playback with fade-out effect.

Returns:

  • (nil)


731
732
733
734
# File 'mixer.c', line 731

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

+ (Integer) fading

Get the fading state of the music playback.

The return value is one of the following:

Returns:

  • (Integer)

See Also:



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

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

+ (nil) halt

Halt the music playback.

Returns:

  • (nil)


720
721
722
723
# File 'mixer.c', line 720

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

+ (nil) pause

Pause the playback of the music channel.

Returns:

  • (nil)

See Also:



674
675
676
677
# File 'mixer.c', line 674

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

+ (Boolean) pause?

Return true if a music playback is paused.

Returns:

  • (Boolean)


747
748
749
750
# File 'mixer.c', line 747

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

+ (nil) play(music, loops)

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:

  • {{.fade_in}


602
603
604
605
606
607
# File 'mixer.c', line 602

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

+ (Boolean) play?

Return true if a music is playing.

Returns:

  • (Boolean)


739
740
741
742
# File 'mixer.c', line 739

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

+ (SDL2::Mixer::Music?) playing_music

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

Return nil if no music object is played yet.

Returns:



779
780
781
782
# File 'mixer.c', line 779

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

+ (nil) resume

Resume the playback of the music channel.

Returns:

  • (nil)

See Also:



687
688
689
690
# File 'mixer.c', line 687

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

+ (nil) rewind

Rewind the music to the start.

Returns:

  • (nil)


697
698
699
700
# File 'mixer.c', line 697

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

+ (nil) set_position(position)

Set the position of the currently playing music.

Parameters:

  • position (Float)

    the position to play from.

Returns:

  • (nil)


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

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

+ (Integer) volume

Get the volume of the music channel.

Returns:

  • (Integer)

See Also:



645
646
647
648
# File 'mixer.c', line 645

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

+ (vol) volume=(vol)

Set the volume of the music channel.

Parameters:

Returns:

  • (vol)

See Also:



660
661
662
663
664
# File 'mixer.c', line 660

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