rubysdl 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +505 -0
- data/MANIFEST +81 -0
- data/NEWS.en +144 -0
- data/NEWS.ja +151 -0
- data/README.en +117 -0
- data/README.ja +166 -0
- data/SDL_kanji.c +403 -0
- data/SDL_kanji.h +48 -0
- data/depend +18 -0
- data/doc/Makefile +18 -0
- data/doc/cdrom.rsd +431 -0
- data/doc/collision.rsd +162 -0
- data/doc/event.rsd +1487 -0
- data/doc/font.rsd +839 -0
- data/doc/general.rsd +49 -0
- data/doc/init.rsd +175 -0
- data/doc/joystick.rsd +387 -0
- data/doc/mixer.rsd +837 -0
- data/doc/mpeg.rsd +595 -0
- data/doc/rsd.rb +125 -0
- data/doc/sdlskk.rsd +496 -0
- data/doc/time.rsd +45 -0
- data/doc/video.rsd +2499 -0
- data/doc/wm.rsd +113 -0
- data/extconf.rb +92 -0
- data/lib/rubysdl_aliases.rb +431 -0
- data/lib/sdl.rb +271 -0
- data/rubysdl.h +109 -0
- data/rubysdl_cdrom.c +176 -0
- data/rubysdl_const_list.txt +280 -0
- data/rubysdl_doc.en.rd +2180 -0
- data/rubysdl_doc_old.rd +2402 -0
- data/rubysdl_event.c +346 -0
- data/rubysdl_event2.c +417 -0
- data/rubysdl_event_key.c +356 -0
- data/rubysdl_image.c +53 -0
- data/rubysdl_joystick.c +156 -0
- data/rubysdl_kanji.c +135 -0
- data/rubysdl_main.c +202 -0
- data/rubysdl_mixer.c +422 -0
- data/rubysdl_mouse.c +96 -0
- data/rubysdl_opengl.c +63 -0
- data/rubysdl_pixel.c +133 -0
- data/rubysdl_ref.html +5550 -0
- data/rubysdl_ref.rd +6163 -0
- data/rubysdl_rwops.c +90 -0
- data/rubysdl_sdlskk.c +312 -0
- data/rubysdl_sge_video.c +622 -0
- data/rubysdl_smpeg.c +341 -0
- data/rubysdl_time.c +36 -0
- data/rubysdl_ttf.c +324 -0
- data/rubysdl_video.c +749 -0
- data/rubysdl_wm.c +71 -0
- data/sample/aadraw.rb +24 -0
- data/sample/alpha.rb +27 -0
- data/sample/alphadraw.rb +25 -0
- data/sample/bfont.rb +24 -0
- data/sample/cdrom.rb +17 -0
- data/sample/collision.rb +97 -0
- data/sample/cursor.bmp +0 -0
- data/sample/cursor.rb +22 -0
- data/sample/ellipses.rb +35 -0
- data/sample/event2.rb +32 -0
- data/sample/font.bmp +0 -0
- data/sample/font.rb +25 -0
- data/sample/fpstimer.rb +175 -0
- data/sample/icon.bmp +0 -0
- data/sample/joy2.rb +81 -0
- data/sample/kanji.rb +36 -0
- data/sample/movesp.rb +93 -0
- data/sample/playmod.rb +14 -0
- data/sample/plaympeg.rb +48 -0
- data/sample/playwave.rb +16 -0
- data/sample/randrect.rb +40 -0
- data/sample/sample.ttf +0 -0
- data/sample/sdlskk.rb +70 -0
- data/sample/sgetest.rb +31 -0
- data/sample/stetris.rb +275 -0
- data/sample/testgl.rb +166 -0
- data/sample/testsprite.rb +68 -0
- data/sample/transformblit.rb +41 -0
- metadata +121 -0
data/rubysdl_kanji.c
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
/*
|
2
|
+
Ruby/SDL Ruby extension library for SDL
|
3
|
+
|
4
|
+
Copyright (C) 2001-2007 Ohbayashi Ippei
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "SDL_kanji.h"
|
22
|
+
#include "rubysdl.h"
|
23
|
+
|
24
|
+
static VALUE cKanji;
|
25
|
+
|
26
|
+
static VALUE kanji_open(VALUE obj,VALUE filename,VALUE size)
|
27
|
+
{
|
28
|
+
Kanji_Font* font;
|
29
|
+
|
30
|
+
font = Kanji_OpenFont(GETCSTR(filename),NUM2INT(size));
|
31
|
+
if( font == NULL )
|
32
|
+
rb_raise(eSDLError,"Couldn't open bdf font: %s",GETCSTR(filename));
|
33
|
+
return Data_Wrap_Struct(cKanji,0,Kanji_CloseFont,font);
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE kanji_setCodingSystem(VALUE obj,VALUE sys)
|
37
|
+
{
|
38
|
+
Kanji_Font* font;
|
39
|
+
|
40
|
+
Data_Get_Struct(obj,Kanji_Font,font);
|
41
|
+
|
42
|
+
Kanji_SetCodingSystem(font,NUM2INT(sys));
|
43
|
+
return Qnil;
|
44
|
+
}
|
45
|
+
|
46
|
+
static VALUE kanji_addFont(VALUE obj, VALUE filename)
|
47
|
+
{
|
48
|
+
Kanji_Font* font;
|
49
|
+
|
50
|
+
Data_Get_Struct(obj,Kanji_Font,font);
|
51
|
+
if( Kanji_AddFont(font,GETCSTR(filename)) == -1)
|
52
|
+
rb_raise(eSDLError,"Couldn't use font: %s",GETCSTR(filename));
|
53
|
+
return Qnil;
|
54
|
+
}
|
55
|
+
|
56
|
+
static VALUE kanji_textwidth(VALUE obj,VALUE text)
|
57
|
+
{
|
58
|
+
Kanji_Font* font;
|
59
|
+
|
60
|
+
Data_Get_Struct(obj,Kanji_Font,font);
|
61
|
+
return INT2FIX(Kanji_FontWidth(font,GETCSTR(text)));
|
62
|
+
}
|
63
|
+
|
64
|
+
static VALUE kanji_width(VALUE obj)
|
65
|
+
{
|
66
|
+
Kanji_Font* font;
|
67
|
+
|
68
|
+
Data_Get_Struct(obj,Kanji_Font,font);
|
69
|
+
return INT2FIX(Kanji_FontWidth(font,NULL));
|
70
|
+
}
|
71
|
+
|
72
|
+
static VALUE kanji_height(VALUE obj)
|
73
|
+
{
|
74
|
+
Kanji_Font* font;
|
75
|
+
|
76
|
+
Data_Get_Struct(obj,Kanji_Font,font);
|
77
|
+
return INT2FIX(Kanji_FontHeight(font));
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE kanji_putText(VALUE obj,VALUE surface,VALUE text,VALUE x,VALUE y,
|
81
|
+
VALUE r, VALUE g, VALUE b)
|
82
|
+
{
|
83
|
+
Kanji_Font* font;
|
84
|
+
SDL_Surface* target;
|
85
|
+
SDL_Color color;
|
86
|
+
|
87
|
+
if(!rb_obj_is_kind_of(surface,cSurface))
|
88
|
+
rb_raise( rb_eArgError,"type mismatch(expect Surface)" );
|
89
|
+
|
90
|
+
Data_Get_Struct(obj,Kanji_Font,font);
|
91
|
+
Data_Get_Struct(surface,SDL_Surface,target);
|
92
|
+
|
93
|
+
color.r = NUM2INT(r);color.g = NUM2INT(g); color.b = NUM2INT(b);
|
94
|
+
Kanji_PutText(font,NUM2INT(x),NUM2INT(y),target,GETCSTR(text),
|
95
|
+
color);
|
96
|
+
return Qnil;
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE kanji_putTextTate(VALUE obj,VALUE surface,VALUE text,VALUE x,VALUE y,
|
100
|
+
VALUE r, VALUE g, VALUE b)
|
101
|
+
{
|
102
|
+
Kanji_Font* font;
|
103
|
+
SDL_Surface* target;
|
104
|
+
SDL_Color color;
|
105
|
+
|
106
|
+
if(!rb_obj_is_kind_of(surface,cSurface))
|
107
|
+
rb_raise( rb_eArgError,"type mismatch(expect Surface)" );
|
108
|
+
|
109
|
+
Data_Get_Struct(obj,Kanji_Font,font);
|
110
|
+
Data_Get_Struct(surface,SDL_Surface,target);
|
111
|
+
|
112
|
+
color.r = NUM2INT(r);color.g = NUM2INT(g); color.b = NUM2INT(b);
|
113
|
+
|
114
|
+
Kanji_PutTextTate(font,NUM2INT(x),NUM2INT(y),target,GETCSTR(text),
|
115
|
+
color);
|
116
|
+
return Qnil;
|
117
|
+
}
|
118
|
+
|
119
|
+
void init_kanji(void)
|
120
|
+
{
|
121
|
+
cKanji = rb_define_class_under(mSDL,"Kanji",rb_cObject);
|
122
|
+
|
123
|
+
rb_define_singleton_method(cKanji,"open",kanji_open,2);
|
124
|
+
rb_define_method(cKanji,"add",kanji_addFont,1);
|
125
|
+
rb_define_method(cKanji,"setCodingSystem",kanji_setCodingSystem,1);
|
126
|
+
rb_define_method(cKanji,"textwidth",kanji_textwidth,1);
|
127
|
+
rb_define_method(cKanji,"width",kanji_width,0);
|
128
|
+
rb_define_method(cKanji,"height",kanji_height,0);
|
129
|
+
rb_define_method(cKanji,"put",kanji_putText,7);
|
130
|
+
rb_define_method(cKanji,"putTate",kanji_putTextTate,7);
|
131
|
+
|
132
|
+
rb_define_const(cKanji,"SJIS",INT2NUM(KANJI_SJIS));
|
133
|
+
rb_define_const(cKanji,"EUC",INT2NUM(KANJI_EUC));
|
134
|
+
rb_define_const(cKanji,"JIS",INT2NUM(KANJI_JIS));
|
135
|
+
}
|
data/rubysdl_main.c
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
/*
|
2
|
+
Ruby/SDL Ruby extension library for SDL
|
3
|
+
|
4
|
+
Copyright (C) 2001-2007 Ohbayashi Ippei
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#define DEF_GLOBAL
|
22
|
+
#include "rubysdl.h"
|
23
|
+
#include <signal.h>
|
24
|
+
#include <stdio.h>
|
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)
|
71
|
+
{
|
72
|
+
Uint32 flag;
|
73
|
+
|
74
|
+
rb_secure(4);
|
75
|
+
flag= NUM2UINT(flags);
|
76
|
+
if( SDL_Init(flag) < 0 )
|
77
|
+
rb_raise(eSDLError,"Couldn't initialize SDL: %s",SDL_GetError());
|
78
|
+
return Qnil;
|
79
|
+
}
|
80
|
+
|
81
|
+
static VALUE sdl_initSubSystem(VALUE obj,VALUE flags)
|
82
|
+
{
|
83
|
+
if( SDL_InitSubSystem(NUM2UINT(flags)) < 0 )
|
84
|
+
rb_raise(eSDLError,"Couldn't initialize SDL subsystem: %s",SDL_GetError());
|
85
|
+
return Qnil;
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE sdl_wasInit(VALUE mod,VALUE flags)
|
89
|
+
{
|
90
|
+
return UINT2NUM( SDL_WasInit(NUM2UINT(flags)) );
|
91
|
+
}
|
92
|
+
|
93
|
+
static VALUE sdl_putenv(VALUE mod,VALUE var)
|
94
|
+
{
|
95
|
+
if( putenv(GETCSTR(var)) < 0 ){
|
96
|
+
rb_raise(eSDLError,"Can't put environ variable: %s", GETCSTR(var));
|
97
|
+
}
|
98
|
+
return Qnil;
|
99
|
+
}
|
100
|
+
|
101
|
+
static VALUE sdl_getenv(VALUE mod,VALUE name)
|
102
|
+
{
|
103
|
+
char* result = getenv(GETCSTR(name));
|
104
|
+
if( result == NULL ){
|
105
|
+
rb_raise(eSDLError,"Can't get environ variable: %s", GETCSTR(name));
|
106
|
+
}
|
107
|
+
return rb_str_new2(result);
|
108
|
+
}
|
109
|
+
|
110
|
+
static int is_quit=0;
|
111
|
+
int rubysdl_is_quit(void)
|
112
|
+
{
|
113
|
+
return is_quit;
|
114
|
+
}
|
115
|
+
static void sdl_quit()
|
116
|
+
{
|
117
|
+
#ifdef HAVE_SDL_MIXER
|
118
|
+
quit_mixer();
|
119
|
+
#endif
|
120
|
+
#ifdef HAVE_SDL_TTF
|
121
|
+
quit_ttf();
|
122
|
+
#endif
|
123
|
+
is_quit = 1;
|
124
|
+
SDL_Quit();
|
125
|
+
return ;
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE sdl_rb_quit(VALUE obj)
|
129
|
+
{
|
130
|
+
sdl_quit();
|
131
|
+
return Qnil;
|
132
|
+
}
|
133
|
+
|
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
|
+
void Init_sdl()
|
148
|
+
{
|
149
|
+
mSDL = rb_define_module("SDL");
|
150
|
+
eSDLError = rb_define_class_under(mSDL,"Error",rb_eStandardError);
|
151
|
+
rb_define_module_function(mSDL,"init",sdl_init,1);
|
152
|
+
rb_define_module_function(mSDL,"initedSystem",sdl_wasInit,1);
|
153
|
+
rb_define_module_function(mSDL,"initSubSystem",sdl_initSubSystem,1);
|
154
|
+
rb_define_module_function(mSDL,"quit",sdl_rb_quit,0);
|
155
|
+
rb_define_module_function(mSDL,"putenv",sdl_putenv,1);
|
156
|
+
rb_define_module_function(mSDL,"getenv",sdl_getenv,1);
|
157
|
+
|
158
|
+
defineConst();
|
159
|
+
|
160
|
+
|
161
|
+
init_video();
|
162
|
+
#ifdef HAVE_SGE
|
163
|
+
init_sge_video();
|
164
|
+
#else
|
165
|
+
init_pixel();
|
166
|
+
#endif
|
167
|
+
#ifdef DEF_OPENGL
|
168
|
+
init_opengl();
|
169
|
+
#ifdef INIT_OGLMODULE_FROM_SDL
|
170
|
+
Init_opengl();
|
171
|
+
#endif
|
172
|
+
#endif
|
173
|
+
#ifdef HAVE_SDL_IMAGE
|
174
|
+
init_sdl_image();
|
175
|
+
#endif
|
176
|
+
init_event();
|
177
|
+
#ifdef DEF_EVENT2
|
178
|
+
init_event2();
|
179
|
+
#endif
|
180
|
+
init_keyEvent();
|
181
|
+
init_mouse();
|
182
|
+
init_joystick();
|
183
|
+
init_cdrom();
|
184
|
+
init_time();
|
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);
|
200
|
+
}
|
201
|
+
|
202
|
+
|
data/rubysdl_mixer.c
ADDED
@@ -0,0 +1,422 @@
|
|
1
|
+
/*
|
2
|
+
Ruby/SDL Ruby extension library for SDL
|
3
|
+
|
4
|
+
Copyright (C) 2001-2007 Ohbayashi Ippei
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
#ifdef HAVE_SDL_MIXER
|
21
|
+
|
22
|
+
#include "rubysdl.h"
|
23
|
+
#define USE_RWOPS
|
24
|
+
#include <SDL_mixer.h>
|
25
|
+
|
26
|
+
static int mix_opened=0;
|
27
|
+
static int mix_closed=0;
|
28
|
+
|
29
|
+
static VALUE playing_wave = Qnil;
|
30
|
+
static VALUE playing_music=Qnil;
|
31
|
+
|
32
|
+
static void mix_FreeChunk(Mix_Chunk *chunk)
|
33
|
+
{
|
34
|
+
if( ! mix_closed ){
|
35
|
+
Mix_FreeChunk( chunk );
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
static void mix_FreeMusic(Mix_Music *music)
|
40
|
+
{
|
41
|
+
if( !mix_closed ){
|
42
|
+
Mix_FreeMusic( music );
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
static VALUE mix_audioDriverName(VALUE mod)
|
47
|
+
{
|
48
|
+
char driver_name[512];
|
49
|
+
if(SDL_AudioDriverName(driver_name, sizeof(driver_name)) == NULL)
|
50
|
+
rb_raise(eSDLError, "No driver has been initialized: %s", SDL_GetError());
|
51
|
+
return rb_str_new2(driver_name);
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE mix_openAudio(VALUE mod,VALUE frequency,VALUE format,
|
55
|
+
VALUE channels,VALUE chunksize)
|
56
|
+
{
|
57
|
+
if( mix_opened ){
|
58
|
+
rb_raise(eSDLError,"already initialize SDL::Mixer");
|
59
|
+
}
|
60
|
+
if( Mix_OpenAudio( NUM2INT(frequency),NUM2UINT(format),NUM2INT(channels),
|
61
|
+
NUM2INT(chunksize) ) < 0 ){
|
62
|
+
rb_raise(eSDLError,"Couldn't open audio: %s",SDL_GetError());
|
63
|
+
}
|
64
|
+
|
65
|
+
mix_opened = 1;
|
66
|
+
return Qnil;
|
67
|
+
}
|
68
|
+
|
69
|
+
static VALUE mix_querySpec(VALUE mod)
|
70
|
+
{
|
71
|
+
int rate;
|
72
|
+
Uint16 format;
|
73
|
+
int channels;
|
74
|
+
|
75
|
+
if( !Mix_QuerySpec(&rate,&format,&channels) )
|
76
|
+
rb_raise(eSDLError,"audio have not been opened yet: %s", Mix_GetError());
|
77
|
+
return rb_ary_new3( 3,INT2NUM(rate),UINT2NUM(format),INT2NUM(channels) );
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE mix_allocateChannels(VALUE mod,VALUE numchannels)
|
81
|
+
{
|
82
|
+
return INT2FIX( Mix_AllocateChannels(NUM2INT(numchannels)) );
|
83
|
+
}
|
84
|
+
|
85
|
+
/* Returns which channel was used to play the sound. */
|
86
|
+
static VALUE mix_playChannel(VALUE mod,VALUE channel,VALUE wave,VALUE loops)
|
87
|
+
{
|
88
|
+
Mix_Chunk *chunk;
|
89
|
+
int playing_channel;
|
90
|
+
|
91
|
+
if( ! rb_obj_is_kind_of(wave,cWave) )
|
92
|
+
rb_raise(rb_eArgError,"type mismatch: SDL::Mixer::Wave is expected");
|
93
|
+
Data_Get_Struct(wave,Mix_Chunk,chunk);
|
94
|
+
|
95
|
+
playing_channel = Mix_PlayChannel(NUM2INT(channel),chunk,NUM2INT(loops) );
|
96
|
+
if( playing_channel == -1 ){
|
97
|
+
rb_raise( eSDLError, "couldn't play wave: %s", Mix_GetError() );
|
98
|
+
}
|
99
|
+
|
100
|
+
rb_ary_store(playing_wave,playing_channel,wave);/* to avoid gc problem */
|
101
|
+
return INT2FIX(playing_channel);
|
102
|
+
}
|
103
|
+
|
104
|
+
static VALUE mix_playChannelTimed(VALUE mod,VALUE channel,VALUE wave,VALUE loops,
|
105
|
+
VALUE ticks)
|
106
|
+
{
|
107
|
+
Mix_Chunk *chunk;
|
108
|
+
int playing_channel;
|
109
|
+
|
110
|
+
if( ! rb_obj_is_kind_of(wave,cWave) )
|
111
|
+
rb_raise(rb_eArgError,"type mismatch: SDL::Mixer::Wave is expected");
|
112
|
+
Data_Get_Struct(wave,Mix_Chunk,chunk);
|
113
|
+
|
114
|
+
playing_channel = Mix_PlayChannelTimed(NUM2INT(channel),chunk,NUM2INT(loops),
|
115
|
+
NUM2INT(ticks));
|
116
|
+
if( playing_channel == -1 ){
|
117
|
+
rb_raise( eSDLError, "couldn't play wave: %s", Mix_GetError() );
|
118
|
+
}
|
119
|
+
|
120
|
+
rb_ary_store(playing_wave,playing_channel,wave);/* to avoid gc problem */
|
121
|
+
return INT2FIX(playing_channel);
|
122
|
+
}
|
123
|
+
|
124
|
+
static VALUE mix_fadeInChannel(VALUE mod,VALUE channel,VALUE wave,VALUE loops,
|
125
|
+
VALUE ms)
|
126
|
+
{
|
127
|
+
Mix_Chunk *chunk;
|
128
|
+
int playing_channel;
|
129
|
+
|
130
|
+
if( ! rb_obj_is_kind_of(wave,cWave) )
|
131
|
+
rb_raise(rb_eArgError,"type mismatch: SDL::Mixer::Wave is expected");
|
132
|
+
Data_Get_Struct(wave,Mix_Chunk,chunk);
|
133
|
+
|
134
|
+
playing_channel = Mix_FadeInChannel(NUM2INT(channel),chunk,NUM2INT(loops),
|
135
|
+
NUM2INT(ms));
|
136
|
+
if( playing_channel == -1 ){
|
137
|
+
rb_raise( eSDLError, "couldn't play wave: %s", Mix_GetError() );
|
138
|
+
}
|
139
|
+
|
140
|
+
rb_ary_store(playing_wave,playing_channel,wave);/* to avoid gc problem */
|
141
|
+
return INT2FIX(playing_channel);
|
142
|
+
}
|
143
|
+
|
144
|
+
static VALUE mix_fadeInChannelTimed(VALUE mod,VALUE channel,VALUE wave,VALUE loops,
|
145
|
+
VALUE ms, VALUE ticks)
|
146
|
+
{
|
147
|
+
Mix_Chunk *chunk;
|
148
|
+
int playing_channel;
|
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
|
+
}
|
159
|
+
|
160
|
+
rb_ary_store(playing_wave,playing_channel,wave);/* to avoid gc problem */
|
161
|
+
return INT2FIX(playing_channel);
|
162
|
+
}
|
163
|
+
|
164
|
+
static VALUE mix_playing(VALUE mod,VALUE channel)
|
165
|
+
{
|
166
|
+
if( Mix_Playing( NUM2INT(channel) ) ){
|
167
|
+
return Qtrue;
|
168
|
+
}else{
|
169
|
+
return Qfalse;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
static VALUE mix_loadWav(VALUE class,VALUE filename)
|
174
|
+
{
|
175
|
+
Mix_Chunk *wave;
|
176
|
+
Check_Type(filename,T_STRING);
|
177
|
+
wave = Mix_LoadWAV( GETCSTR(filename) );
|
178
|
+
if( wave == NULL ){
|
179
|
+
rb_raise( eSDLError,"Couldn't load wave file %s: %s",
|
180
|
+
GETCSTR(filename), Mix_GetError() );
|
181
|
+
}
|
182
|
+
return Data_Wrap_Struct(class,0,mix_FreeChunk,wave);
|
183
|
+
}
|
184
|
+
|
185
|
+
static VALUE mix_loadWavFromIO(VALUE class, VALUE io)
|
186
|
+
{
|
187
|
+
Mix_Chunk *wave;
|
188
|
+
wave = Mix_LoadWAV_RW(rubysdl_RWops_from_ruby_obj(io), 1);
|
189
|
+
if( wave == NULL ){
|
190
|
+
rb_raise(eSDLError,"Couldn't load wave file from IO: %s",
|
191
|
+
Mix_GetError());
|
192
|
+
}
|
193
|
+
return Data_Wrap_Struct(class,0,mix_FreeChunk,wave);
|
194
|
+
}
|
195
|
+
|
196
|
+
/* Volume setting functions and methods : volume in 0..128 */
|
197
|
+
static VALUE mix_volume(VALUE mod,VALUE channel,VALUE volume)
|
198
|
+
{
|
199
|
+
return INT2FIX( Mix_Volume( NUM2INT(channel),NUM2INT(volume) ) );
|
200
|
+
}
|
201
|
+
static VALUE mix_wave_volume(VALUE obj,VALUE volume)
|
202
|
+
{
|
203
|
+
Mix_Chunk *chunk;
|
204
|
+
Data_Get_Struct(obj,Mix_Chunk,chunk);
|
205
|
+
return INT2FIX( Mix_VolumeChunk( chunk,NUM2INT(volume) ) );
|
206
|
+
}
|
207
|
+
|
208
|
+
/* Halt,Pause function */
|
209
|
+
static VALUE mix_halt(VALUE mod,VALUE channel)
|
210
|
+
{
|
211
|
+
Mix_HaltChannel(NUM2INT(channel));
|
212
|
+
return Qnil;
|
213
|
+
}
|
214
|
+
static VALUE mix_pause(VALUE mod,VALUE channel)
|
215
|
+
{
|
216
|
+
Mix_Pause(NUM2INT(channel));
|
217
|
+
return Qnil;
|
218
|
+
}
|
219
|
+
static VALUE mix_resume(VALUE mod,VALUE channel)
|
220
|
+
{
|
221
|
+
Mix_Resume(NUM2INT(channel));
|
222
|
+
return Qnil;
|
223
|
+
}
|
224
|
+
static VALUE mix_paused(VALUE mod,VALUE channel)
|
225
|
+
{
|
226
|
+
return INT2FIX(Mix_Paused(NUM2INT(channel)));
|
227
|
+
}
|
228
|
+
static VALUE mix_fadeOut(VALUE mod,VALUE channel,VALUE ms)
|
229
|
+
{
|
230
|
+
return INT2FIX(Mix_FadeOutChannel(NUM2INT(channel), NUM2INT(ms)));
|
231
|
+
}
|
232
|
+
static VALUE mix_expire(VALUE mod, VALUE channel, VALUE ticks)
|
233
|
+
{
|
234
|
+
return INT2FIX(Mix_ExpireChannel(NUM2INT(channel),NUM2INT(ticks)));
|
235
|
+
}
|
236
|
+
static VALUE mix_fading(VALUE mod, VALUE which)
|
237
|
+
{
|
238
|
+
if( NUM2INT(which) < 0 || Mix_AllocateChannels(-1) <= NUM2INT(which))
|
239
|
+
rb_raise(eSDLError, "channel %d out of range", NUM2INT(which));
|
240
|
+
return INT2FIX(Mix_FadingChannel(which));
|
241
|
+
}
|
242
|
+
|
243
|
+
/* music functions */
|
244
|
+
#define MakeSimpleRubyFunc(rubyFunc,sdlFunc) \
|
245
|
+
static VALUE rubyFunc(VALUE mod) \
|
246
|
+
{ \
|
247
|
+
sdlFunc(); \
|
248
|
+
return Qnil; \
|
249
|
+
} \
|
250
|
+
|
251
|
+
static VALUE mix_playMusic(VALUE mod,VALUE music,VALUE loops)
|
252
|
+
{
|
253
|
+
Mix_Music *mus;
|
254
|
+
if( ! rb_obj_is_kind_of(music,cMusic) )
|
255
|
+
rb_raise(rb_eArgError,"type mismatch: SDL::Mixer::Music is expected");
|
256
|
+
Data_Get_Struct(music,Mix_Music,mus);
|
257
|
+
playing_music=music; /* to avoid gc problem */
|
258
|
+
Mix_PlayMusic(mus,NUM2INT(loops));
|
259
|
+
return Qnil;
|
260
|
+
}
|
261
|
+
|
262
|
+
static VALUE mix_fadeInMusic(VALUE mod,VALUE music,VALUE loops,VALUE ms)
|
263
|
+
{
|
264
|
+
Mix_Music *mus;
|
265
|
+
if( ! rb_obj_is_kind_of(music,cMusic) )
|
266
|
+
rb_raise(rb_eArgError,"type mismatch: SDL::Mixer::Music is expected");
|
267
|
+
Data_Get_Struct(music,Mix_Music,mus);
|
268
|
+
Mix_FadeInMusic(mus,NUM2INT(loops),NUM2INT(ms));
|
269
|
+
return Qnil;
|
270
|
+
}
|
271
|
+
|
272
|
+
static VALUE mix_setVolumeMusic(VALUE mod,VALUE volume)
|
273
|
+
{
|
274
|
+
Mix_VolumeMusic( NUM2INT(volume) );
|
275
|
+
return Qnil;
|
276
|
+
}
|
277
|
+
|
278
|
+
static VALUE mix_fadeOutMusic(VALUE mod,VALUE ms)
|
279
|
+
{
|
280
|
+
Mix_FadeOutMusic(NUM2INT(ms));
|
281
|
+
return Qnil;
|
282
|
+
}
|
283
|
+
|
284
|
+
MakeSimpleRubyFunc(mix_haltMusic,Mix_HaltMusic)
|
285
|
+
MakeSimpleRubyFunc(mix_pauseMusic,Mix_PauseMusic)
|
286
|
+
MakeSimpleRubyFunc(mix_resumeMusic,Mix_ResumeMusic)
|
287
|
+
MakeSimpleRubyFunc(mix_rewindMusic,Mix_RewindMusic)
|
288
|
+
|
289
|
+
static VALUE mix_pausedMusic(VALUE mod)
|
290
|
+
{
|
291
|
+
return BOOL(Mix_PausedMusic());
|
292
|
+
}
|
293
|
+
|
294
|
+
static VALUE mix_playingMusic(VALUE mod)
|
295
|
+
{
|
296
|
+
return BOOL(Mix_PlayingMusic());
|
297
|
+
}
|
298
|
+
|
299
|
+
static VALUE mix_fadingMusic(VALUE mod)
|
300
|
+
{
|
301
|
+
return INT2FIX(Mix_FadingMusic());
|
302
|
+
}
|
303
|
+
|
304
|
+
static VALUE mix_loadMus(VALUE class,VALUE filename)
|
305
|
+
{
|
306
|
+
Mix_Music* music;
|
307
|
+
music = Mix_LoadMUS(GETCSTR(filename));
|
308
|
+
if( music == NULL )
|
309
|
+
rb_raise(eSDLError,
|
310
|
+
"Couldn't load %s: %s",GETCSTR(filename),SDL_GetError());
|
311
|
+
return Data_Wrap_Struct(class,0,mix_FreeMusic,music);
|
312
|
+
}
|
313
|
+
|
314
|
+
#ifdef HAVE_MIX_LOADMUS_RW
|
315
|
+
static VALUE mix_loadMusFromString(VALUE class,VALUE str)
|
316
|
+
{
|
317
|
+
Mix_Music* music;
|
318
|
+
volatile VALUE result;
|
319
|
+
volatile VALUE buf;
|
320
|
+
|
321
|
+
StringValue(str);
|
322
|
+
buf = rb_str_dup(str);
|
323
|
+
music = Mix_LoadMUS_RW(SDL_RWFromConstMem(RSTRING(buf)->ptr,
|
324
|
+
RSTRING(buf)->len));
|
325
|
+
|
326
|
+
if( music == NULL )
|
327
|
+
rb_raise(eSDLError,
|
328
|
+
"Couldn't load from String: %s",Mix_GetError());
|
329
|
+
|
330
|
+
result = Data_Wrap_Struct(class,0,mix_FreeMusic,music);
|
331
|
+
rb_iv_set(result, "buf", buf);
|
332
|
+
|
333
|
+
return result;
|
334
|
+
}
|
335
|
+
#endif
|
336
|
+
|
337
|
+
static void defineConstForAudio()
|
338
|
+
{
|
339
|
+
rb_define_const(mMixer,"FORMAT_U8",UINT2NUM(AUDIO_U8));
|
340
|
+
rb_define_const(mMixer,"FORMAT_S8",UINT2NUM(AUDIO_S8));
|
341
|
+
rb_define_const(mMixer,"FORMAT_U16LSB",UINT2NUM(AUDIO_U16LSB));
|
342
|
+
rb_define_const(mMixer,"FORMAT_S16LSB",UINT2NUM(AUDIO_S16LSB));
|
343
|
+
rb_define_const(mMixer,"FORMAT_U16MSB",UINT2NUM(AUDIO_U16MSB));
|
344
|
+
rb_define_const(mMixer,"FORMAT_S16MSB",UINT2NUM(AUDIO_S16MSB));
|
345
|
+
rb_define_const(mMixer,"FORMAT_U16",UINT2NUM(AUDIO_U16));
|
346
|
+
rb_define_const(mMixer,"FORMAT_S16",UINT2NUM(AUDIO_S16));
|
347
|
+
|
348
|
+
rb_define_const(mMixer,"FORMAT_U16SYS",UINT2NUM(AUDIO_U16SYS));
|
349
|
+
rb_define_const(mMixer,"FORMAT_S16SYS",UINT2NUM(AUDIO_S16SYS));
|
350
|
+
|
351
|
+
rb_define_const(mMixer,"CHANNELS",INT2NUM(MIX_CHANNELS));
|
352
|
+
rb_define_const(mMixer,"DEFAULT_FREQUENCY",INT2NUM(MIX_DEFAULT_FREQUENCY));
|
353
|
+
rb_define_const(mMixer,"DEFAULT_FORMAT",UINT2NUM(MIX_DEFAULT_FORMAT));
|
354
|
+
rb_define_const(mMixer,"DEFAULT_CHANNELS",UINT2NUM(MIX_DEFAULT_CHANNELS));
|
355
|
+
rb_define_const(mMixer,"MAX_VOLUME",INT2NUM(MIX_MAX_VOLUME));
|
356
|
+
|
357
|
+
rb_define_const(mMixer,"NO_FADING", INT2NUM(MIX_NO_FADING));
|
358
|
+
rb_define_const(mMixer,"FADING_OUT", INT2NUM(MIX_FADING_OUT));
|
359
|
+
rb_define_const(mMixer,"FADING_IN", INT2NUM(MIX_FADING_IN));
|
360
|
+
}
|
361
|
+
|
362
|
+
void init_mixer()
|
363
|
+
{
|
364
|
+
mMixer = rb_define_module_under(mSDL,"Mixer");
|
365
|
+
rb_define_module_function(mMixer,"open",mix_openAudio,4);
|
366
|
+
rb_define_module_function(mMixer,"spec",mix_querySpec,0);
|
367
|
+
rb_define_module_function(mMixer,"driverName", mix_audioDriverName, 0);
|
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);
|
382
|
+
|
383
|
+
rb_define_module_function(mMixer,"playMusic",mix_playMusic,2);
|
384
|
+
rb_define_module_function(mMixer,"fadeInMusic",mix_fadeInMusic,3);
|
385
|
+
rb_define_module_function(mMixer,"setVolumeMusic",mix_setVolumeMusic,1);
|
386
|
+
rb_define_module_function(mMixer,"haltMusic",mix_haltMusic,0);
|
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);
|
394
|
+
|
395
|
+
cWave = rb_define_class_under(mMixer,"Wave",rb_cObject);
|
396
|
+
rb_define_singleton_method(cWave,"load",mix_loadWav,1);
|
397
|
+
rb_define_singleton_method(cWave,"loadFromIO",mix_loadWavFromIO,1);
|
398
|
+
rb_define_method(cWave,"setVolume",mix_wave_volume,1);
|
399
|
+
|
400
|
+
cMusic = rb_define_class_under(mMixer,"Music",rb_cObject);
|
401
|
+
rb_define_singleton_method(cMusic,"load",mix_loadMus,1);
|
402
|
+
#ifdef HAVE_MIX_LOADMUS_RW
|
403
|
+
rb_define_singleton_method(cMusic,"loadFromString",mix_loadMusFromString,1);
|
404
|
+
#endif
|
405
|
+
|
406
|
+
/* to avoid to do garbage collect when playing */
|
407
|
+
playing_wave = rb_ary_new();
|
408
|
+
rb_global_variable( &playing_wave );
|
409
|
+
rb_global_variable( &playing_music );
|
410
|
+
|
411
|
+
defineConstForAudio();
|
412
|
+
return ;
|
413
|
+
}
|
414
|
+
|
415
|
+
void quit_mixer()
|
416
|
+
{
|
417
|
+
if( mix_opened ){
|
418
|
+
Mix_CloseAudio();
|
419
|
+
mix_closed = 1;
|
420
|
+
}
|
421
|
+
}
|
422
|
+
#endif /* HAVE_SDL_MIXER */
|