rubysdl 1.3.1 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +22 -2
- data/NEWS.en +80 -0
- data/NEWS.ja +83 -0
- data/README.en +2 -1
- data/README.ja +2 -2
- data/doc-en/Makefile +18 -0
- data/doc-en/cdrom.rsd +417 -0
- data/doc-en/collision.rsd +174 -0
- data/doc-en/event.rsd +1476 -0
- data/doc-en/font.rsd +811 -0
- data/doc-en/general.rsd +43 -0
- data/doc-en/init.rsd +168 -0
- data/doc-en/joystick.rsd +401 -0
- data/doc-en/mixer.rsd +869 -0
- data/doc-en/mpeg.rsd +585 -0
- data/doc-en/opengl.rsd +155 -0
- data/doc-en/sdlskk.rsd +472 -0
- data/doc-en/time.rsd +46 -0
- data/doc-en/video.rsd +2806 -0
- data/doc-en/wm.rsd +112 -0
- data/doc/Makefile +1 -1
- data/doc/cdrom.rsd +3 -3
- data/doc/event.rsd +178 -179
- data/doc/general.rsd +10 -0
- data/doc/init.rsd +2 -2
- data/doc/joystick.rsd +29 -5
- data/doc/mixer.rsd +20 -0
- data/doc/rsd.rb +42 -9
- data/doc/sdlskk.rsd +7 -7
- data/doc/video.rsd +461 -168
- data/doc/wm.rsd +2 -2
- data/extconf.rb +1 -8
- data/lib/rubysdl_aliases.rb +52 -190
- data/lib/rubysdl_compatible_ver1.rb +243 -0
- data/lib/sdl.rb +58 -92
- data/rubysdl.h +59 -68
- data/rubysdl_cdrom.c +125 -102
- data/{rubysdl_doc.en.rd → rubysdl_doc_old.en.rd} +3 -2
- data/rubysdl_event.c +318 -255
- data/rubysdl_event_key.c +299 -287
- data/rubysdl_image.c +37 -13
- data/rubysdl_joystick.c +180 -67
- data/rubysdl_kanji.c +61 -75
- data/rubysdl_main.c +65 -138
- data/rubysdl_mixer.c +339 -214
- data/rubysdl_mouse.c +50 -43
- data/rubysdl_opengl.c +31 -28
- data/rubysdl_pixel.c +17 -28
- data/rubysdl_ref.en.html +5658 -0
- data/rubysdl_ref.en.rd +6337 -0
- data/rubysdl_ref.html +2253 -1964
- data/rubysdl_ref.rd +823 -469
- data/rubysdl_rwops.c +9 -6
- data/rubysdl_sdlskk.c +137 -165
- data/rubysdl_sge_video.c +355 -469
- data/rubysdl_smpeg.c +189 -190
- data/rubysdl_time.c +1 -1
- data/rubysdl_ttf.c +147 -215
- data/rubysdl_video.c +486 -405
- data/rubysdl_wm.c +30 -30
- data/sample/aadraw.rb +9 -9
- data/sample/alpha.rb +12 -13
- data/sample/alphadraw.rb +10 -10
- data/sample/bfont.rb +4 -4
- data/sample/cdrom.rb +11 -4
- data/sample/collision.rb +20 -20
- data/sample/cursor.rb +5 -5
- data/sample/ellipses.rb +20 -16
- data/sample/event2.rb +11 -9
- data/sample/font.rb +4 -4
- data/sample/fpstimer.rb +3 -3
- data/sample/icon.bmp.gz +0 -0
- data/sample/icon.png +0 -0
- data/sample/joy2.rb +14 -14
- data/sample/kanji.rb +7 -7
- data/sample/load_from_io.rb +44 -0
- data/sample/movesp.rb +13 -12
- data/sample/playmod.rb +2 -3
- data/sample/plaympeg.rb +8 -8
- data/sample/playwave.rb +5 -6
- data/sample/sdlskk.rb +11 -11
- data/sample/sgetest.rb +14 -12
- data/sample/stetris.rb +12 -13
- data/sample/testgl.rb +13 -14
- data/sample/testsprite.rb +12 -11
- data/sample/transformblit.rb +23 -22
- metadata +62 -35
- data/rubysdl_event2.c +0 -417
data/rubysdl_main.c
CHANGED
@@ -20,89 +20,45 @@
|
|
20
20
|
|
21
21
|
#define DEF_GLOBAL
|
22
22
|
#include "rubysdl.h"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
/* declaration of initialize functions */
|
27
|
-
void init_video();
|
28
|
-
#ifdef HAVE_SGE
|
29
|
-
void init_sge_video();
|
30
|
-
#else
|
31
|
-
void init_pixel();
|
32
|
-
#endif
|
33
|
-
#ifdef DEF_OPENGL
|
34
|
-
void init_opengl();
|
35
|
-
#ifdef INIT_OGLMODULE_FROM_SDL
|
36
|
-
void Init_opengl();
|
37
|
-
#endif
|
38
|
-
#endif
|
39
|
-
#ifdef HAVE_SDL_IMAGE
|
40
|
-
void init_sdl_image();
|
41
|
-
#endif
|
42
|
-
void init_event();
|
43
|
-
#ifdef DEF_EVENT2
|
44
|
-
void init_event2();
|
45
|
-
#endif
|
46
|
-
void init_keyEvent();
|
47
|
-
void init_mouse();
|
48
|
-
void init_joystick();
|
49
|
-
void init_cdrom();
|
50
|
-
void init_time();
|
51
|
-
void init_wm();
|
52
|
-
void init_kanji(void);
|
53
|
-
#ifdef HAVE_SDL_TTF
|
54
|
-
void init_ttf();
|
55
|
-
void quit_ttf();
|
56
|
-
#endif
|
57
|
-
#ifdef HAVE_SDL_MIXER
|
58
|
-
void init_mixer();
|
59
|
-
void quit_mixer();
|
60
|
-
#endif
|
61
|
-
#ifdef HAVE_SMPEG
|
62
|
-
void init_smpeg();
|
63
|
-
#endif
|
64
|
-
|
65
|
-
#ifdef HAVE_SDLSKK
|
66
|
-
void init_sdlskk();
|
67
|
-
#endif
|
68
|
-
|
69
|
-
static void sdl_quit();
|
70
|
-
static VALUE sdl_init(VALUE obj,VALUE flags)
|
23
|
+
|
24
|
+
static VALUE sdl_s_init(VALUE mod, VALUE flags)
|
71
25
|
{
|
72
|
-
Uint32 flag;
|
73
|
-
|
74
26
|
rb_secure(4);
|
75
|
-
|
76
|
-
|
77
|
-
rb_raise(eSDLError,"Couldn't initialize SDL: %s",SDL_GetError());
|
27
|
+
if( SDL_Init(NUM2UINT(flags)) < 0 )
|
28
|
+
rb_raise(eSDLError, "Couldn't initialize SDL: %s", SDL_GetError());
|
78
29
|
return Qnil;
|
79
30
|
}
|
80
31
|
|
81
|
-
static VALUE
|
32
|
+
static VALUE sdl_s_initSubSystem(VALUE mod, VALUE flags)
|
82
33
|
{
|
83
34
|
if( SDL_InitSubSystem(NUM2UINT(flags)) < 0 )
|
84
|
-
rb_raise(eSDLError,"Couldn't initialize SDL subsystem: %s",SDL_GetError());
|
35
|
+
rb_raise(eSDLError, "Couldn't initialize SDL subsystem: %s", SDL_GetError());
|
85
36
|
return Qnil;
|
86
37
|
}
|
87
38
|
|
88
|
-
static VALUE
|
39
|
+
static VALUE sdl_s_inited_system(VALUE mod, VALUE flags)
|
89
40
|
{
|
90
|
-
return UINT2NUM(
|
41
|
+
return UINT2NUM(SDL_WasInit(NUM2UINT(flags)));
|
91
42
|
}
|
92
43
|
|
93
|
-
static VALUE
|
44
|
+
static VALUE sdl_s_putenv(VALUE mod, VALUE var)
|
94
45
|
{
|
95
|
-
|
96
|
-
|
46
|
+
rb_secure(4);
|
47
|
+
SafeStringValue(var);
|
48
|
+
|
49
|
+
if( putenv(RSTRING_PTR(var)) < 0 ){
|
50
|
+
rb_raise(eSDLError, "Can't put environ variable: %s", RSTRING_PTR(var));
|
97
51
|
}
|
98
52
|
return Qnil;
|
99
53
|
}
|
100
54
|
|
101
|
-
static VALUE
|
55
|
+
static VALUE sdl_s_getenv(VALUE mod, VALUE name)
|
102
56
|
{
|
103
|
-
char* result
|
104
|
-
|
105
|
-
|
57
|
+
char* result;
|
58
|
+
SafeStringValue(name);
|
59
|
+
result = getenv(RSTRING_PTR(name));
|
60
|
+
if(result == NULL){
|
61
|
+
rb_raise(eSDLError, "Can't get environ variable: %s", RSTRING_PTR(name));
|
106
62
|
}
|
107
63
|
return rb_str_new2(result);
|
108
64
|
}
|
@@ -112,91 +68,62 @@ int rubysdl_is_quit(void)
|
|
112
68
|
{
|
113
69
|
return is_quit;
|
114
70
|
}
|
115
|
-
static void sdl_quit()
|
71
|
+
static void sdl_quit(VALUE v)
|
116
72
|
{
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
quit_ttf();
|
122
|
-
#endif
|
123
|
-
is_quit = 1;
|
73
|
+
if(rubysdl_is_quit())
|
74
|
+
return;
|
75
|
+
rubysdl_quit_Mixer();
|
76
|
+
rubysdl_quit_TTF();
|
124
77
|
SDL_Quit();
|
125
|
-
|
78
|
+
is_quit = 1;
|
126
79
|
}
|
127
80
|
|
128
|
-
static VALUE
|
81
|
+
static VALUE sdl_s_quit(VALUE obj)
|
129
82
|
{
|
130
|
-
sdl_quit();
|
83
|
+
sdl_quit(0);
|
131
84
|
return Qnil;
|
132
85
|
}
|
133
86
|
|
134
|
-
static void defineConst()
|
135
|
-
{
|
136
|
-
rb_define_const(mSDL,"INIT_TIMER",UINT2NUM(SDL_INIT_TIMER));
|
137
|
-
rb_define_const(mSDL,"INIT_AUDIO",UINT2NUM(SDL_INIT_AUDIO));
|
138
|
-
rb_define_const(mSDL,"INIT_VIDEO",UINT2NUM(SDL_INIT_VIDEO));
|
139
|
-
rb_define_const(mSDL,"INIT_CDROM",UINT2NUM(SDL_INIT_CDROM));
|
140
|
-
rb_define_const(mSDL,"INIT_JOYSTICK",UINT2NUM(SDL_INIT_JOYSTICK));
|
141
|
-
rb_define_const(mSDL,"INIT_NOPARACHUTE",UINT2NUM(SDL_INIT_NOPARACHUTE));
|
142
|
-
rb_define_const(mSDL,"INIT_EVENTTHREAD",UINT2NUM(SDL_INIT_EVENTTHREAD));
|
143
|
-
rb_define_const(mSDL,"INIT_EVERYTHING",UINT2NUM(SDL_INIT_EVERYTHING));
|
144
|
-
}
|
145
|
-
|
146
|
-
|
147
87
|
void Init_sdl()
|
148
88
|
{
|
149
|
-
mSDL = rb_define_module("SDL");
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
rb_define_module_function(mSDL,"
|
154
|
-
rb_define_module_function(mSDL,"
|
155
|
-
rb_define_module_function(mSDL,"
|
156
|
-
rb_define_module_function(mSDL,"
|
89
|
+
VALUE mSDL = rb_define_module("SDL");
|
90
|
+
VALUE cSurface;
|
91
|
+
|
92
|
+
eSDLError = rb_define_class_under(mSDL, "Error", rb_eStandardError);
|
93
|
+
rb_define_module_function(mSDL, "init", sdl_s_init, 1);
|
94
|
+
rb_define_module_function(mSDL, "initedSystem", sdl_s_inited_system, 1);
|
95
|
+
rb_define_module_function(mSDL, "initSubSystem", sdl_s_initSubSystem, 1);
|
96
|
+
rb_define_module_function(mSDL, "quit", sdl_s_quit, 0);
|
97
|
+
rb_define_module_function(mSDL, "putenv", sdl_s_putenv, 1);
|
98
|
+
rb_define_module_function(mSDL, "getenv", sdl_s_getenv, 1);
|
157
99
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
init_wm();
|
186
|
-
init_kanji();
|
187
|
-
#ifdef HAVE_SDL_TTF
|
188
|
-
init_ttf();
|
189
|
-
#endif
|
190
|
-
#ifdef HAVE_SDL_MIXER
|
191
|
-
init_mixer();
|
192
|
-
#endif
|
193
|
-
#ifdef HAVE_SMPEG
|
194
|
-
init_smpeg();
|
195
|
-
#endif
|
196
|
-
#ifdef HAVE_SDLSKK
|
197
|
-
init_sdlskk();
|
198
|
-
#endif
|
199
|
-
rb_set_end_proc(sdl_quit,0);
|
100
|
+
rb_define_const(mSDL, "INIT_TIMER", UINT2NUM(SDL_INIT_TIMER));
|
101
|
+
rb_define_const(mSDL, "INIT_AUDIO", UINT2NUM(SDL_INIT_AUDIO));
|
102
|
+
rb_define_const(mSDL, "INIT_VIDEO", UINT2NUM(SDL_INIT_VIDEO));
|
103
|
+
rb_define_const(mSDL, "INIT_CDROM", UINT2NUM(SDL_INIT_CDROM));
|
104
|
+
rb_define_const(mSDL, "INIT_JOYSTICK", UINT2NUM(SDL_INIT_JOYSTICK));
|
105
|
+
rb_define_const(mSDL, "INIT_NOPARACHUTE", UINT2NUM(SDL_INIT_NOPARACHUTE));
|
106
|
+
rb_define_const(mSDL, "INIT_EVENTTHREAD", UINT2NUM(SDL_INIT_EVENTTHREAD));
|
107
|
+
rb_define_const(mSDL, "INIT_EVERYTHING", UINT2NUM(SDL_INIT_EVERYTHING));
|
108
|
+
|
109
|
+
|
110
|
+
cSurface = rubysdl_init_video(mSDL);
|
111
|
+
rubysdl_init_sge(mSDL, cSurface);
|
112
|
+
rubysdl_init_GL(mSDL);
|
113
|
+
rubysdl_init_image(mSDL, cSurface);
|
114
|
+
rubysdl_init_Event(mSDL);
|
115
|
+
rubysdl_init_Key(mSDL);
|
116
|
+
rubysdl_init_Mouse(mSDL);
|
117
|
+
rubysdl_init_Joystick(mSDL);
|
118
|
+
rubysdl_init_CD(mSDL);
|
119
|
+
rubysdl_init_time(mSDL);
|
120
|
+
rubysdl_init_WM(mSDL);
|
121
|
+
rubysdl_init_Kanji(mSDL);
|
122
|
+
rubysdl_init_TTF(mSDL);
|
123
|
+
rubysdl_init_Mixer(mSDL);
|
124
|
+
rubysdl_init_MPEG(mSDL);
|
125
|
+
rubysdl_init_SKK(mSDL);
|
126
|
+
rb_set_end_proc(sdl_quit, 0);
|
200
127
|
}
|
201
128
|
|
202
129
|
|
data/rubysdl_mixer.c
CHANGED
@@ -17,33 +17,86 @@
|
|
17
17
|
License along with this library; if not, write to the Free Software
|
18
18
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
19
|
*/
|
20
|
-
#ifdef HAVE_SDL_MIXER
|
21
|
-
|
22
20
|
#include "rubysdl.h"
|
21
|
+
#ifdef HAVE_SDL_MIXER
|
23
22
|
#define USE_RWOPS
|
24
23
|
#include <SDL_mixer.h>
|
25
24
|
|
26
|
-
static
|
27
|
-
static
|
25
|
+
static VALUE mMixer;
|
26
|
+
static VALUE cWave;
|
27
|
+
static VALUE cMusic;
|
28
28
|
|
29
29
|
static VALUE playing_wave = Qnil;
|
30
|
-
static VALUE playing_music=Qnil;
|
30
|
+
static VALUE playing_music = Qnil;
|
31
31
|
|
32
|
-
static
|
32
|
+
static int Mix_opened(void)
|
33
33
|
{
|
34
|
-
|
35
|
-
Mix_FreeChunk( chunk );
|
36
|
-
}
|
34
|
+
return Mix_QuerySpec(NULL, NULL, NULL);
|
37
35
|
}
|
38
36
|
|
39
|
-
|
37
|
+
typedef struct {
|
38
|
+
Mix_Chunk* chunk;
|
39
|
+
} Wave;
|
40
|
+
|
41
|
+
typedef struct {
|
42
|
+
Mix_Music* music;
|
43
|
+
} Music;
|
44
|
+
|
45
|
+
DEFINE_GET_STRUCT(Wave, GetWave, cWave, "SDL::Mixer::Wave");
|
46
|
+
static Mix_Chunk* Get_Mix_Chunk(VALUE obj)
|
40
47
|
{
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
Wave* wave = GetWave(obj);
|
49
|
+
if(wave->chunk == NULL)
|
50
|
+
rb_raise(eSDLError, "Wave data is already disposed");
|
51
|
+
return wave->chunk;
|
52
|
+
}
|
53
|
+
static void Wave_free(Wave* wave)
|
54
|
+
{
|
55
|
+
if(Mix_opened() && wave->chunk)
|
56
|
+
Mix_FreeChunk(wave->chunk);
|
57
|
+
free(wave);
|
58
|
+
}
|
59
|
+
static VALUE Wave_s_alloc(VALUE klass)
|
60
|
+
{
|
61
|
+
Wave* wave = ALLOC(Wave);
|
62
|
+
wave->chunk = NULL;
|
63
|
+
return Data_Wrap_Struct(klass, 0, Wave_free, wave);
|
64
|
+
}
|
65
|
+
static VALUE Wave_create(Mix_Chunk* chunk)
|
66
|
+
{
|
67
|
+
VALUE newobj = Wave_s_alloc(cWave);
|
68
|
+
GetWave(newobj)->chunk = chunk;
|
69
|
+
return newobj;
|
44
70
|
}
|
45
71
|
|
46
|
-
|
72
|
+
DEFINE_GET_STRUCT(Music, GetMusic, cMusic, "SDL::Mixer::Music");
|
73
|
+
static Mix_Music* Get_Mix_Music(VALUE obj)
|
74
|
+
{
|
75
|
+
Music* mus = GetMusic(obj);
|
76
|
+
if(mus->music == NULL)
|
77
|
+
rb_raise(eSDLError, "Wave data is already disposed");
|
78
|
+
return mus->music;
|
79
|
+
}
|
80
|
+
static void Music_free(Music* mus)
|
81
|
+
{
|
82
|
+
if(Mix_opened() && mus->music)
|
83
|
+
Mix_FreeMusic(mus->music);
|
84
|
+
free(mus);
|
85
|
+
}
|
86
|
+
static VALUE Music_s_alloc(VALUE klass)
|
87
|
+
{
|
88
|
+
Music* mus = ALLOC(Music);
|
89
|
+
mus->music = NULL;
|
90
|
+
return Data_Wrap_Struct(klass, 0, Music_free, mus);
|
91
|
+
}
|
92
|
+
static VALUE Music_create(Mix_Music* music)
|
93
|
+
{
|
94
|
+
VALUE newobj = Music_s_alloc(cMusic);
|
95
|
+
GetMusic(newobj)->music = music;
|
96
|
+
return newobj;
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE Mixer_s_driverName(VALUE mod)
|
47
100
|
{
|
48
101
|
char driver_name[512];
|
49
102
|
if(SDL_AudioDriverName(driver_name, sizeof(driver_name)) == NULL)
|
@@ -51,268 +104,314 @@ static VALUE mix_audioDriverName(VALUE mod)
|
|
51
104
|
return rb_str_new2(driver_name);
|
52
105
|
}
|
53
106
|
|
54
|
-
static VALUE
|
55
|
-
VALUE channels,VALUE chunksize)
|
107
|
+
static VALUE Mixer_s_open(VALUE mod, VALUE frequency, VALUE format,
|
108
|
+
VALUE channels, VALUE chunksize)
|
56
109
|
{
|
57
|
-
|
58
|
-
|
110
|
+
rb_secure(4);
|
111
|
+
|
112
|
+
if(Mix_opened()){
|
113
|
+
rb_raise(eSDLError, "already initialize SDL::Mixer");
|
59
114
|
}
|
60
|
-
if( Mix_OpenAudio(
|
61
|
-
|
62
|
-
rb_raise(eSDLError,"Couldn't open audio: %s",SDL_GetError());
|
115
|
+
if( Mix_OpenAudio(NUM2INT(frequency), NUM2UINT(format), NUM2INT(channels),
|
116
|
+
NUM2INT(chunksize)) < 0 ){
|
117
|
+
rb_raise(eSDLError, "Couldn't open audio: %s", SDL_GetError());
|
63
118
|
}
|
64
119
|
|
65
|
-
mix_opened = 1;
|
66
120
|
return Qnil;
|
67
121
|
}
|
68
122
|
|
69
|
-
static VALUE
|
123
|
+
static VALUE Mixer_s_close(VALUE mod)
|
124
|
+
{
|
125
|
+
rb_secure(4);
|
126
|
+
Mix_CloseAudio();
|
127
|
+
return Qnil;
|
128
|
+
}
|
129
|
+
|
130
|
+
static VALUE Mixer_s_spec(VALUE mod)
|
70
131
|
{
|
71
132
|
int rate;
|
72
133
|
Uint16 format;
|
73
134
|
int channels;
|
74
135
|
|
75
|
-
if( !Mix_QuerySpec(&rate
|
76
|
-
rb_raise(eSDLError,"audio have not been opened yet: %s",
|
77
|
-
|
136
|
+
if( !Mix_QuerySpec(&rate, &format, &channels) )
|
137
|
+
rb_raise(eSDLError,"audio have not been opened yet: %s",
|
138
|
+
Mix_GetError());
|
139
|
+
return rb_ary_new3(3, INT2NUM(rate), UINT2NUM(format), INT2NUM(channels));
|
140
|
+
|
78
141
|
}
|
79
142
|
|
80
|
-
static VALUE
|
143
|
+
static VALUE Mixer_s_allocateChannels(VALUE mod, VALUE numchannels)
|
81
144
|
{
|
145
|
+
rb_secure(4);
|
82
146
|
return INT2FIX( Mix_AllocateChannels(NUM2INT(numchannels)) );
|
83
147
|
}
|
84
148
|
|
85
149
|
/* Returns which channel was used to play the sound. */
|
86
|
-
static VALUE
|
150
|
+
static VALUE Mixer_s_playChannel(VALUE mod, VALUE channel, VALUE wave, VALUE loops)
|
87
151
|
{
|
88
|
-
|
89
|
-
|
152
|
+
int play_channel;
|
153
|
+
rb_secure(4);
|
154
|
+
|
155
|
+
play_channel = Mix_PlayChannel(NUM2INT(channel),
|
156
|
+
Get_Mix_Chunk(wave),
|
157
|
+
NUM2INT(loops));
|
158
|
+
|
159
|
+
if( play_channel == -1 )
|
160
|
+
rb_raise(eSDLError, "couldn't play wave: %s",
|
161
|
+
Mix_GetError());
|
90
162
|
|
91
|
-
|
92
|
-
|
93
|
-
|
163
|
+
rb_ary_store(playing_wave, play_channel, wave);/* to avoid gc problem */
|
164
|
+
return INT2FIX(play_channel);
|
165
|
+
}
|
94
166
|
|
95
|
-
|
96
|
-
|
97
|
-
|
167
|
+
static VALUE Mixer_s_playChannelTimed(VALUE mod,
|
168
|
+
VALUE channel,
|
169
|
+
VALUE wave,
|
170
|
+
VALUE loops,
|
171
|
+
VALUE ticks)
|
172
|
+
{
|
173
|
+
int play_channel;
|
174
|
+
|
175
|
+
play_channel = Mix_PlayChannelTimed(NUM2INT(channel),
|
176
|
+
Get_Mix_Chunk(wave),
|
177
|
+
NUM2INT(loops),
|
178
|
+
NUM2INT(ticks));
|
179
|
+
if( play_channel == -1 ){
|
180
|
+
rb_raise(eSDLError, "couldn't play wave: %s",
|
181
|
+
Mix_GetError());
|
98
182
|
}
|
99
183
|
|
100
|
-
rb_ary_store(playing_wave,
|
101
|
-
return INT2FIX(
|
184
|
+
rb_ary_store(playing_wave, play_channel, wave);/* to avoid gc problem */
|
185
|
+
return INT2FIX(play_channel);
|
102
186
|
}
|
103
187
|
|
104
|
-
static VALUE
|
105
|
-
|
188
|
+
static VALUE Mixer_s_fadeInChannel(VALUE mod,
|
189
|
+
VALUE channel,
|
190
|
+
VALUE wave,
|
191
|
+
VALUE loops,
|
192
|
+
VALUE ms)
|
106
193
|
{
|
107
|
-
Mix_Chunk *chunk;
|
108
194
|
int playing_channel;
|
109
195
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
playing_channel = Mix_PlayChannelTimed(NUM2INT(channel),chunk,NUM2INT(loops),
|
115
|
-
NUM2INT(ticks));
|
196
|
+
playing_channel = Mix_FadeInChannel(NUM2INT(channel),
|
197
|
+
Get_Mix_Chunk(wave),
|
198
|
+
NUM2INT(loops),
|
199
|
+
NUM2INT(ms));
|
116
200
|
if( playing_channel == -1 ){
|
117
|
-
rb_raise(
|
201
|
+
rb_raise(eSDLError, "couldn't play wave: %s",
|
202
|
+
Mix_GetError());
|
118
203
|
}
|
119
|
-
|
120
|
-
rb_ary_store(playing_wave,playing_channel,wave)
|
204
|
+
/* to avoid gc problem */
|
205
|
+
rb_ary_store(playing_wave, playing_channel, wave);
|
121
206
|
return INT2FIX(playing_channel);
|
122
207
|
}
|
123
208
|
|
124
|
-
static VALUE
|
125
|
-
|
209
|
+
static VALUE Mixer_s_fadeInChannelTimed(VALUE mod,
|
210
|
+
VALUE channel,
|
211
|
+
VALUE wave,
|
212
|
+
VALUE loops,
|
213
|
+
VALUE ms, VALUE ticks)
|
126
214
|
{
|
127
|
-
Mix_Chunk *chunk;
|
128
215
|
int playing_channel;
|
129
216
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
NUM2INT(ms));
|
217
|
+
playing_channel = Mix_FadeInChannelTimed(NUM2INT(channel),
|
218
|
+
Get_Mix_Chunk(wave),
|
219
|
+
NUM2INT(loops),
|
220
|
+
NUM2INT(ms),
|
221
|
+
NUM2INT(ticks));
|
136
222
|
if( playing_channel == -1 ){
|
137
|
-
rb_raise(
|
223
|
+
rb_raise(eSDLError, "couldn't play wave: %s",
|
224
|
+
Mix_GetError());
|
138
225
|
}
|
139
|
-
|
140
|
-
rb_ary_store(playing_wave,playing_channel,wave)
|
226
|
+
/* to avoid gc problem */
|
227
|
+
rb_ary_store(playing_wave, playing_channel, wave);
|
141
228
|
return INT2FIX(playing_channel);
|
142
229
|
}
|
143
230
|
|
144
|
-
static VALUE
|
145
|
-
VALUE ms, VALUE ticks)
|
231
|
+
static VALUE Mixer_s_play_p(VALUE mod, VALUE channel)
|
146
232
|
{
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
if( ! rb_obj_is_kind_of(wave,cWave) )
|
151
|
-
rb_raise(rb_eArgError,"type mismatch: SDL::Mixer::Wave is expected");
|
152
|
-
Data_Get_Struct(wave,Mix_Chunk,chunk);
|
153
|
-
|
154
|
-
playing_channel = Mix_FadeInChannelTimed(NUM2INT(channel),chunk,NUM2INT(loops),
|
155
|
-
NUM2INT(ms), NUM2INT(ticks));
|
156
|
-
if( playing_channel == -1 ){
|
157
|
-
rb_raise( eSDLError, "couldn't play wave: %s", Mix_GetError() );
|
158
|
-
}
|
233
|
+
return INT2BOOL(Mix_Playing(NUM2INT(channel)));
|
234
|
+
}
|
159
235
|
|
160
|
-
|
161
|
-
|
236
|
+
static VALUE Mixer_s_playing_channels(VALUE mod)
|
237
|
+
{
|
238
|
+
return INT2NUM(Mix_Playing(-1));
|
162
239
|
}
|
163
240
|
|
164
|
-
static VALUE
|
241
|
+
static VALUE Wave_s_load(VALUE class, VALUE filename)
|
165
242
|
{
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
243
|
+
Mix_Chunk *chunk;
|
244
|
+
|
245
|
+
rb_secure(4);
|
246
|
+
SafeStringValue(filename);
|
247
|
+
|
248
|
+
chunk = Mix_LoadWAV(RSTRING_PTR(filename));
|
249
|
+
if( chunk == NULL ){
|
250
|
+
rb_raise(eSDLError, "Couldn't load wave file %s: %s",
|
251
|
+
RSTRING_PTR(filename), SDL_GetError());
|
170
252
|
}
|
253
|
+
return Wave_create(chunk);
|
171
254
|
}
|
172
|
-
|
173
|
-
static VALUE
|
255
|
+
|
256
|
+
static VALUE Wave_s_loadFromIO(VALUE class, VALUE io)
|
174
257
|
{
|
175
258
|
Mix_Chunk *wave;
|
176
|
-
|
177
|
-
wave = Mix_LoadWAV( GETCSTR(filename) );
|
259
|
+
wave = Mix_LoadWAV_RW(rubysdl_RWops_from_ruby_obj(io), 1);
|
178
260
|
if( wave == NULL ){
|
179
|
-
rb_raise(
|
180
|
-
|
261
|
+
rb_raise(eSDLError, "Couldn't load wave file from IO: %s",
|
262
|
+
Mix_GetError());
|
181
263
|
}
|
182
|
-
return
|
264
|
+
return Wave_create(wave);
|
183
265
|
}
|
184
266
|
|
185
|
-
static VALUE
|
267
|
+
static VALUE Wave_s_loadFromString(VALUE class, VALUE str)
|
186
268
|
{
|
187
269
|
Mix_Chunk *wave;
|
188
|
-
|
270
|
+
rb_secure(4);
|
271
|
+
SafeStringValue(str);
|
272
|
+
|
273
|
+
wave = Mix_LoadWAV_RW(SDL_RWFromConstMem(RSTRING_PTR(str),
|
274
|
+
RSTRING_LEN(str)),
|
275
|
+
1);
|
189
276
|
if( wave == NULL ){
|
190
|
-
rb_raise(eSDLError,"Couldn't load wave file from
|
277
|
+
rb_raise(eSDLError, "Couldn't load wave file from String: %s",
|
191
278
|
Mix_GetError());
|
192
279
|
}
|
193
|
-
return
|
280
|
+
return Wave_create(wave);
|
194
281
|
}
|
195
|
-
|
282
|
+
|
283
|
+
|
196
284
|
/* Volume setting functions and methods : volume in 0..128 */
|
197
|
-
static VALUE
|
285
|
+
static VALUE Mixer_s_setVolume(VALUE mod, VALUE channel, VALUE volume)
|
198
286
|
{
|
199
|
-
|
287
|
+
rb_secure(4);
|
288
|
+
return INT2FIX(Mix_Volume(NUM2INT(channel), NUM2INT(volume)));
|
200
289
|
}
|
201
|
-
|
290
|
+
|
291
|
+
static VALUE Wave_s_setVolume(VALUE self, VALUE volume)
|
202
292
|
{
|
203
|
-
|
204
|
-
Data_Get_Struct(obj,Mix_Chunk,chunk);
|
205
|
-
return INT2FIX( Mix_VolumeChunk( chunk,NUM2INT(volume) ) );
|
293
|
+
return INT2FIX(Mix_VolumeChunk(Get_Mix_Chunk(self), NUM2INT(volume)));
|
206
294
|
}
|
207
295
|
|
208
296
|
/* Halt,Pause function */
|
209
|
-
static VALUE
|
297
|
+
static VALUE Mixer_s_halt(VALUE mod, VALUE channel)
|
210
298
|
{
|
299
|
+
rb_secure(4);
|
211
300
|
Mix_HaltChannel(NUM2INT(channel));
|
212
301
|
return Qnil;
|
213
302
|
}
|
214
|
-
|
303
|
+
|
304
|
+
static VALUE Mixer_s_pause(VALUE mod, VALUE channel)
|
215
305
|
{
|
306
|
+
rb_secure(4);
|
216
307
|
Mix_Pause(NUM2INT(channel));
|
217
308
|
return Qnil;
|
218
309
|
}
|
219
|
-
|
310
|
+
|
311
|
+
static VALUE Mixer_s_resume(VALUE mod, VALUE channel)
|
220
312
|
{
|
313
|
+
rb_secure(4);
|
221
314
|
Mix_Resume(NUM2INT(channel));
|
222
315
|
return Qnil;
|
223
316
|
}
|
224
|
-
|
317
|
+
|
318
|
+
static VALUE Mixer_s_pause_p(VALUE mod, VALUE channel)
|
225
319
|
{
|
320
|
+
rb_secure(4);
|
226
321
|
return INT2FIX(Mix_Paused(NUM2INT(channel)));
|
227
322
|
}
|
228
|
-
static VALUE
|
323
|
+
static VALUE Mixer_s_fadeOut(VALUE mod, VALUE channel, VALUE ms)
|
229
324
|
{
|
230
325
|
return INT2FIX(Mix_FadeOutChannel(NUM2INT(channel), NUM2INT(ms)));
|
231
326
|
}
|
232
|
-
static VALUE
|
327
|
+
static VALUE Mixer_s_expire(VALUE mod, VALUE channel, VALUE ticks)
|
233
328
|
{
|
234
329
|
return INT2FIX(Mix_ExpireChannel(NUM2INT(channel),NUM2INT(ticks)));
|
235
330
|
}
|
236
|
-
static VALUE
|
331
|
+
static VALUE Mixer_s_fading(VALUE mod, VALUE which)
|
237
332
|
{
|
238
333
|
if( NUM2INT(which) < 0 || Mix_AllocateChannels(-1) <= NUM2INT(which))
|
239
334
|
rb_raise(eSDLError, "channel %d out of range", NUM2INT(which));
|
240
|
-
return INT2FIX(Mix_FadingChannel(which));
|
335
|
+
return INT2FIX(Mix_FadingChannel(NUM2INT(which)));
|
241
336
|
}
|
242
337
|
|
243
338
|
/* music functions */
|
244
|
-
#define MakeSimpleRubyFunc(rubyFunc,sdlFunc) \
|
339
|
+
#define MakeSimpleRubyFunc(rubyFunc, sdlFunc) \
|
245
340
|
static VALUE rubyFunc(VALUE mod) \
|
246
341
|
{ \
|
342
|
+
rb_secure(4); \
|
247
343
|
sdlFunc(); \
|
248
344
|
return Qnil; \
|
249
345
|
} \
|
250
346
|
|
251
|
-
static VALUE
|
347
|
+
static VALUE Mixer_s_playMusic(VALUE mod, VALUE music, VALUE loops)
|
252
348
|
{
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
playing_music=music; /* to avoid gc problem */
|
258
|
-
Mix_PlayMusic(mus,NUM2INT(loops));
|
349
|
+
rb_secure(4);
|
350
|
+
|
351
|
+
Mix_PlayMusic(Get_Mix_Music(music), NUM2INT(loops));
|
352
|
+
playing_music = music; /* to avoid gc problem */
|
259
353
|
return Qnil;
|
260
354
|
}
|
261
355
|
|
262
|
-
static VALUE
|
356
|
+
static VALUE Mixer_s_fadeInMusic(VALUE mod, VALUE music, VALUE loops, VALUE ms)
|
263
357
|
{
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
Data_Get_Struct(music,Mix_Music,mus);
|
268
|
-
Mix_FadeInMusic(mus,NUM2INT(loops),NUM2INT(ms));
|
358
|
+
rb_secure(4);
|
359
|
+
Mix_FadeInMusic(Get_Mix_Music(music), NUM2INT(loops), NUM2INT(ms));
|
360
|
+
playing_music = music; /* to avoid gc problem */
|
269
361
|
return Qnil;
|
270
362
|
}
|
271
363
|
|
272
|
-
static VALUE
|
364
|
+
static VALUE Mixer_s_setVolumeMusic(VALUE mod, VALUE volume)
|
273
365
|
{
|
366
|
+
rb_secure(4);
|
274
367
|
Mix_VolumeMusic( NUM2INT(volume) );
|
275
368
|
return Qnil;
|
276
369
|
}
|
277
370
|
|
278
|
-
static VALUE
|
371
|
+
static VALUE Mixer_s_fadeOutMusic(VALUE mod, VALUE ms)
|
279
372
|
{
|
373
|
+
rb_secure(4);
|
280
374
|
Mix_FadeOutMusic(NUM2INT(ms));
|
281
375
|
return Qnil;
|
282
376
|
}
|
283
377
|
|
284
|
-
MakeSimpleRubyFunc(
|
285
|
-
MakeSimpleRubyFunc(
|
286
|
-
MakeSimpleRubyFunc(
|
287
|
-
MakeSimpleRubyFunc(
|
378
|
+
MakeSimpleRubyFunc(Mixer_s_haltMusic, Mix_HaltMusic)
|
379
|
+
MakeSimpleRubyFunc(Mixer_s_pauseMusic, Mix_PauseMusic)
|
380
|
+
MakeSimpleRubyFunc(Mixer_s_resumeMusic, Mix_ResumeMusic)
|
381
|
+
MakeSimpleRubyFunc(Mixer_s_rewindMusic, Mix_RewindMusic)
|
288
382
|
|
289
|
-
static VALUE
|
383
|
+
static VALUE Mixer_s_pauseMusic_p(VALUE mod)
|
290
384
|
{
|
291
|
-
return
|
385
|
+
return INT2BOOL(Mix_PausedMusic());
|
292
386
|
}
|
293
387
|
|
294
|
-
static VALUE
|
388
|
+
static VALUE Mixer_s_playMusic_p(VALUE mod)
|
295
389
|
{
|
296
|
-
return
|
390
|
+
return INT2BOOL(Mix_PlayingMusic());
|
297
391
|
}
|
298
392
|
|
299
|
-
static VALUE
|
393
|
+
static VALUE Mixer_s_fadingMusic(VALUE mod)
|
300
394
|
{
|
301
395
|
return INT2FIX(Mix_FadingMusic());
|
302
396
|
}
|
303
397
|
|
304
|
-
static VALUE
|
398
|
+
static VALUE Music_s_load(VALUE class, VALUE filename)
|
305
399
|
{
|
306
400
|
Mix_Music* music;
|
307
|
-
|
401
|
+
|
402
|
+
rb_secure(4);
|
403
|
+
SafeStringValue(filename);
|
404
|
+
|
405
|
+
music = Mix_LoadMUS(RSTRING_PTR(filename));
|
308
406
|
if( music == NULL )
|
309
|
-
|
310
|
-
|
311
|
-
|
407
|
+
rb_raise(eSDLError,
|
408
|
+
"Couldn't load %s: %s", RSTRING_PTR(filename),
|
409
|
+
SDL_GetError());
|
410
|
+
return Music_create(music);
|
312
411
|
}
|
313
412
|
|
314
413
|
#ifdef HAVE_MIX_LOADMUS_RW
|
315
|
-
static VALUE
|
414
|
+
static VALUE Mixer_s_loadMusFromString(VALUE class, VALUE str)
|
316
415
|
{
|
317
416
|
Mix_Music* music;
|
318
417
|
volatile VALUE result;
|
@@ -320,103 +419,129 @@ static VALUE mix_loadMusFromString(VALUE class,VALUE str)
|
|
320
419
|
|
321
420
|
StringValue(str);
|
322
421
|
buf = rb_str_dup(str);
|
323
|
-
music = Mix_LoadMUS_RW(SDL_RWFromConstMem(
|
324
|
-
|
422
|
+
music = Mix_LoadMUS_RW(SDL_RWFromConstMem(RSTRING_PTR(buf),
|
423
|
+
RSTRING_LEN(buf)));
|
325
424
|
|
326
425
|
if( music == NULL )
|
327
426
|
rb_raise(eSDLError,
|
328
427
|
"Couldn't load from String: %s",Mix_GetError());
|
329
428
|
|
330
|
-
result =
|
429
|
+
result = Music_create(music);
|
331
430
|
rb_iv_set(result, "buf", buf);
|
332
431
|
|
333
432
|
return result;
|
334
433
|
}
|
335
434
|
#endif
|
336
435
|
|
337
|
-
static
|
338
|
-
{
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
mMixer
|
365
|
-
rb_define_module_function(mMixer,"
|
366
|
-
rb_define_module_function(mMixer,"
|
367
|
-
rb_define_module_function(mMixer,"
|
368
|
-
rb_define_module_function(mMixer,"playChannel",mix_playChannel,3);
|
369
|
-
rb_define_module_function(mMixer,"playChannelTimed", mix_playChannelTimed, 4);
|
370
|
-
rb_define_module_function(mMixer,"fadeInChannel", mix_fadeInChannel, 4);
|
371
|
-
rb_define_module_function(mMixer,"fadeInChannelTimed", mix_fadeInChannelTimed, 5);
|
372
|
-
rb_define_module_function(mMixer,"play?",mix_playing,1);
|
373
|
-
rb_define_module_function(mMixer,"setVolume",mix_volume,2);
|
374
|
-
rb_define_module_function(mMixer,"allocateChannels",mix_allocateChannels,1);
|
375
|
-
rb_define_module_function(mMixer,"halt",mix_halt,1);
|
376
|
-
rb_define_module_function(mMixer,"pause",mix_pause,1);
|
377
|
-
rb_define_module_function(mMixer,"resume",mix_resume,1);
|
378
|
-
rb_define_module_function(mMixer,"pause?",mix_paused,1);
|
379
|
-
rb_define_module_function(mMixer,"expire",mix_expire,2);
|
380
|
-
rb_define_module_function(mMixer,"fading",mix_fading,1);
|
381
|
-
rb_define_module_function(mMixer,"fadeOut",mix_fadeOut,2);
|
436
|
+
static VALUE Wave_destroy(VALUE self)
|
437
|
+
{
|
438
|
+
Wave* wave = GetWave(self);
|
439
|
+
if (wave->chunk) {
|
440
|
+
Mix_FreeChunk(wave->chunk);
|
441
|
+
wave->chunk = NULL;
|
442
|
+
}
|
443
|
+
return Qnil;
|
444
|
+
}
|
445
|
+
|
446
|
+
static VALUE Music_destroy(VALUE self)
|
447
|
+
{
|
448
|
+
Music* mus = GetMusic(self);
|
449
|
+
if (mus->music) {
|
450
|
+
Mix_FreeMusic(mus->music);
|
451
|
+
mus->music = NULL;
|
452
|
+
}
|
453
|
+
return Qnil;
|
454
|
+
}
|
455
|
+
|
456
|
+
void rubysdl_init_Mixer(VALUE mSDL)
|
457
|
+
{
|
458
|
+
mMixer = rb_define_module_under(mSDL, "Mixer");
|
459
|
+
rb_define_module_function(mMixer, "open", Mixer_s_open, 4);
|
460
|
+
rb_define_module_function(mMixer, "close", Mixer_s_close, 0);
|
461
|
+
rb_define_module_function(mMixer, "spec", Mixer_s_spec, 0);
|
462
|
+
rb_define_module_function(mMixer, "driverName", Mixer_s_driverName, 0);
|
463
|
+
rb_define_module_function(mMixer, "playChannel", Mixer_s_playChannel, 3);
|
464
|
+
rb_define_module_function(mMixer, "playChannelTimed", Mixer_s_playChannelTimed, 4);
|
465
|
+
rb_define_module_function(mMixer, "fadeInChannel", Mixer_s_playChannel, 4);
|
466
|
+
rb_define_module_function(mMixer, "fadeInChannelTimed", Mixer_s_fadeInChannelTimed, 5);
|
382
467
|
|
383
|
-
rb_define_module_function(mMixer,"
|
384
|
-
rb_define_module_function(mMixer,"
|
385
|
-
rb_define_module_function(mMixer,"
|
386
|
-
rb_define_module_function(mMixer,"
|
387
|
-
rb_define_module_function(mMixer,"fadeOutMusic",mix_fadeOutMusic,1);
|
388
|
-
rb_define_module_function(mMixer,"pauseMusic",mix_pauseMusic,0);
|
389
|
-
rb_define_module_function(mMixer,"resumeMusic",mix_resumeMusic,0);
|
390
|
-
rb_define_module_function(mMixer,"rewindMusic",mix_rewindMusic,0);
|
391
|
-
rb_define_module_function(mMixer,"pauseMusic?",mix_pausedMusic,0);
|
392
|
-
rb_define_module_function(mMixer,"playMusic?",mix_playingMusic,0);
|
393
|
-
rb_define_module_function(mMixer,"fadingMusic",mix_fadingMusic,0);
|
468
|
+
rb_define_module_function(mMixer, "play?", Mixer_s_play_p, 1);
|
469
|
+
rb_define_module_function(mMixer, "playingChannels", Mixer_s_playing_channels, 0);
|
470
|
+
rb_define_module_function(mMixer, "setVolume", Mixer_s_setVolume, 2);
|
471
|
+
rb_define_module_function(mMixer, "allocateChannels", Mixer_s_allocateChannels, 1);
|
394
472
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
473
|
+
rb_define_module_function(mMixer, "halt", Mixer_s_halt, 1);
|
474
|
+
rb_define_module_function(mMixer, "pause", Mixer_s_pause, 1);
|
475
|
+
rb_define_module_function(mMixer, "resume", Mixer_s_resume, 1);
|
476
|
+
rb_define_module_function(mMixer, "pause?", Mixer_s_pause_p, 1);
|
477
|
+
rb_define_module_function(mMixer, "expire", Mixer_s_expire, 2);
|
478
|
+
rb_define_module_function(mMixer, "fading", Mixer_s_fading, 1);
|
479
|
+
rb_define_module_function(mMixer, "fadeOut", Mixer_s_fadeOut, 2);
|
480
|
+
|
481
|
+
rb_define_module_function(mMixer, "playMusic", Mixer_s_playMusic, 2);
|
482
|
+
rb_define_module_function(mMixer, "fadeInMusic", Mixer_s_fadeInMusic, 3);
|
483
|
+
rb_define_module_function(mMixer, "setVolumeMusic", Mixer_s_setVolumeMusic, 1);
|
484
|
+
rb_define_module_function(mMixer, "haltMusic", Mixer_s_haltMusic, 0);
|
485
|
+
rb_define_module_function(mMixer, "fadeOutMusic", Mixer_s_fadeOutMusic, 1);
|
486
|
+
rb_define_module_function(mMixer, "pauseMusic", Mixer_s_pauseMusic, 0);
|
487
|
+
rb_define_module_function(mMixer, "resumeMusic", Mixer_s_resumeMusic, 0);
|
488
|
+
rb_define_module_function(mMixer, "rewindMusic", Mixer_s_rewindMusic, 0);
|
489
|
+
rb_define_module_function(mMixer, "pauseMusic?", Mixer_s_pauseMusic_p, 0);
|
490
|
+
rb_define_module_function(mMixer, "playMusic?", Mixer_s_playMusic_p, 0);
|
491
|
+
rb_define_module_function(mMixer, "fadingMusic", Mixer_s_fadingMusic, 0);
|
492
|
+
|
493
|
+
cWave = rb_define_class_under(mMixer, "Wave", rb_cObject);
|
494
|
+
rb_define_singleton_method(cWave, "load", Wave_s_load, 1);
|
495
|
+
rb_define_singleton_method(cWave, "loadFromIO", Wave_s_loadFromIO,1);
|
496
|
+
rb_define_singleton_method(cWave, "loadFromString", Wave_s_loadFromString,1);
|
497
|
+
rb_define_method(cWave, "setVolume", Wave_s_setVolume, 1);
|
498
|
+
|
499
|
+
cMusic = rb_define_class_under(mMixer, "Music", rb_cObject);
|
500
|
+
rb_define_singleton_method(cMusic, "load", Music_s_load, 1);
|
402
501
|
#ifdef HAVE_MIX_LOADMUS_RW
|
403
|
-
rb_define_singleton_method(cMusic,"loadFromString",
|
502
|
+
rb_define_singleton_method(cMusic, "loadFromString",
|
503
|
+
Mixer_s_loadMusFromString,1);
|
404
504
|
#endif
|
405
|
-
|
505
|
+
rb_define_method(cWave, "destroy", Wave_destroy, 0);
|
506
|
+
rb_define_method(cMusic, "destroy", Music_destroy, 0);
|
507
|
+
|
406
508
|
/* to avoid to do garbage collect when playing */
|
407
|
-
playing_wave = rb_ary_new();
|
408
509
|
rb_global_variable( &playing_wave );
|
409
510
|
rb_global_variable( &playing_music );
|
511
|
+
playing_wave = rb_ary_new();
|
512
|
+
|
513
|
+
rb_define_const(mMixer, "FORMAT_U8", UINT2NUM(AUDIO_U8));
|
514
|
+
rb_define_const(mMixer, "FORMAT_S8", UINT2NUM(AUDIO_S8));
|
515
|
+
rb_define_const(mMixer, "FORMAT_U16LSB", UINT2NUM(AUDIO_U16LSB));
|
516
|
+
rb_define_const(mMixer, "FORMAT_S16LSB", UINT2NUM(AUDIO_S16LSB));
|
517
|
+
rb_define_const(mMixer, "FORMAT_U16MSB", UINT2NUM(AUDIO_U16MSB));
|
518
|
+
rb_define_const(mMixer, "FORMAT_S16MSB", UINT2NUM(AUDIO_S16MSB));
|
519
|
+
rb_define_const(mMixer, "FORMAT_U16", UINT2NUM(AUDIO_U16));
|
520
|
+
rb_define_const(mMixer, "FORMAT_S16", UINT2NUM(AUDIO_S16));
|
410
521
|
|
411
|
-
|
412
|
-
|
522
|
+
rb_define_const(mMixer, "FORMAT_U16SYS", UINT2NUM(AUDIO_U16SYS));
|
523
|
+
rb_define_const(mMixer, "FORMAT_S16SYS", UINT2NUM(AUDIO_S16SYS));
|
524
|
+
|
525
|
+
rb_define_const(mMixer, "CHANNELS", INT2NUM(MIX_CHANNELS));
|
526
|
+
rb_define_const(mMixer, "DEFAULT_FREQUENCY", INT2NUM(MIX_DEFAULT_FREQUENCY));
|
527
|
+
rb_define_const(mMixer, "DEFAULT_FORMAT", UINT2NUM(MIX_DEFAULT_FORMAT));
|
528
|
+
rb_define_const(mMixer, "DEFAULT_CHANNELS", UINT2NUM(MIX_DEFAULT_CHANNELS));
|
529
|
+
rb_define_const(mMixer, "MAX_VOLUME", INT2NUM(MIX_MAX_VOLUME));
|
530
|
+
|
531
|
+
return;
|
413
532
|
}
|
414
533
|
|
415
|
-
void
|
534
|
+
void rubysdl_quit_Mixer(void)
|
416
535
|
{
|
417
|
-
if(
|
536
|
+
if(Mix_opened()){
|
418
537
|
Mix_CloseAudio();
|
419
|
-
mix_closed = 1;
|
420
538
|
}
|
421
539
|
}
|
540
|
+
#else /* HAVE_SDL_MIXER */
|
541
|
+
void rubysdl_init_Mixer(VALUE mSDL)
|
542
|
+
{
|
543
|
+
}
|
544
|
+
void rubysdl_quit_Mixer(void)
|
545
|
+
{
|
546
|
+
}
|
422
547
|
#endif /* HAVE_SDL_MIXER */
|