[GB.SDL2]

* NEW: Channel.Distance is a new property that defines the channel 
  distance, between 0 (near) and 255 (far).
* NEW: Channel.Angle is a new property that defines the channel direction,
  0° being the front, 90° the right, 180° behind and 270° the left.
* NEW: Channel.Reverse is a new boolean property that reverses the channel
  stereo.
* NEW: Music.SoundFontPath is a new property to tell SDL the directories 
  where the MIDI sound font files are stored.


git-svn-id: svn://localhost/gambas/trunk@6780 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2014-12-30 23:10:56 +00:00
parent f811768f78
commit c9d87bf8b9
3 changed files with 85 additions and 4 deletions

View File

@ -43,7 +43,7 @@ static void free_channel(CCHANNEL *ch)
GB.Unref(POINTER(&ch->sound));
ch->sound = NULL;
ch->free = 0;
ch->free = FALSE;
_pipe_usage--;
if (_pipe_usage == 0)
@ -79,7 +79,7 @@ static void channel_finished_cb(int channel)
if (!ch)
return;
ch->free = write(_pipe[1], &buf, 1) == 1;
ch->free = (write(_pipe[1], &buf, 1) == 1);
}
static void return_channel(int channel, CSOUND *sound)
@ -166,6 +166,12 @@ void CHANNEL_exit()
close(_pipe[1]);
}
static void update_channel_effect(CCHANNEL *_object)
{
if (Mix_SetPosition(THIS->channel, THIS->angle, THIS->distance) == 0)
GB.Error("Unable to set effect: &1", Mix_GetError());
}
//-------------------------------------------------------------------------
BEGIN_METHOD(Channels_get, GB_INTEGER index)
@ -261,6 +267,53 @@ BEGIN_PROPERTY(Channel_Volume)
END_PROPERTY
BEGIN_PROPERTY(Channel_Distance)
if (READ_PROPERTY)
GB.ReturnInteger(THIS->distance);
else
{
int d = VPROP(GB_INTEGER);
if (d < 0 || d > 255)
{
GB.Error(GB_ERR_ARG);
return;
}
THIS->distance = d;
update_channel_effect(THIS);
}
END_PROPERTY
BEGIN_PROPERTY(Channel_Angle)
if (READ_PROPERTY)
GB.ReturnInteger(THIS->angle);
else
{
THIS->angle = VPROP(GB_INTEGER);
update_channel_effect(THIS);
}
END_PROPERTY
BEGIN_PROPERTY(Channel_Reverse)
if (READ_PROPERTY)
GB.ReturnBoolean(THIS->reverse);
else
{
bool v = VPROP(GB_BOOLEAN);
if (Mix_SetReverseStereo(THIS->channel, v))
THIS->reverse = v;
else
GB.Error(Mix_GetError());
}
END_PROPERTY
//-------------------------------------------------------------------------
GB_DESC ChannelsDesc[] =
@ -286,6 +339,9 @@ GB_DESC ChannelDesc[] =
GB_METHOD("Stop", NULL, Channel_Stop, "[(FadeOut)f]"),
GB_PROPERTY("Volume", "i", Channel_Volume),
GB_PROPERTY("Distance", "i", Channel_Distance),
GB_PROPERTY("Angle", "i", Channel_Angle),
GB_PROPERTY("Reverse", "b", Channel_Reverse),
GB_END_DECLARE
};

View File

@ -32,7 +32,10 @@ typedef
GB_BASE ob;
int channel;
CSOUND *sound;
int free;
uchar distance;
ushort angle;
unsigned reverse : 1;
unsigned free : 1;
}
CCHANNEL;

View File

@ -140,7 +140,18 @@ BEGIN_PROPERTY(Music_Pos)
GB.ReturnFloat(get_music_pos());
else
{
double pos = VPROP(GB_FLOAT);
double pos;
if (!_music)
return;
if (Mix_GetMusicType(_music) == MUS_MOD)
{
GB.Error("Seeking is not supported on MOD files");
return;
}
pos = VPROP(GB_FLOAT);
Mix_RewindMusic();
if (Mix_SetMusicPosition(pos) == 0)
_ref_pos = pos;
@ -178,12 +189,23 @@ BEGIN_PROPERTY(Music_State)
END_PROPERTY
BEGIN_PROPERTY(Music_SoundFontPath)
if (READ_PROPERTY)
GB.ReturnNewZeroString(Mix_GetSoundFonts());
else
Mix_SetSoundFonts(GB.ToZeroString(PROP(GB_STRING)));
END_PROPERTY
//-------------------------------------------------------------------------
GB_DESC MusicDesc[] =
{
GB_DECLARE_STATIC("Music"),
GB_STATIC_PROPERTY("SoundFontPath", "s", Music_SoundFontPath),
GB_STATIC_METHOD("Load", NULL, Music_Load, "(File)s"),
GB_STATIC_METHOD("Play", NULL, Music_Play, "[(Loops)i(FadeIn)f]"),
GB_STATIC_METHOD("Pause", NULL, Music_Pause, NULL),