Class: Ray::Music

Inherits:
AudioSource
  • Object
show all
Defined in:
lib/ray/music.rb,
ext/music.c

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ Music

Returns a new instance of Music.



3
4
5
# File 'lib/ray/music.rb', line 3

def initialize(filename = nil)
  open(filename) if filename
end

Instance Method Details

#durationFloat

Returns Duration of the music. 0 when no buffer is attached to the music.

Returns:

  • (Float)

    Duration of the music. 0 when no buffer is attached to the music.



71
72
73
74
# File 'ext/music.c', line 71

static
VALUE ray_music_duration(VALUE self) {
  return rb_float_new(say_music_get_duration(ray_rb2music(self)));
}

#looping=(val) ⇒ Object



44
45
46
47
48
# File 'ext/music.c', line 44

static
VALUE ray_music_set_looping(VALUE self, VALUE val) {
  say_music_set_looping(ray_rb2music(self), RTEST(val));
  return val;
}

#looping?true, false

Returns True if the music is looping.

Returns:

  • (true, false)

    True if the music is looping



38
39
40
41
# File 'ext/music.c', line 38

static
VALUE ray_music_is_looping(VALUE self) {
  return say_music_is_looping(ray_rb2music(self)) ? Qtrue : Qfalse;
}

#open(filename) ⇒ Object

Parameters:

  • filename (String)

    Name of the file containing the music to load.



27
28
29
30
31
32
33
34
35
# File 'ext/music.c', line 27

static
VALUE ray_music_open(VALUE self, VALUE arg) {
  say_music *music = ray_rb2music(self);
  if (!say_music_open(music, StringValuePtr(arg))) {
    rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
  }

  return self;
}

#pauseObject

Pauses the music. Can be resumed using play.



84
85
86
87
88
# File 'ext/music.c', line 84

static
VALUE ray_music_pause(VALUE self) {
  say_music_pause(ray_rb2music(self));
  return self;
}

#playObject

Plays the music (or resume from a pause)



77
78
79
80
81
# File 'ext/music.c', line 77

static
VALUE ray_music_play(VALUE self) {
  say_music_play(ray_rb2music(self));
  return self;
}

#pretty_print(q) ⇒ Object



7
8
9
# File 'lib/ray/music.rb', line 7

def pretty_print(q)
  super q, ["time", "duration", "looping?"]
end

#seek(time) ⇒ Object Also known as: time=

Seeks to a specific time in the music

Parameters:

  • time (Float)

    Time in seconds



55
56
57
58
59
# File 'ext/music.c', line 55

static
VALUE ray_music_seek(VALUE self, VALUE time) {
  say_music_seek(ray_rb2music(self), NUM2DBL(time));
  return time;
}

#stopObject

Stops the music



91
92
93
94
95
# File 'ext/music.c', line 91

static
VALUE ray_music_stop(VALUE self) {
  say_music_stop(ray_rb2music(self));
  return self;
}

#timeFloat

Returns current playing offset, in seconds.

Returns:

  • (Float)

    current playing offset, in seconds



62
63
64
65
# File 'ext/music.c', line 62

static
VALUE ray_music_time(VALUE self) {
  return rb_float_new(say_music_get_time(ray_rb2music(self)));
}