sfml3-rb 0.2.2 → 0.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.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +43 -17
  4. data/README.md +97 -29
  5. data/ext/audio/audio_enums.c +58 -20
  6. data/ext/audio/listener.c +89 -6
  7. data/ext/audio/music.c +206 -5
  8. data/ext/audio/sound.c +175 -5
  9. data/ext/audio/sound_buffer.c +189 -47
  10. data/ext/audio/sound_buffer_recorder.c +83 -16
  11. data/ext/audio/sound_recorder.c +172 -52
  12. data/ext/audio/sound_source_cone.c +108 -29
  13. data/ext/audio/sound_stream.c +178 -5
  14. data/ext/core/exceptions.c +10 -8
  15. data/ext/core/unicode.c +12 -2
  16. data/ext/ext.c +4 -0
  17. data/ext/graphics/blend_mode.c +203 -53
  18. data/ext/graphics/circle.c +271 -4
  19. data/ext/graphics/color.c +240 -90
  20. data/ext/graphics/drawable.c +15 -4
  21. data/ext/graphics/font.c +138 -25
  22. data/ext/graphics/glyph.c +31 -8
  23. data/ext/graphics/image.c +180 -37
  24. data/ext/graphics/polygon.c +293 -26
  25. data/ext/graphics/rect.c +211 -54
  26. data/ext/graphics/rectangle.c +279 -26
  27. data/ext/graphics/render_state.c +116 -2
  28. data/ext/graphics/render_texture.c +163 -2
  29. data/ext/graphics/shader.c +283 -17
  30. data/ext/graphics/shape.c +252 -26
  31. data/ext/graphics/sprite.c +216 -25
  32. data/ext/graphics/stencil_mode.c +148 -39
  33. data/ext/graphics/target.c +67 -22
  34. data/ext/graphics/target.h +15 -15
  35. data/ext/graphics/text.c +306 -6
  36. data/ext/graphics/texture.c +257 -3
  37. data/ext/graphics/transform.c +178 -5
  38. data/ext/graphics/transformable.c +126 -2
  39. data/ext/graphics/vertex.c +79 -2
  40. data/ext/graphics/vertex_array.c +128 -16
  41. data/ext/graphics/vertex_buffer.c +124 -2
  42. data/ext/graphics/view.c +130 -2
  43. data/ext/network/ftp.c +249 -10
  44. data/ext/network/http.c +156 -38
  45. data/ext/network/ip_address.c +107 -26
  46. data/ext/network/network_enums.c +248 -141
  47. data/ext/network/packet.c +273 -39
  48. data/ext/network/socket_selector.c +91 -19
  49. data/ext/network/tcp_listener.c +75 -16
  50. data/ext/network/tcp_socket.c +128 -25
  51. data/ext/network/udp_socket.c +122 -26
  52. data/ext/ports.rb +7 -0
  53. data/ext/system/buffer.c +41 -12
  54. data/ext/system/clock.c +68 -9
  55. data/ext/system/input_stream.c +94 -42
  56. data/ext/system/sleep.c +10 -2
  57. data/ext/system/time.c +172 -34
  58. data/ext/system/vec2.c +156 -35
  59. data/ext/system/vec3.c +166 -35
  60. data/ext/window/clipboard.c +47 -17
  61. data/ext/window/context.c +59 -9
  62. data/ext/window/context_settings.c +116 -38
  63. data/ext/window/cursor.c +39 -9
  64. data/ext/window/event.c +163 -42
  65. data/ext/window/joystick.c +69 -3
  66. data/ext/window/keyboard.c +168 -116
  67. data/ext/window/mouse.c +36 -2
  68. data/ext/window/sensor.c +28 -2
  69. data/ext/window/touch.c +20 -2
  70. data/ext/window/video_mode.c +90 -19
  71. data/ext/window/vulkan.c +34 -6
  72. data/ext/window/window.c +340 -16
  73. data/lib/sfml/version.rb +1 -1
  74. data/sig/audio/audio_enums.rbs +30 -0
  75. data/sig/audio/listener.rbs +16 -0
  76. data/sig/audio/music.rbs +56 -0
  77. data/sig/audio/sound.rbs +51 -0
  78. data/sig/audio/sound_buffer.rbs +17 -0
  79. data/sig/audio/sound_buffer_recorder.rbs +14 -0
  80. data/sig/audio/sound_recorder.rbs +17 -0
  81. data/sig/audio/sound_source_cone.rbs +14 -0
  82. data/sig/audio/sound_stream.rbs +51 -0
  83. data/sig/graphics/blend_mode.rbs +29 -0
  84. data/sig/graphics/circle.rbs +44 -0
  85. data/sig/graphics/color.rbs +39 -0
  86. data/sig/graphics/drawable.rbs +5 -0
  87. data/sig/graphics/font.rbs +20 -0
  88. data/sig/graphics/glyph.rbs +7 -0
  89. data/sig/graphics/image.rbs +22 -0
  90. data/sig/graphics/polygon.rbs +42 -0
  91. data/sig/graphics/rect.rbs +33 -0
  92. data/sig/graphics/rectangle.rbs +42 -0
  93. data/sig/graphics/render_state.rbs +21 -0
  94. data/sig/graphics/render_texture.rbs +37 -0
  95. data/sig/graphics/shader.rbs +39 -0
  96. data/sig/graphics/shape.rbs +38 -0
  97. data/sig/graphics/sprite.rbs +34 -0
  98. data/sig/graphics/stencil_mode.rbs +18 -0
  99. data/sig/graphics/target.rbs +10 -0
  100. data/sig/graphics/text.rbs +48 -0
  101. data/sig/graphics/texture.rbs +34 -0
  102. data/sig/graphics/transform.rbs +37 -0
  103. data/sig/graphics/transformable.rbs +25 -0
  104. data/sig/graphics/vertex.rbs +17 -0
  105. data/sig/graphics/vertex_array.rbs +17 -0
  106. data/sig/graphics/vertex_buffer.rbs +22 -0
  107. data/sig/graphics/view.rbs +24 -0
  108. data/sig/network/ftp.rbs +46 -0
  109. data/sig/network/http.rbs +27 -0
  110. data/sig/network/ip_address.rbs +22 -0
  111. data/sig/network/network_enums.rbs +95 -0
  112. data/sig/network/packet.rbs +40 -0
  113. data/sig/network/socket_selector.rbs +14 -0
  114. data/sig/network/tcp_listener.rbs +13 -0
  115. data/sig/network/tcp_socket.rbs +18 -0
  116. data/sig/network/udp_socket.rbs +17 -0
  117. data/sig/system/buffer.rbs +11 -0
  118. data/sig/system/clock.rbs +13 -0
  119. data/sig/system/input_stream.rbs +7 -0
  120. data/sig/system/sleep.rbs +3 -0
  121. data/sig/system/time.rbs +28 -0
  122. data/sig/system/vec2.rbs +26 -0
  123. data/sig/system/vec3.rbs +27 -0
  124. data/sig/window/clipboard.rbs +8 -0
  125. data/sig/window/context.rbs +11 -0
  126. data/sig/window/context_settings.rbs +20 -0
  127. data/sig/window/cursor.rbs +6 -0
  128. data/sig/window/event.rbs +20 -0
  129. data/sig/window/joystick.rbs +15 -0
  130. data/sig/window/keyboard.rbs +10 -0
  131. data/sig/window/mouse.rbs +9 -0
  132. data/sig/window/sensor.rbs +8 -0
  133. data/sig/window/touch.rbs +6 -0
  134. data/sig/window/video_mode.rbs +16 -0
  135. data/sig/window/vulkan.rbs +7 -0
  136. data/sig/window/window.rbs +57 -0
  137. metadata +66 -2
data/ext/audio/music.c CHANGED
@@ -40,16 +40,23 @@ static void* Music_destroy_without_gvl(void* handle) {
40
40
  static void Music_free(void* ptr) {
41
41
  Music* music = ptr;
42
42
 
43
- effect_processor_release(music->source.effect_slot);
43
+ /* Destroy (which blocks until CSFML guarantees no in-flight audio-thread
44
+ callback still references this source) before releasing the effect
45
+ slot, not after -- see the matching comment in sound.c's Sound_free. */
44
46
  rb_thread_call_without_gvl(Music_destroy_without_gvl, music->source.handle, RUBY_UBF_IO, NULL);
47
+ effect_processor_release(music->source.effect_slot);
45
48
  rb_gc_unregister_address(&music->rb_stream);
46
49
  free(music);
47
50
  }
48
51
 
52
+ /* Deliberately no RUBY_TYPED_FREE_IMMEDIATELY: Music_free releases the GVL for
53
+ sfMusic_destroy, and freeing during GC (which the flag requests) would let
54
+ another thread allocate while GC is mid-cycle, which Ruby aborts on as
55
+ "object allocation during garbage collection phase". Deferred finalization
56
+ runs the same free with the GVL held and no GC in progress. */
49
57
  static const rb_data_type_t Music_data_type = {
50
58
  .wrap_struct_name = "SFML::Music",
51
- .function = {.dmark = Music_mark, .dfree = Music_free, .dsize = NULL},
52
- .flags = RUBY_TYPED_FREE_IMMEDIATELY};
59
+ .function = {.dmark = Music_mark, .dfree = Music_free, .dsize = NULL}};
53
60
 
54
61
  static VALUE Music_wrap(VALUE klass, sfMusic* handle, VALUE rb_stream) {
55
62
  Music* ptr;
@@ -68,10 +75,26 @@ static VALUE Music_wrap(VALUE klass, sfMusic* handle, VALUE rb_stream) {
68
75
  return TypedData_Wrap_Struct(klass, &Music_data_type, ptr);
69
76
  }
70
77
 
78
+ /* call-seq:
79
+ * Music.from_file(path) -> Music
80
+ *
81
+ * Creates a music stream that reads from an audio file.
82
+ *
83
+ * @return [Music]
84
+ * @raise [RuntimeError] if the file cannot be opened or decoded
85
+ */
71
86
  static VALUE Music_from_file(VALUE klass, VALUE rb_path) {
72
87
  return Music_wrap(klass, sfMusic_createFromFile(StringValueCStr(rb_path)), Qnil);
73
88
  }
74
89
 
90
+ /* call-seq:
91
+ * Music.from_memory(data) -> Music
92
+ *
93
+ * Creates a music stream that reads from audio held in a String.
94
+ *
95
+ * @return [Music]
96
+ * @raise [RuntimeError] if +data+ cannot be decoded
97
+ */
75
98
  static VALUE Music_from_memory(VALUE klass, VALUE rb_data) {
76
99
  StringValue(rb_data);
77
100
 
@@ -79,6 +102,14 @@ static VALUE Music_from_memory(VALUE klass, VALUE rb_data) {
79
102
  klass, sfMusic_createFromMemory(RSTRING_PTR(rb_data), (size_t)RSTRING_LEN(rb_data)), Qnil);
80
103
  }
81
104
 
105
+ /* call-seq:
106
+ * Music.from_stream(stream) -> Music
107
+ *
108
+ * Creates a music stream that reads from a custom InputStream.
109
+ *
110
+ * @return [Music]
111
+ * @raise [RuntimeError] if the stream cannot be decoded
112
+ */
82
113
  static VALUE Music_from_stream(VALUE klass, VALUE rb_stream) {
83
114
  VALUE holder = Qnil;
84
115
  sfInputStream* stream = input_stream_from_rb(rb_stream, &holder);
@@ -86,18 +117,43 @@ static VALUE Music_from_stream(VALUE klass, VALUE rb_stream) {
86
117
  return Music_wrap(klass, sfMusic_createFromStream(stream), holder);
87
118
  }
88
119
 
120
+ /* call-seq: duration -> Time
121
+ *
122
+ * Returns the total duration of the music.
123
+ *
124
+ * @return [Time] total duration of the music
125
+ */
89
126
  static VALUE Music_duration(VALUE self) {
90
127
  return time_to_rb(sfMusic_getDuration(Get_Music_Struct(self)));
91
128
  }
92
129
 
130
+ /* call-seq: channel_count -> Integer
131
+ *
132
+ * Returns the number of audio channels in the music.
133
+ *
134
+ * @return [Integer]
135
+ */
93
136
  static VALUE Music_channel_count(VALUE self) {
94
137
  return UINT2NUM(sfMusic_getChannelCount(Get_Music_Struct(self)));
95
138
  }
96
139
 
140
+ /* call-seq: sample_rate -> Integer
141
+ *
142
+ * Returns the music's sample rate in samples per second.
143
+ *
144
+ * @return [Integer]
145
+ */
97
146
  static VALUE Music_sample_rate(VALUE self) {
98
147
  return UINT2NUM(sfMusic_getSampleRate(Get_Music_Struct(self)));
99
148
  }
100
149
 
150
+ /* call-seq: channel_map -> Array<Symbol>
151
+ *
152
+ * Returns the channel layout of the music.
153
+ *
154
+ * @return [Array<Symbol>] one entry per channel, e.g.
155
+ * +[:front_left, :front_right]+
156
+ */
101
157
  static VALUE Music_channel_map(VALUE self) {
102
158
  size_t count = 0;
103
159
  const sfSoundChannel* map = sfMusic_getChannelMap(Get_Music_Struct(self), &count);
@@ -119,12 +175,26 @@ static VALUE Music_channel_map(VALUE self) {
119
175
 
120
176
  /* Loop points are an offset plus a length, matching sfTimeSpan. Returned as a
121
177
  two-element [offset, length] pair of SFML::Time. */
178
+ /* call-seq: loop_points -> [Time, Time]
179
+ *
180
+ * Returns the loop points as an +[offset, length]+ pair.
181
+ *
182
+ * @return [Array<Time>] a two-element +[offset, length]+ pair
183
+ */
122
184
  static VALUE Music_loop_points(VALUE self) {
123
185
  sfTimeSpan span = sfMusic_getLoopPoints(Get_Music_Struct(self));
124
186
 
125
187
  return rb_ary_new_from_args(2, time_to_rb(span.offset), time_to_rb(span.length));
126
188
  }
127
189
 
190
+ /* call-seq:
191
+ * loop_points=(value) -> [Time, Time]
192
+ *
193
+ * Sets the loop points as a two-element +[offset, length]+ pair.
194
+ *
195
+ * @return [Array<Time>] +value+
196
+ * @raise [ArgumentError] if +value+ is not a two-element Array
197
+ */
128
198
  static VALUE Music_set_loop_points(VALUE self, VALUE rb_span) {
129
199
  sfTimeSpan span;
130
200
 
@@ -146,8 +216,139 @@ static VALUE Music_set_loop_points(VALUE self, VALUE rb_span) {
146
216
  #undef SS_FN
147
217
  #undef SS_METHOD
148
218
 
149
- void Init_Music(VALUE rb_module) {
150
- rb_cMusic = rb_define_class_under(rb_module, "Music", rb_cObject);
219
+ /* Document-class: SFML::Music
220
+ * Music streamed from a file, memory buffer or InputStream rather than held
221
+ * fully decoded in memory, so it's suited to long tracks that would be
222
+ * wasteful to load whole as a SoundBuffer.
223
+ *
224
+ * @!method play
225
+ * Starts playback, or resumes it when paused.
226
+ * @return [self]
227
+ * @!method pause
228
+ * Pauses playback, keeping the current playing offset.
229
+ * @return [self]
230
+ * @!method stop
231
+ * Stops playback and rewinds to the beginning. May briefly block the
232
+ * calling thread if an audio-thread callback for this source is in
233
+ * flight.
234
+ * @return [self]
235
+ * @!method status
236
+ * Returns the current playback status.
237
+ * @return [Symbol] one of +:stopped+, +:paused+, +:playing+
238
+ * @!method looping?
239
+ * Returns +true+ if playback loops back to the start on completion.
240
+ * @return [Boolean]
241
+ * @!method looping=(value)
242
+ * Enables or disables looping.
243
+ * @return [Boolean]
244
+ * @!method pitch
245
+ * Returns the pitch scaling factor.
246
+ * @return [Float]
247
+ * @!method pitch=(value)
248
+ * Sets the pitch scaling factor.
249
+ * @return [Float]
250
+ * @!method pan
251
+ * Returns the source's stereo pan.
252
+ * @return [Float] stereo pan, -1 (left) to 1 (right)
253
+ * @!method pan=(value)
254
+ * Sets the source's stereo pan.
255
+ * @return [Float]
256
+ * @!method volume
257
+ * Returns the source's volume.
258
+ * @return [Float] 0 to 100
259
+ * @!method volume=(value)
260
+ * Sets the source's volume.
261
+ * @return [Float]
262
+ * @!method spatialization_enabled?
263
+ * Returns +true+ if 3D spatialization is enabled.
264
+ * @return [Boolean]
265
+ * @!method spatialization_enabled=(value)
266
+ * Enables or disables 3D spatialization.
267
+ * @return [Boolean]
268
+ * @!method position
269
+ * Returns the source's position in 3D space.
270
+ * @return [Vector3]
271
+ * @!method position=(value)
272
+ * Sets the source's position in 3D space.
273
+ * @return [Vector3]
274
+ * @!method direction
275
+ * Returns the direction the source is facing.
276
+ * @return [Vector3]
277
+ * @!method direction=(value)
278
+ * Sets the direction the source is facing.
279
+ * @return [Vector3]
280
+ * @!method velocity
281
+ * Returns the source's velocity, used for Doppler calculations.
282
+ * @return [Vector3]
283
+ * @!method velocity=(value)
284
+ * Sets the source's velocity for Doppler calculations.
285
+ * @return [Vector3]
286
+ * @!method cone
287
+ * Returns the source's directional attenuation cone.
288
+ * @return [SoundSourceCone]
289
+ * @!method cone=(value)
290
+ * Sets the source's directional attenuation cone.
291
+ * @return [SoundSourceCone]
292
+ * @!method doppler_factor
293
+ * Returns the factor by which the Doppler effect is scaled.
294
+ * @return [Float]
295
+ * @!method doppler_factor=(value)
296
+ * Sets the factor by which the Doppler effect is scaled.
297
+ * @return [Float]
298
+ * @!method directional_attenuation_factor
299
+ * Returns the factor controlling directional attenuation.
300
+ * @return [Float]
301
+ * @!method directional_attenuation_factor=(value)
302
+ * Sets the factor controlling directional attenuation.
303
+ * @return [Float]
304
+ * @!method relative_to_listener?
305
+ * Returns +true+ if the source is positioned relative to the listener.
306
+ * @return [Boolean]
307
+ * @!method relative_to_listener=(value)
308
+ * Makes the source relative to, or independent of, the listener.
309
+ * @return [Boolean]
310
+ * @!method min_distance
311
+ * Returns the minimum distance of the distance-attenuation model.
312
+ * @return [Float]
313
+ * @!method min_distance=(value)
314
+ * Sets the minimum distance of the distance-attenuation model.
315
+ * @return [Float]
316
+ * @!method max_distance
317
+ * Returns the maximum distance of the distance-attenuation model.
318
+ * @return [Float]
319
+ * @!method max_distance=(value)
320
+ * Sets the maximum distance of the distance-attenuation model.
321
+ * @return [Float]
322
+ * @!method min_gain
323
+ * Returns the minimum gain of the distance-attenuation model.
324
+ * @return [Float]
325
+ * @!method min_gain=(value)
326
+ * Sets the minimum gain of the distance-attenuation model.
327
+ * @return [Float]
328
+ * @!method max_gain
329
+ * Returns the maximum gain of the distance-attenuation model.
330
+ * @return [Float]
331
+ * @!method max_gain=(value)
332
+ * Sets the maximum gain of the distance-attenuation model.
333
+ * @return [Float]
334
+ * @!method attenuation
335
+ * Returns the distance-attenuation factor.
336
+ * @return [Float]
337
+ * @!method attenuation=(value)
338
+ * Sets the distance-attenuation factor.
339
+ * @return [Float]
340
+ * @!method playing_offset
341
+ * Returns the current playing offset.
342
+ * @return [Time]
343
+ * @!method playing_offset=(value)
344
+ * Seeks to the given playing offset.
345
+ * @return [Time]
346
+ * @!method effect_processor=(proc)
347
+ * Installs a Proc that post-processes this source's audio in real time.
348
+ * @return [Proc] +proc+
349
+ */
350
+ void Init_Music(VALUE rb_mSFML) {
351
+ rb_cMusic = rb_define_class_under(rb_mSFML, "Music", rb_cObject);
151
352
 
152
353
  rb_define_singleton_method(rb_cMusic, "from_file", Music_from_file, 1);
153
354
  rb_define_singleton_method(rb_cMusic, "from_memory", Music_from_memory, 1);
data/ext/audio/sound.c CHANGED
@@ -33,15 +33,25 @@ static void* Sound_destroy_without_gvl(void* handle) {
33
33
  static void Sound_free(void* ptr) {
34
34
  Sound* sound = ptr;
35
35
 
36
- effect_processor_release(sound->source.effect_slot);
36
+ /* Destroy (which blocks until CSFML guarantees no in-flight audio-thread
37
+ callback still references this source) before releasing the effect
38
+ slot, not after: releasing first opens a window where another Ruby
39
+ thread's effect_processor_acquire could reuse the slot number for an
40
+ unrelated new source while this source's callback might still be
41
+ executing against it. */
37
42
  rb_thread_call_without_gvl(Sound_destroy_without_gvl, sound->source.handle, RUBY_UBF_IO, NULL);
43
+ effect_processor_release(sound->source.effect_slot);
38
44
  free(sound);
39
45
  }
40
46
 
47
+ /* Deliberately no RUBY_TYPED_FREE_IMMEDIATELY: Sound_free releases the GVL for
48
+ sfSound_destroy, and freeing during GC (which the flag requests) would let
49
+ another thread allocate while GC is mid-cycle, which Ruby aborts on as
50
+ "object allocation during garbage collection phase". Deferred finalization
51
+ runs the same free with the GVL held and no GC in progress. */
41
52
  static const rb_data_type_t Sound_data_type = {
42
53
  .wrap_struct_name = "SFML::Sound",
43
- .function = {.dmark = Sound_mark, .dfree = Sound_free, .dsize = NULL},
44
- .flags = RUBY_TYPED_FREE_IMMEDIATELY};
54
+ .function = {.dmark = Sound_mark, .dfree = Sound_free, .dsize = NULL}};
45
55
 
46
56
  static VALUE Sound_wrap(VALUE klass, sfSound* handle, VALUE rb_buffer) {
47
57
  Sound* ptr;
@@ -58,6 +68,14 @@ static VALUE Sound_wrap(VALUE klass, sfSound* handle, VALUE rb_buffer) {
58
68
  return TypedData_Wrap_Struct(klass, &Sound_data_type, ptr);
59
69
  }
60
70
 
71
+ /* call-seq:
72
+ * Sound.new(buffer) -> Sound
73
+ *
74
+ * Creates a sound that plays the given buffer.
75
+ *
76
+ * @return [Sound]
77
+ * @raise [ArgumentError] if +buffer+ is not a SoundBuffer
78
+ */
61
79
  static VALUE Sound_new(VALUE klass, VALUE rb_buffer) {
62
80
  if (!rb_obj_is_kind_of(rb_buffer, Get_Klass_SoundBuffer())) {
63
81
  raise_invalid_argument_class(Get_Klass_SoundBuffer());
@@ -66,6 +84,12 @@ static VALUE Sound_new(VALUE klass, VALUE rb_buffer) {
66
84
  return Sound_wrap(klass, sfSound_create(Get_SoundBuffer_Struct(rb_buffer)), rb_buffer);
67
85
  }
68
86
 
87
+ /* call-seq: copy -> Sound
88
+ *
89
+ * Creates an independent copy of the sound that shares its buffer.
90
+ *
91
+ * @return [Sound] an independent copy that shares the same SoundBuffer
92
+ */
69
93
  static VALUE Sound_copy(VALUE self) {
70
94
  Sound* sound = (Sound*)Get_Sound_Struct(self);
71
95
 
@@ -73,6 +97,12 @@ static VALUE Sound_copy(VALUE self) {
73
97
  sound->rb_buffer);
74
98
  }
75
99
 
100
+ /* call-seq: buffer -> SoundBuffer
101
+ *
102
+ * Returns the buffer currently attached to this sound.
103
+ *
104
+ * @return [SoundBuffer] the buffer currently attached to this sound
105
+ */
76
106
  static VALUE Sound_get_buffer(VALUE self) {
77
107
  return ((Sound*)Get_Sound_Struct(self))->rb_buffer;
78
108
  }
@@ -93,6 +123,16 @@ static void* Sound_set_buffer_without_gvl(void* raw) {
93
123
  return NULL;
94
124
  }
95
125
 
126
+ /* call-seq:
127
+ * buffer=(value) -> SoundBuffer
128
+ *
129
+ * Attaches a new SoundBuffer. If a buffer is already attached and the sound
130
+ * is playing, it is stopped first, which may briefly block the calling
131
+ * thread (see #stop).
132
+ *
133
+ * @return [SoundBuffer] +value+
134
+ * @raise [ArgumentError] if +value+ is not a SoundBuffer
135
+ */
96
136
  static VALUE Sound_set_buffer(VALUE self, VALUE rb_buffer) {
97
137
  Sound* sound = (Sound*)Get_Sound_Struct(self);
98
138
  SoundSetBufferArgs args;
@@ -116,8 +156,138 @@ static VALUE Sound_set_buffer(VALUE self, VALUE rb_buffer) {
116
156
  #undef SS_FN
117
157
  #undef SS_METHOD
118
158
 
119
- void Init_Sound(VALUE rb_module) {
120
- rb_cSound = rb_define_class_under(rb_module, "Sound", rb_cObject);
159
+ /* Document-class: SFML::Sound
160
+ * A sound playing directly from a SoundBuffer held fully in memory. Suited
161
+ * to short effects; for long files prefer Music, which streams instead.
162
+ *
163
+ * @!method play
164
+ * Starts playback, or resumes it when paused.
165
+ * @return [self]
166
+ * @!method pause
167
+ * Pauses playback, keeping the current playing offset.
168
+ * @return [self]
169
+ * @!method stop
170
+ * Stops playback and rewinds to the beginning. May briefly block the
171
+ * calling thread if an audio-thread callback for this source is in
172
+ * flight.
173
+ * @return [self]
174
+ * @!method status
175
+ * Returns the current playback status.
176
+ * @return [Symbol] one of +:stopped+, +:paused+, +:playing+
177
+ * @!method looping?
178
+ * Returns +true+ if playback loops back to the start on completion.
179
+ * @return [Boolean]
180
+ * @!method looping=(value)
181
+ * Enables or disables looping.
182
+ * @return [Boolean]
183
+ * @!method pitch
184
+ * Returns the pitch scaling factor.
185
+ * @return [Float]
186
+ * @!method pitch=(value)
187
+ * Sets the pitch scaling factor.
188
+ * @return [Float]
189
+ * @!method pan
190
+ * Returns the source's stereo pan.
191
+ * @return [Float] stereo pan, -1 (left) to 1 (right)
192
+ * @!method pan=(value)
193
+ * Sets the source's stereo pan.
194
+ * @return [Float]
195
+ * @!method volume
196
+ * Returns the source's volume.
197
+ * @return [Float] 0 to 100
198
+ * @!method volume=(value)
199
+ * Sets the source's volume.
200
+ * @return [Float]
201
+ * @!method spatialization_enabled?
202
+ * Returns +true+ if 3D spatialization is enabled.
203
+ * @return [Boolean]
204
+ * @!method spatialization_enabled=(value)
205
+ * Enables or disables 3D spatialization.
206
+ * @return [Boolean]
207
+ * @!method position
208
+ * Returns the source's position in 3D space.
209
+ * @return [Vector3]
210
+ * @!method position=(value)
211
+ * Sets the source's position in 3D space.
212
+ * @return [Vector3]
213
+ * @!method direction
214
+ * Returns the direction the source is facing.
215
+ * @return [Vector3]
216
+ * @!method direction=(value)
217
+ * Sets the direction the source is facing.
218
+ * @return [Vector3]
219
+ * @!method velocity
220
+ * Returns the source's velocity, used for Doppler calculations.
221
+ * @return [Vector3]
222
+ * @!method velocity=(value)
223
+ * Sets the source's velocity for Doppler calculations.
224
+ * @return [Vector3]
225
+ * @!method cone
226
+ * Returns the source's directional attenuation cone.
227
+ * @return [SoundSourceCone]
228
+ * @!method cone=(value)
229
+ * Sets the source's directional attenuation cone.
230
+ * @return [SoundSourceCone]
231
+ * @!method doppler_factor
232
+ * Returns the factor by which the Doppler effect is scaled.
233
+ * @return [Float]
234
+ * @!method doppler_factor=(value)
235
+ * Sets the factor by which the Doppler effect is scaled.
236
+ * @return [Float]
237
+ * @!method directional_attenuation_factor
238
+ * Returns the factor controlling directional attenuation.
239
+ * @return [Float]
240
+ * @!method directional_attenuation_factor=(value)
241
+ * Sets the factor controlling directional attenuation.
242
+ * @return [Float]
243
+ * @!method relative_to_listener?
244
+ * Returns +true+ if the source is positioned relative to the listener.
245
+ * @return [Boolean]
246
+ * @!method relative_to_listener=(value)
247
+ * Makes the source relative to, or independent of, the listener.
248
+ * @return [Boolean]
249
+ * @!method min_distance
250
+ * Returns the minimum distance of the distance-attenuation model.
251
+ * @return [Float]
252
+ * @!method min_distance=(value)
253
+ * Sets the minimum distance of the distance-attenuation model.
254
+ * @return [Float]
255
+ * @!method max_distance
256
+ * Returns the maximum distance of the distance-attenuation model.
257
+ * @return [Float]
258
+ * @!method max_distance=(value)
259
+ * Sets the maximum distance of the distance-attenuation model.
260
+ * @return [Float]
261
+ * @!method min_gain
262
+ * Returns the minimum gain of the distance-attenuation model.
263
+ * @return [Float]
264
+ * @!method min_gain=(value)
265
+ * Sets the minimum gain of the distance-attenuation model.
266
+ * @return [Float]
267
+ * @!method max_gain
268
+ * Returns the maximum gain of the distance-attenuation model.
269
+ * @return [Float]
270
+ * @!method max_gain=(value)
271
+ * Sets the maximum gain of the distance-attenuation model.
272
+ * @return [Float]
273
+ * @!method attenuation
274
+ * Returns the distance-attenuation factor.
275
+ * @return [Float]
276
+ * @!method attenuation=(value)
277
+ * Sets the distance-attenuation factor.
278
+ * @return [Float]
279
+ * @!method playing_offset
280
+ * Returns the current playing offset.
281
+ * @return [Time]
282
+ * @!method playing_offset=(value)
283
+ * Seeks to the given playing offset.
284
+ * @return [Time]
285
+ * @!method effect_processor=(proc)
286
+ * Installs a Proc that post-processes this source's audio in real time.
287
+ * @return [Proc] +proc+
288
+ */
289
+ void Init_Sound(VALUE rb_mSFML) {
290
+ rb_cSound = rb_define_class_under(rb_mSFML, "Sound", rb_cObject);
121
291
 
122
292
  rb_define_singleton_method(rb_cSound, "new", Sound_new, 1);
123
293