Ejemplo n.º 1
0
void syncchannel(soundchannel &chan)
{
    if(!chan.dirty) return;
    if(!Mix_FadingChannel(chan.id)) Mix_Volume(chan.id, chan.volume);
    Mix_SetPanning(chan.id, 255-chan.pan, chan.pan);
    chan.dirty = false;
}
Ejemplo n.º 2
0
/*
 *  call-seq:
 *    volume = new_vol
 *
 *  Set the new #volume level of the sound.
 *  0.0 is totally silent, 1.0 is full volume.
 * 
 *  Volume cannot be set while the sound is fading in or out.
 *  Be sure to check #fading? or rescue from SDLError when
 *  using this method.
 *
 *  May raise::  SDLError if the sound is fading in or out.
 *	
 */
static VALUE rg_sound_setvolume( VALUE self, VALUE volume )
{
	RG_Sound *sound;
	Data_Get_Struct(self,  RG_Sound, sound);

	/* Change channel volume if Sound is currently assigned to a channel */
	if( _rg_sound_channel_check(sound) )
	{
		/* But only if it's not fading right now. */
		if( Mix_FadingChannel(sound->channel) == MIX_NO_FADING )
		{
			sound->volume = NUM2DBL(volume);
			Mix_Volume( sound->channel, (int)(MIX_MAX_VOLUME * sound->volume) );
		}
		else
		{
			rb_raise(eSDLError, "cannot set Sound volume while fading");
		}
	}
	else
	{
		/* Save it for later. */
		sound->volume = NUM2DBL(volume);
	}

	return volume;
}
Ejemplo n.º 3
0
static mrb_value
mrb_sdl2_mixer_fading_channel(mrb_state *mrb, mrb_value self)
{
  mrb_int which;
  mrb_get_args(mrb, "i", &which);
  return mrb_fixnum_value(Mix_FadingChannel(which));
}
Ejemplo n.º 4
0
d_define_method(track, stop_fade_out)(struct s_object *self, int delay) {
  d_using(track);
  if ((track_attributes->channel != d_track_auto_channel) && ((Mix_Playing(track_attributes->channel)) || (Mix_Paused(track_attributes->channel))))
    if (Mix_FadingChannel(track_attributes->channel) != MIX_FADING_OUT)
      if (!Mix_FadeOutChannel(track_attributes->channel, delay))
        Mix_HaltChannel(track_attributes->channel);
  return self;
}
Ejemplo n.º 5
0
Mix_Fading cAudio :: Is_Sound_Fading( int sound_channel ) const
{
	if( !m_sound_enabled || !m_initialised || sound_channel < 0 )
	{
		return MIX_NO_FADING;
	}

	return Mix_FadingChannel( sound_channel );
}
Ejemplo n.º 6
0
/*
 *  call-seq:
 *    fading?( direction=:either )  ->  true or false
 *
 *  True if the Sound is currently fading in or out.
 *  See also #play and #fade_out.
 *
 *  direction::  Check if it is fading :in, :out, or :either.
 *               (Symbol, required)
 *
 */
static VALUE rg_sound_fadingp( int argc, VALUE *argv, VALUE self )
{
	RG_Sound *sound;
	Data_Get_Struct(self,  RG_Sound, sound);

	VALUE vdirection;
	rb_scan_args(argc, argv, "01", &vdirection);
	
	int direction;
	int channel = sound->channel;

	/* If it's not actually on a channel, return false right away. */
	if( !(_rg_sound_channel_check(sound)) )
	{
		return Qfalse;
	}

	if( RTEST(vdirection) )
	{
		if( make_symbol("in") == vdirection )
		{
			return ( (Mix_FadingChannel(channel) == MIX_FADING_IN)  ? Qtrue : Qfalse );
		}
		
		else if( make_symbol("out") == vdirection )
		{
			return ( (Mix_FadingChannel(channel) == MIX_FADING_OUT) ? Qtrue : Qfalse );
		}
		
		else if( make_symbol("either") == vdirection )
		{
			return ( (Mix_FadingChannel(channel) != MIX_NO_FADING)  ? Qtrue : Qfalse );
		}
	}

	/* default */
	return ( (Mix_FadingChannel(channel) != MIX_NO_FADING)  ? Qtrue : Qfalse );
}
Ejemplo n.º 7
0
	static int lua_Mix_FadingChannel(State & state){
		Stack * stack = state.stack;
		if (stack->is<LUA_TNUMBER>(1)){
			int channel = stack->to<int>(1);
			Mix_Fading fading = Mix_FadingChannel(channel);
			switch (fading){
			case MIX_NO_FADING:
				stack->push<const std::string &>("none");
				break;
			case MIX_FADING_OUT:
				stack->push<const std::string &>("out");
				break;
			case MIX_FADING_IN:
				stack->push<const std::string &>("in");
				break;
			}
			return 1;
		}
		return 0;
	}
Ejemplo n.º 8
0
int cAudio :: isSoundFading( int SoundChannel )
{
	if( !bSounds || !bInitialised )
	{
		return 0;
	}

	Mix_Fading status = Mix_FadingChannel( SoundChannel );

	if( status == MIX_NO_FADING )
	{
		return 0;
	}
	else if( status == MIX_FADING_IN )
	{
		return 1;
	}
	else if( status == MIX_FADING_OUT )
	{
		return 2;
	}

	return 0;
}