Class: RGame::Core::Song
- Inherits:
-
Object
- Object
- RGame::Core::Song
- Defined in:
- lib/rgame/core/audio.rb,
ext/rgame_core/ruby/audio_ext.c
Overview
A long piece of music, streamed from disk rather than decoded up front.
music = RGame::Core::Song.new(audio, 'assets/theme.ogg')
music.play(looping: true)
music. # => true
music.stop
Unlike a sample, a song is one voice: playing it while it plays restarts it from the beginning. Stopping and playing again also restarts — there is no pause.
"Only one song at a time" is a rule a game keeps, not one this class enforces. Two songs can play at once, which is what a crossfade is.
Instance Method Summary collapse
- #initialize(audio, path) ⇒ Object constructor
- #looping? ⇒ Boolean
-
#play(looping: false) ⇒ Object
looping:is a keyword here and positional in C, which has no keywords. - #play_looping(looping) ⇒ Object
- #playing? ⇒ Boolean
- #stop ⇒ Object
- #volume ⇒ Object
- #volume=(volume) ⇒ Object
Constructor Details
#initialize(audio, path) ⇒ Object
252 253 254 255 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 252
static VALUE song_initialize(VALUE self, VALUE audio, VALUE path) {
return sound_initialize(self, audio, path, &song_data_type, load_song,
rb_const_get(cSong, rb_intern("LoadError")));
}
|
Instance Method Details
#looping? ⇒ Boolean
275 276 277 278 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 275
static VALUE song_looping_p(VALUE self) {
return rgame_song_looping((rgame_song *)sound_unwrap(self, &song_data_type)->handle) ? Qtrue
: Qfalse;
}
|
#play(looping: false) ⇒ Object
looping: is a keyword here and positional in C, which has no keywords.
119 120 121 |
# File 'lib/rgame/core/audio.rb', line 119 def play(looping: false) play_looping(looping) end |
#play_looping(looping) ⇒ Object
259 260 261 262 263 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 259
static VALUE song_play(VALUE self, VALUE looping) {
rgame_song_play((rgame_song *)sound_unwrap(self, &song_data_type)->handle,
RTEST(looping) ? 1 : 0);
return self;
}
|
#playing? ⇒ Boolean
270 271 272 273 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 270
static VALUE song_playing_p(VALUE self) {
return rgame_song_playing((rgame_song *)sound_unwrap(self, &song_data_type)->handle) ? Qtrue
: Qfalse;
}
|
#stop ⇒ Object
265 266 267 268 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 265
static VALUE song_stop(VALUE self) {
rgame_song_stop((rgame_song *)sound_unwrap(self, &song_data_type)->handle);
return self;
}
|
#volume ⇒ Object
280 281 282 283 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 280
static VALUE song_volume(VALUE self) {
return DBL2NUM(
(double)rgame_song_volume((rgame_song *)sound_unwrap(self, &song_data_type)->handle));
}
|
#volume=(volume) ⇒ Object
285 286 287 288 289 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 285
static VALUE song_set_volume(VALUE self, VALUE volume) {
rgame_song_set_volume((rgame_song *)sound_unwrap(self, &song_data_type)->handle,
(float)NUM2DBL(volume));
return volume;
}
|