gosu 0.15.2 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +138 -0
  3. data/dependencies/SDL/include/SDL_assert.h +293 -0
  4. data/dependencies/SDL/include/SDL_atomic.h +295 -0
  5. data/dependencies/SDL/include/SDL_audio.h +859 -0
  6. data/dependencies/SDL/include/SDL_bits.h +121 -0
  7. data/dependencies/SDL/include/SDL_blendmode.h +123 -0
  8. data/dependencies/SDL/include/SDL_clipboard.h +71 -0
  9. data/dependencies/SDL/include/SDL_config.h +55 -0
  10. data/dependencies/SDL/include/SDL_config_android.h +182 -0
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
  12. data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
  13. data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
  14. data/dependencies/SDL/include/SDL_config_os2.h +188 -0
  15. data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
  16. data/dependencies/SDL/include/SDL_config_psp.h +165 -0
  17. data/dependencies/SDL/include/SDL_config_windows.h +288 -0
  18. data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
  19. data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
  20. data/dependencies/SDL/include/SDL_copying.h +20 -0
  21. data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
  22. data/dependencies/SDL/include/SDL_egl.h +1676 -0
  23. data/dependencies/SDL/include/SDL_endian.h +263 -0
  24. data/dependencies/SDL/include/SDL_error.h +112 -0
  25. data/dependencies/SDL/include/SDL_events.h +827 -0
  26. data/dependencies/SDL/include/SDL_filesystem.h +136 -0
  27. data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
  28. data/dependencies/SDL/include/SDL_gesture.h +87 -0
  29. data/dependencies/SDL/include/SDL_haptic.h +1247 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1578 -0
  31. data/dependencies/SDL/include/SDL_joystick.h +499 -0
  32. data/dependencies/SDL/include/SDL_keyboard.h +217 -0
  33. data/dependencies/SDL/include/SDL_keycode.h +351 -0
  34. data/dependencies/SDL/include/SDL_loadso.h +81 -0
  35. data/dependencies/SDL/include/SDL_locale.h +101 -0
  36. data/dependencies/SDL/include/SDL_log.h +211 -0
  37. data/dependencies/SDL/include/SDL_main.h +180 -0
  38. data/dependencies/SDL/include/SDL_messagebox.h +146 -0
  39. data/dependencies/SDL/include/SDL_metal.h +117 -0
  40. data/dependencies/SDL/include/SDL_misc.h +75 -0
  41. data/dependencies/SDL/include/SDL_mouse.h +302 -0
  42. data/dependencies/SDL/include/SDL_mutex.h +251 -0
  43. data/dependencies/SDL/include/SDL_name.h +33 -0
  44. data/dependencies/SDL/include/SDL_opengl.h +2183 -0
  45. data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
  46. data/dependencies/SDL/include/SDL_opengles.h +39 -0
  47. data/dependencies/SDL/include/SDL_opengles2.h +52 -0
  48. data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
  49. data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
  50. data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
  51. data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
  52. data/dependencies/SDL/include/SDL_pixels.h +479 -0
  53. data/dependencies/SDL/include/SDL_platform.h +198 -0
  54. data/dependencies/SDL/include/SDL_power.h +75 -0
  55. data/dependencies/SDL/include/SDL_quit.h +58 -0
  56. data/dependencies/SDL/include/SDL_rect.h +174 -0
  57. data/dependencies/SDL/include/SDL_render.h +1158 -0
  58. data/dependencies/SDL/include/SDL_revision.h +2 -0
  59. data/dependencies/SDL/include/SDL_rwops.h +283 -0
  60. data/dependencies/SDL/include/SDL_scancode.h +413 -0
  61. data/dependencies/SDL/include/SDL_sensor.h +267 -0
  62. data/dependencies/SDL/include/SDL_shape.h +144 -0
  63. data/dependencies/SDL/include/SDL_stdinc.h +647 -0
  64. data/dependencies/SDL/include/SDL_surface.h +563 -0
  65. data/dependencies/SDL/include/SDL_system.h +325 -0
  66. data/dependencies/SDL/include/SDL_syswm.h +354 -0
  67. data/dependencies/SDL/include/SDL_test.h +69 -0
  68. data/dependencies/SDL/include/SDL_test_assert.h +105 -0
  69. data/dependencies/SDL/include/SDL_test_common.h +218 -0
  70. data/dependencies/SDL/include/SDL_test_compare.h +69 -0
  71. data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
  72. data/dependencies/SDL/include/SDL_test_font.h +81 -0
  73. data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
  74. data/dependencies/SDL/include/SDL_test_harness.h +134 -0
  75. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  76. data/dependencies/SDL/include/SDL_test_log.h +67 -0
  77. data/dependencies/SDL/include/SDL_test_md5.h +129 -0
  78. data/dependencies/SDL/include/SDL_test_memory.h +63 -0
  79. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  80. data/dependencies/SDL/include/SDL_thread.h +366 -0
  81. data/dependencies/SDL/include/SDL_timer.h +115 -0
  82. data/dependencies/SDL/include/SDL_touch.h +102 -0
  83. data/dependencies/SDL/include/SDL_types.h +29 -0
  84. data/dependencies/SDL/include/SDL_version.h +162 -0
  85. data/dependencies/SDL/include/SDL_video.h +1282 -0
  86. data/dependencies/SDL/include/SDL_vulkan.h +276 -0
  87. data/dependencies/SDL/include/begin_code.h +166 -0
  88. data/dependencies/SDL/include/close_code.h +40 -0
  89. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  90. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  91. data/dependencies/SDL_sound/SDL_sound.c +795 -0
  92. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  93. data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
  94. data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
  95. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
  96. data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
  97. data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
  98. data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
  99. data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
  100. data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
  101. data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
  102. data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
  103. data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
  104. data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
  105. data/dependencies/SDL_sound/dr_flac.h +5906 -0
  106. data/dependencies/SDL_sound/dr_mp3.h +2832 -0
  107. data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
  108. data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
  109. data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
  110. data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
  111. data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
  112. data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
  113. data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
  114. data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
  115. data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
  116. data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
  117. data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
  118. data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
  119. data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
  120. data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
  121. data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
  122. data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
  123. data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
  124. data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
  125. data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
  126. data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
  127. data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
  128. data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
  129. data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
  130. data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
  131. data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
  132. data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
  133. data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
  134. data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
  135. data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
  136. data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
  137. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
  138. data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
  139. data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
  140. data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
  141. data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
  142. data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
  143. data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
  144. data/dependencies/al_soft/AL/al.h +655 -0
  145. data/dependencies/al_soft/AL/alc.h +270 -0
  146. data/dependencies/al_soft/AL/alext.h +585 -0
  147. data/dependencies/al_soft/AL/efx-creative.h +3 -0
  148. data/dependencies/al_soft/AL/efx-presets.h +402 -0
  149. data/dependencies/al_soft/AL/efx.h +762 -0
  150. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  151. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  152. data/{src → dependencies/stb}/stb_image.h +330 -127
  153. data/{src → dependencies/stb}/stb_image_write.h +156 -85
  154. data/{src → dependencies/stb}/stb_truetype.h +192 -69
  155. data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
  156. data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
  157. data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
  158. data/ext/gosu/extconf.rb +56 -22
  159. data/{Gosu → include/Gosu}/Audio.hpp +6 -8
  160. data/{Gosu → include/Gosu}/AutoLink.hpp +0 -0
  161. data/include/Gosu/Bitmap.hpp +100 -0
  162. data/{Gosu → include/Gosu}/Buttons.hpp +94 -35
  163. data/{Gosu → include/Gosu}/Channel.h +0 -0
  164. data/{Gosu → include/Gosu}/Color.h +0 -0
  165. data/{Gosu → include/Gosu}/Color.hpp +0 -0
  166. data/{Gosu → include/Gosu}/Directories.hpp +0 -0
  167. data/{Gosu → include/Gosu}/Font.h +0 -0
  168. data/{Gosu → include/Gosu}/Font.hpp +0 -0
  169. data/{Gosu → include/Gosu}/Fwd.hpp +0 -0
  170. data/{Gosu → include/Gosu}/Gosu.h +3 -0
  171. data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
  172. data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
  173. data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
  174. data/{Gosu → include/Gosu}/IO.hpp +0 -0
  175. data/{Gosu → include/Gosu}/Image.h +0 -0
  176. data/{Gosu → include/Gosu}/Image.hpp +7 -6
  177. data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
  178. data/{Gosu → include/Gosu}/Input.hpp +30 -15
  179. data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
  180. data/{Gosu → include/Gosu}/Math.hpp +0 -0
  181. data/{Gosu → include/Gosu}/Platform.hpp +0 -0
  182. data/{Gosu → include/Gosu}/Sample.h +0 -0
  183. data/{Gosu → include/Gosu}/Song.h +0 -0
  184. data/{Gosu → include/Gosu}/Text.hpp +0 -0
  185. data/{Gosu → include/Gosu}/TextInput.h +0 -0
  186. data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
  187. data/{Gosu → include/Gosu}/Timing.hpp +0 -0
  188. data/{Gosu → include/Gosu}/Utility.hpp +1 -1
  189. data/{Gosu → include/Gosu}/Version.hpp +0 -0
  190. data/{Gosu → include/Gosu}/Window.h +2 -0
  191. data/{Gosu → include/Gosu}/Window.hpp +21 -13
  192. data/lib/OpenAL32.dll +0 -0
  193. data/lib/SDL2.dll +0 -0
  194. data/lib/gosu.rb +0 -3
  195. data/lib/gosu/patches.rb +0 -9
  196. data/lib/gosu/swig_patches.rb +3 -2
  197. data/lib/libmpg123.dll +0 -0
  198. data/lib/libsndfile.dll +0 -0
  199. data/lib64/OpenAL32.dll +0 -0
  200. data/lib64/SDL2.dll +0 -0
  201. data/lib64/libmpg123.dll +0 -0
  202. data/lib64/libsndfile.dll +0 -0
  203. data/rdoc/gosu.rb +95 -20
  204. data/src/Audio.cpp +50 -224
  205. data/src/AudioFile.hpp +17 -37
  206. data/src/AudioFileAudioToolbox.cpp +237 -0
  207. data/src/AudioFileSDLSound.cpp +147 -0
  208. data/src/AudioImpl.cpp +3 -12
  209. data/src/AudioImpl.hpp +3 -1
  210. data/src/Bitmap.cpp +85 -83
  211. data/src/BitmapIO.cpp +52 -58
  212. data/src/Constants.cpp +80 -33
  213. data/src/Font.cpp +3 -1
  214. data/src/GosuWrapper.cpp +19 -0
  215. data/src/Graphics.cpp +7 -4
  216. data/src/Image.cpp +13 -16
  217. data/src/Input.cpp +408 -159
  218. data/src/LargeImageData.cpp +1 -1
  219. data/src/MarkupParser.cpp +2 -1
  220. data/src/RubyGosu.cxx +349 -83
  221. data/src/RubyGosu.h +4 -2
  222. data/src/TexChunk.cpp +1 -1
  223. data/src/TextBuilder.cpp +3 -1
  224. data/src/Texture.cpp +1 -1
  225. data/src/TrueTypeFont.cpp +1 -1
  226. data/src/Utility.cpp +11 -7
  227. data/src/Window.cpp +30 -39
  228. data/src/WindowWrapper.cpp +28 -0
  229. metadata +207 -52
  230. data/Gosu/Bitmap.hpp +0 -113
  231. data/src/AudioToolboxFile.hpp +0 -210
  232. data/src/OggFile.hpp +0 -92
  233. data/src/SndFile.hpp +0 -174
  234. data/src/WinMain.cpp +0 -64
@@ -0,0 +1,488 @@
1
+ /*
2
+ * This source code is public domain.
3
+ *
4
+ * Authors: Olivier Lapicque <olivierl@jps.net>
5
+ */
6
+
7
+ //////////////////////////////////////////////
8
+ // DigiTracker (MDL) module loader //
9
+ //////////////////////////////////////////////
10
+ #include "libmodplug.h"
11
+
12
+ typedef struct MDLSONGHEADER
13
+ {
14
+ DWORD id; // "DMDL" = 0x4C444D44
15
+ BYTE version;
16
+ } MDLSONGHEADER;
17
+
18
+
19
+ typedef struct MDLINFOBLOCK
20
+ {
21
+ CHAR songname[32];
22
+ CHAR composer[20];
23
+ WORD norders;
24
+ WORD repeatpos;
25
+ BYTE globalvol;
26
+ BYTE speed;
27
+ BYTE tempo;
28
+ BYTE channelinfo[32];
29
+ BYTE seq[256];
30
+ } MDLINFOBLOCK;
31
+
32
+
33
+ typedef struct MDLPATTERNDATA
34
+ {
35
+ BYTE channels;
36
+ BYTE lastrow; // nrows = lastrow+1
37
+ CHAR name[16];
38
+ WORD data[1];
39
+ } MDLPATTERNDATA;
40
+
41
+
42
+ void ConvertMDLCommand(MODCOMMAND *m, UINT eff, UINT data)
43
+ //--------------------------------------------------------
44
+ {
45
+ UINT command = 0, param = data;
46
+ switch(eff)
47
+ {
48
+ case 0x01: command = CMD_PORTAMENTOUP; break;
49
+ case 0x02: command = CMD_PORTAMENTODOWN; break;
50
+ case 0x03: command = CMD_TONEPORTAMENTO; break;
51
+ case 0x04: command = CMD_VIBRATO; break;
52
+ case 0x05: command = CMD_ARPEGGIO; break;
53
+ case 0x07: command = (param < 0x20) ? CMD_SPEED : CMD_TEMPO; break;
54
+ case 0x08: command = CMD_PANNING8; param <<= 1; break;
55
+ case 0x0B: command = CMD_POSITIONJUMP; break;
56
+ case 0x0C: command = CMD_GLOBALVOLUME; break;
57
+ case 0x0D: command = CMD_PATTERNBREAK; param = (data & 0x0F) + (data>>4)*10; break;
58
+ case 0x0E:
59
+ command = CMD_S3MCMDEX;
60
+ switch(data & 0xF0)
61
+ {
62
+ case 0x00: command = 0; break; // What is E0x in MDL (there is a bunch) ?
63
+ case 0x10: if (param & 0x0F) { param |= 0xF0; command = CMD_PANNINGSLIDE; } else command = 0; break;
64
+ case 0x20: if (param & 0x0F) { param = (param << 4) | 0x0F; command = CMD_PANNINGSLIDE; } else command = 0; break;
65
+ case 0x30: param = (data & 0x0F) | 0x10; break; // glissando
66
+ case 0x40: param = (data & 0x0F) | 0x30; break; // vibrato waveform
67
+ case 0x60: param = (data & 0x0F) | 0xB0; break;
68
+ case 0x70: param = (data & 0x0F) | 0x40; break; // tremolo waveform
69
+ case 0x90: command = CMD_RETRIG; param &= 0x0F; break;
70
+ case 0xA0: param = (data & 0x0F) << 4; command = CMD_GLOBALVOLSLIDE; break;
71
+ case 0xB0: param = data & 0x0F; command = CMD_GLOBALVOLSLIDE; break;
72
+ case 0xF0: param = ((data >> 8) & 0x0F) | 0xA0; break;
73
+ }
74
+ break;
75
+ case 0x0F: command = CMD_SPEED; break;
76
+ case 0x10: if ((param & 0xF0) != 0xE0) { command = CMD_VOLUMESLIDE; if ((param & 0xF0) == 0xF0) param = ((param << 4) | 0x0F); else param >>= 2; } break;
77
+ case 0x20: if ((param & 0xF0) != 0xE0) { command = CMD_VOLUMESLIDE; if ((param & 0xF0) != 0xF0) param >>= 2; } break;
78
+ case 0x30: command = CMD_RETRIG; break;
79
+ case 0x40: command = CMD_TREMOLO; break;
80
+ case 0x50: command = CMD_TREMOR; break;
81
+ case 0xEF: if (param > 0xFF) param = 0xFF; command = CMD_OFFSET; break;
82
+ }
83
+ if (command)
84
+ {
85
+ m->command = command;
86
+ m->param = param;
87
+ }
88
+ }
89
+
90
+
91
+ void UnpackMDLTrack(MODCOMMAND *pat, UINT nChannels, UINT nRows, UINT nTrack, const BYTE *lpTracks)
92
+ //-------------------------------------------------------------------------------------------------
93
+ {
94
+ MODCOMMAND cmd, *m = pat;
95
+ UINT len = *((WORD *)lpTracks);
96
+ UINT pos = 0, row = 0, i;
97
+ lpTracks += 2;
98
+ for (UINT ntrk=1; ntrk<nTrack; ntrk++)
99
+ {
100
+ lpTracks += len;
101
+ len = *((WORD *)lpTracks);
102
+ lpTracks += 2;
103
+ }
104
+ cmd.note = cmd.instr = 0;
105
+ cmd.volcmd = cmd.vol = 0;
106
+ cmd.command = cmd.param = 0;
107
+ while ((row < nRows) && (pos < len))
108
+ {
109
+ UINT xx;
110
+ BYTE b = lpTracks[pos++];
111
+ xx = b >> 2;
112
+ switch(b & 0x03)
113
+ {
114
+ case 0x01:
115
+ for (i=0; i<=xx; i++)
116
+ {
117
+ if (row) *m = *(m-nChannels);
118
+ m += nChannels;
119
+ row++;
120
+ if (row >= nRows) break;
121
+ }
122
+ break;
123
+
124
+ case 0x02:
125
+ if (xx < row) *m = pat[nChannels*xx];
126
+ m += nChannels;
127
+ row++;
128
+ break;
129
+
130
+ case 0x03:
131
+ {
132
+ cmd.note = (xx & 0x01) ? lpTracks[pos++] : 0;
133
+ cmd.instr = (xx & 0x02) ? lpTracks[pos++] : 0;
134
+ cmd.volcmd = cmd.vol = 0;
135
+ cmd.command = cmd.param = 0;
136
+ if ((cmd.note < NOTE_MAX-12) && (cmd.note)) cmd.note += 12;
137
+ UINT volume = (xx & 0x04) ? lpTracks[pos++] : 0;
138
+ UINT commands = (xx & 0x08) ? lpTracks[pos++] : 0;
139
+ UINT command1 = commands & 0x0F;
140
+ UINT command2 = commands & 0xF0;
141
+ UINT param1 = (xx & 0x10) ? lpTracks[pos++] : 0;
142
+ UINT param2 = (xx & 0x20) ? lpTracks[pos++] : 0;
143
+ if ((command1 == 0x0E) && ((param1 & 0xF0) == 0xF0) && (!command2))
144
+ {
145
+ param1 = ((param1 & 0x0F) << 8) | param2;
146
+ command1 = 0xEF;
147
+ command2 = param2 = 0;
148
+ }
149
+ if (volume)
150
+ {
151
+ cmd.volcmd = VOLCMD_VOLUME;
152
+ cmd.vol = (volume+1) >> 2;
153
+ }
154
+ ConvertMDLCommand(&cmd, command1, param1);
155
+ if ((cmd.command != CMD_SPEED)
156
+ && (cmd.command != CMD_TEMPO)
157
+ && (cmd.command != CMD_PATTERNBREAK))
158
+ ConvertMDLCommand(&cmd, command2, param2);
159
+ *m = cmd;
160
+ m += nChannels;
161
+ row++;
162
+ }
163
+ break;
164
+
165
+ // Empty Slots
166
+ default:
167
+ row += xx+1;
168
+ m += (xx+1)*nChannels;
169
+ if (row >= nRows) break;
170
+ }
171
+ }
172
+ }
173
+
174
+
175
+
176
+ BOOL CSoundFile_ReadMDL(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
177
+ //---------------------------------------------------------------
178
+ {
179
+ DWORD dwMemPos, dwPos, blocklen, dwTrackPos;
180
+ const MDLSONGHEADER *pmsh = (const MDLSONGHEADER *)lpStream;
181
+ const MDLINFOBLOCK *pmib;
182
+ const MDLPATTERNDATA *pmpd;
183
+ UINT i,j, norders = 0, npatterns = 0, ntracks = 0;
184
+ UINT ninstruments = 0, nsamples = 0;
185
+ WORD block;
186
+ WORD patterntracks[MAX_PATTERNS*32];
187
+ BYTE smpinfo[MAX_SAMPLES];
188
+ BYTE insvolenv[MAX_INSTRUMENTS];
189
+ BYTE inspanenv[MAX_INSTRUMENTS];
190
+ LPCBYTE pvolenv, ppanenv, ppitchenv;
191
+ UINT nvolenv, npanenv, npitchenv;
192
+
193
+ if ((!lpStream) || (dwMemLength < 1024)) return FALSE;
194
+ if ((pmsh->id != 0x4C444D44) || ((pmsh->version & 0xF0) > 0x10)) return FALSE;
195
+ SDL_memset(patterntracks, 0, sizeof(patterntracks));
196
+ SDL_memset(smpinfo, 0, sizeof(smpinfo));
197
+ SDL_memset(insvolenv, 0, sizeof(insvolenv));
198
+ SDL_memset(inspanenv, 0, sizeof(inspanenv));
199
+ dwMemPos = 5;
200
+ dwTrackPos = 0;
201
+ pvolenv = ppanenv = ppitchenv = NULL;
202
+ nvolenv = npanenv = npitchenv = 0;
203
+ _this->m_nSamples = _this->m_nInstruments = 0;
204
+ while (dwMemPos+6 < dwMemLength)
205
+ {
206
+ block = *((WORD *)(lpStream+dwMemPos));
207
+ blocklen = *((DWORD *)(lpStream+dwMemPos+2));
208
+ dwMemPos += 6;
209
+ if (dwMemPos + blocklen > dwMemLength)
210
+ {
211
+ if (dwMemPos == 11) return FALSE;
212
+ break;
213
+ }
214
+ switch(block)
215
+ {
216
+ // IN: infoblock
217
+ case 0x4E49:
218
+ pmib = (MDLINFOBLOCK *)(lpStream+dwMemPos);
219
+ norders = pmib->norders;
220
+ if (norders > MAX_ORDERS) norders = MAX_ORDERS;
221
+ _this->m_nRestartPos = pmib->repeatpos;
222
+ _this->m_nDefaultGlobalVolume = pmib->globalvol;
223
+ _this->m_nDefaultTempo = pmib->tempo;
224
+ _this->m_nDefaultSpeed = pmib->speed;
225
+ _this->m_nChannels = 4;
226
+ for (i=0; i<32; i++)
227
+ {
228
+ _this->ChnSettings[i].nVolume = 64;
229
+ _this->ChnSettings[i].nPan = (pmib->channelinfo[i] & 0x7F) << 1;
230
+ if (pmib->channelinfo[i] & 0x80)
231
+ _this->ChnSettings[i].dwFlags |= CHN_MUTE;
232
+ else
233
+ _this->m_nChannels = i+1;
234
+ }
235
+ for (j=0; j<norders; j++) _this->Order[j] = pmib->seq[j];
236
+ break;
237
+ // ME: song message
238
+ case 0x454D:
239
+ break;
240
+ // PA: Pattern Data
241
+ case 0x4150:
242
+ npatterns = lpStream[dwMemPos];
243
+ if (npatterns > MAX_PATTERNS) npatterns = MAX_PATTERNS;
244
+ dwPos = dwMemPos + 1;
245
+ for (i=0; i<npatterns; i++)
246
+ {
247
+ if (dwPos+18 >= dwMemLength) break;
248
+ pmpd = (MDLPATTERNDATA *)(lpStream + dwPos);
249
+ if (pmpd->channels > 32) break;
250
+ _this->PatternSize[i] = pmpd->lastrow+1;
251
+ if (_this->m_nChannels < pmpd->channels) _this->m_nChannels = pmpd->channels;
252
+ dwPos += 18 + 2*pmpd->channels;
253
+ for (j=0; j<pmpd->channels; j++)
254
+ {
255
+ patterntracks[i*32+j] = pmpd->data[j];
256
+ }
257
+ }
258
+ break;
259
+ // TR: Track Data
260
+ case 0x5254:
261
+ if (dwTrackPos) break;
262
+ ntracks = *((WORD *)(lpStream+dwMemPos));
263
+ dwTrackPos = dwMemPos+2;
264
+ break;
265
+ // II: Instruments
266
+ case 0x4949:
267
+ ninstruments = lpStream[dwMemPos];
268
+ dwPos = dwMemPos+1;
269
+ for (i=0; i<ninstruments; i++)
270
+ {
271
+ UINT nins = lpStream[dwPos];
272
+ if ((nins >= MAX_INSTRUMENTS) || (!nins)) break;
273
+ if (_this->m_nInstruments < nins) _this->m_nInstruments = nins;
274
+ if (!_this->Headers[nins])
275
+ {
276
+ UINT note = 12;
277
+ if ((_this->Headers[nins] = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER))) == NULL) break;
278
+ INSTRUMENTHEADER *penv = _this->Headers[nins];
279
+ SDL_memset(penv, 0, sizeof(INSTRUMENTHEADER));
280
+ penv->nGlobalVol = 64;
281
+ penv->nPPC = 5*12;
282
+ for (j=0; j<lpStream[dwPos+1]; j++)
283
+ {
284
+ const BYTE *ps = lpStream+dwPos+34+14*j;
285
+ while ((note < (UINT)(ps[1]+12)) && (note < NOTE_MAX))
286
+ {
287
+ penv->NoteMap[note] = note+1;
288
+ if (ps[0] < MAX_SAMPLES)
289
+ {
290
+ int ismp = ps[0];
291
+ penv->Keyboard[note] = ps[0];
292
+ _this->Ins[ismp].nVolume = ps[2];
293
+ _this->Ins[ismp].nPan = ps[4] << 1;
294
+ _this->Ins[ismp].nVibType = ps[11];
295
+ _this->Ins[ismp].nVibSweep = ps[10];
296
+ _this->Ins[ismp].nVibDepth = ps[9];
297
+ _this->Ins[ismp].nVibRate = ps[8];
298
+ }
299
+ penv->nFadeOut = (ps[7] << 8) | ps[6];
300
+ if (penv->nFadeOut == 0xFFFF) penv->nFadeOut = 0;
301
+ note++;
302
+ }
303
+ // Use volume envelope ?
304
+ if (ps[3] & 0x80)
305
+ {
306
+ penv->dwFlags |= ENV_VOLUME;
307
+ insvolenv[nins] = (ps[3] & 0x3F) + 1;
308
+ }
309
+ // Use panning envelope ?
310
+ if (ps[5] & 0x80)
311
+ {
312
+ penv->dwFlags |= ENV_PANNING;
313
+ inspanenv[nins] = (ps[5] & 0x3F) + 1;
314
+ }
315
+ }
316
+ }
317
+ dwPos += 34 + 14*lpStream[dwPos+1];
318
+ }
319
+ for (j=1; j<=_this->m_nInstruments; j++) if (!_this->Headers[j])
320
+ {
321
+ _this->Headers[j] = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER));
322
+ if (_this->Headers[j]) SDL_memset(_this->Headers[j], 0, sizeof(INSTRUMENTHEADER));
323
+ }
324
+ break;
325
+ // VE: Volume Envelope
326
+ case 0x4556:
327
+ if ((nvolenv = lpStream[dwMemPos]) == 0) break;
328
+ if (dwMemPos + nvolenv*32 + 1 <= dwMemLength) pvolenv = lpStream + dwMemPos + 1;
329
+ break;
330
+ // PE: Panning Envelope
331
+ case 0x4550:
332
+ if ((npanenv = lpStream[dwMemPos]) == 0) break;
333
+ if (dwMemPos + npanenv*32 + 1 <= dwMemLength) ppanenv = lpStream + dwMemPos + 1;
334
+ break;
335
+ // FE: Pitch Envelope
336
+ case 0x4546:
337
+ if ((npitchenv = lpStream[dwMemPos]) == 0) break;
338
+ if (dwMemPos + npitchenv*32 + 1 <= dwMemLength) ppitchenv = lpStream + dwMemPos + 1;
339
+ break;
340
+ // IS: Sample Infoblock
341
+ case 0x5349:
342
+ nsamples = lpStream[dwMemPos];
343
+ dwPos = dwMemPos+1;
344
+ for (i=0; i<nsamples; i++, dwPos += 59)
345
+ {
346
+ UINT nins = lpStream[dwPos];
347
+ if ((nins >= MAX_SAMPLES) || (!nins)) continue;
348
+ if (_this->m_nSamples < nins) _this->m_nSamples = nins;
349
+ MODINSTRUMENT *pins = &_this->Ins[nins];
350
+ pins->nC4Speed = *((DWORD *)(lpStream+dwPos+41));
351
+ pins->nLength = *((DWORD *)(lpStream+dwPos+45));
352
+ pins->nLoopStart = *((DWORD *)(lpStream+dwPos+49));
353
+ pins->nLoopEnd = pins->nLoopStart + *((DWORD *)(lpStream+dwPos+53));
354
+ if (pins->nLoopEnd > pins->nLoopStart) pins->uFlags |= CHN_LOOP;
355
+ pins->nGlobalVol = 64;
356
+ if (lpStream[dwPos+58] & 0x01)
357
+ {
358
+ pins->uFlags |= CHN_16BIT;
359
+ pins->nLength >>= 1;
360
+ pins->nLoopStart >>= 1;
361
+ pins->nLoopEnd >>= 1;
362
+ }
363
+ if (lpStream[dwPos+58] & 0x02) pins->uFlags |= CHN_PINGPONGLOOP;
364
+ smpinfo[nins] = (lpStream[dwPos+58] >> 2) & 3;
365
+ }
366
+ break;
367
+ // SA: Sample Data
368
+ case 0x4153:
369
+ dwPos = dwMemPos;
370
+ for (i=1; i<=_this->m_nSamples; i++) if ((_this->Ins[i].nLength) && (!_this->Ins[i].pSample) && (smpinfo[i] != 3) && (dwPos < dwMemLength))
371
+ {
372
+ MODINSTRUMENT *pins = &_this->Ins[i];
373
+ UINT flags = (pins->uFlags & CHN_16BIT) ? RS_PCM16S : RS_PCM8S;
374
+ if (!smpinfo[i])
375
+ {
376
+ dwPos += CSoundFile_ReadSample(_this, pins, flags, (LPSTR)(lpStream+dwPos), dwMemLength - dwPos);
377
+ } else
378
+ {
379
+ DWORD dwLen = *((DWORD *)(lpStream+dwPos));
380
+ dwPos += 4;
381
+ if ((dwLen < dwMemLength) && (dwLen <= dwMemLength - dwPos) && (dwLen > 4))
382
+ {
383
+ flags = (pins->uFlags & CHN_16BIT) ? RS_MDL16 : RS_MDL8;
384
+ CSoundFile_ReadSample(_this, pins, flags, (LPSTR)(lpStream+dwPos), dwLen);
385
+ }
386
+ dwPos += dwLen;
387
+ }
388
+ }
389
+ break;
390
+ }
391
+ dwMemPos += blocklen;
392
+ }
393
+ // Unpack Patterns
394
+ if ((dwTrackPos) && (npatterns) && (_this->m_nChannels) && (ntracks))
395
+ {
396
+ for (UINT ipat=0; ipat<npatterns; ipat++)
397
+ {
398
+ if ((_this->Patterns[ipat] = CSoundFile_AllocatePattern(_this->PatternSize[ipat], _this->m_nChannels)) == NULL) break;
399
+ for (UINT chn=0; chn<_this->m_nChannels; chn++) if ((patterntracks[ipat*32+chn]) && (patterntracks[ipat*32+chn] <= ntracks))
400
+ {
401
+ MODCOMMAND *m = _this->Patterns[ipat] + chn;
402
+ UnpackMDLTrack(m, _this->m_nChannels, _this->PatternSize[ipat], patterntracks[ipat*32+chn], lpStream+dwTrackPos);
403
+ }
404
+ }
405
+ }
406
+ // Set up envelopes
407
+ for (UINT iIns=1; iIns<=_this->m_nInstruments; iIns++) if (_this->Headers[iIns])
408
+ {
409
+ INSTRUMENTHEADER *penv = _this->Headers[iIns];
410
+ // Setup volume envelope
411
+ if ((nvolenv) && (pvolenv) && (insvolenv[iIns]))
412
+ {
413
+ LPCBYTE pve = pvolenv;
414
+ for (UINT nve=0; nve<nvolenv; nve++, pve+=33) if (pve[0]+1 == insvolenv[iIns])
415
+ {
416
+ WORD vtick = 1;
417
+ penv->nVolEnv = 15;
418
+ for (UINT iv=0; iv<15; iv++)
419
+ {
420
+ if (iv) vtick += pve[iv*2+1];
421
+ penv->VolPoints[iv] = vtick;
422
+ penv->VolEnv[iv] = pve[iv*2+2];
423
+ if (!pve[iv*2+1])
424
+ {
425
+ penv->nVolEnv = iv+1;
426
+ break;
427
+ }
428
+ }
429
+ penv->nVolSustainBegin = penv->nVolSustainEnd = pve[31] & 0x0F;
430
+ if (pve[31] & 0x10) penv->dwFlags |= ENV_VOLSUSTAIN;
431
+ if (pve[31] & 0x20) penv->dwFlags |= ENV_VOLLOOP;
432
+ penv->nVolLoopStart = pve[32] & 0x0F;
433
+ penv->nVolLoopEnd = pve[32] >> 4;
434
+ }
435
+ }
436
+ // Setup panning envelope
437
+ if ((npanenv) && (ppanenv) && (inspanenv[iIns]))
438
+ {
439
+ LPCBYTE ppe = ppanenv;
440
+ for (UINT npe=0; npe<npanenv; npe++, ppe+=33) if (ppe[0]+1 == inspanenv[iIns])
441
+ {
442
+ WORD vtick = 1;
443
+ penv->nPanEnv = 15;
444
+ for (UINT iv=0; iv<15; iv++)
445
+ {
446
+ if (iv) vtick += ppe[iv*2+1];
447
+ penv->PanPoints[iv] = vtick;
448
+ penv->PanEnv[iv] = ppe[iv*2+2];
449
+ if (!ppe[iv*2+1])
450
+ {
451
+ penv->nPanEnv = iv+1;
452
+ break;
453
+ }
454
+ }
455
+ if (ppe[31] & 0x10) penv->dwFlags |= ENV_PANSUSTAIN;
456
+ if (ppe[31] & 0x20) penv->dwFlags |= ENV_PANLOOP;
457
+ penv->nPanLoopStart = ppe[32] & 0x0F;
458
+ penv->nPanLoopEnd = ppe[32] >> 4;
459
+ }
460
+ }
461
+ }
462
+ _this->m_dwSongFlags |= SONG_LINEARSLIDES;
463
+ _this->m_nType = MOD_TYPE_MDL;
464
+ return TRUE;
465
+ }
466
+
467
+
468
+ /////////////////////////////////////////////////////////////////////////
469
+ // MDL Sample Unpacking
470
+
471
+ // MDL Huffman ReadBits compression
472
+ WORD MDLReadBits(DWORD *bitbuf, UINT *bitnum, LPBYTE *_ibuf, CHAR n)
473
+ //-----------------------------------------------------------------
474
+ {
475
+ LPBYTE ibuf = *_ibuf;
476
+ const WORD v = (WORD)(*bitbuf & ((1 << n) - 1) );
477
+ *bitbuf >>= n;
478
+ *bitnum -= n;
479
+ if (*bitnum <= 24)
480
+ {
481
+ *bitbuf |= (((DWORD)(*ibuf++)) << *bitnum);
482
+ *bitnum += 8;
483
+ }
484
+ *_ibuf = ibuf;
485
+ return v;
486
+ }
487
+
488
+