Class: Ruby2D::Music

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2d/music.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, opts = {}) ⇒ Music

Returns a new instance of Music.



9
10
11
12
13
14
15
16
17
18
# File 'lib/ruby2d/music.rb', line 9

def initialize(path, opts = {})
  unless File.exist? path
    raise Error, "Cannot find audio file `#{path}`"
  end
  @path = path
  @loop = opts[:loop] || false
  unless ext_init(@path)
    raise Error, "Music `#{@path}` cannot be created"
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#loopObject

Returns the value of attribute loop.



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

def loop
  @loop
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/ruby2d/music.rb', line 6

def path
  @path
end

Class Method Details

.volumeObject

Returns the volume, in percentage



41
42
43
# File 'lib/ruby2d/music.rb', line 41

def self.volume
  self.ext_get_volume
end

.volume=(v) ⇒ Object

Set music volume, 0 to 100%



46
47
48
49
50
# File 'lib/ruby2d/music.rb', line 46

def self.volume=(v)
  # If a negative value, volume will be 0
  if v < 0 then v = 0 end
  self.ext_set_volume(v)
end

Instance Method Details

#fadeout(ms) ⇒ Object

Fade out music over provided milliseconds



57
58
59
# File 'lib/ruby2d/music.rb', line 57

def fadeout(ms)
  ext_fadeout(ms)
end

#lengthObject

Returns the length in seconds



62
63
64
# File 'lib/ruby2d/music.rb', line 62

def length
  ext_length
end

#pauseObject

Pause the music



26
27
28
# File 'lib/ruby2d/music.rb', line 26

def pause
  ext_pause
end

#playObject

Play the music



21
22
23
# File 'lib/ruby2d/music.rb', line 21

def play
  ext_play
end

#resumeObject

Resume paused music



31
32
33
# File 'lib/ruby2d/music.rb', line 31

def resume
  ext_resume
end

#stopObject

Stop playing the music, start at beginning



36
37
38
# File 'lib/ruby2d/music.rb', line 36

def stop
  ext_stop
end

#volumeObject

Alias instance methods to class methods



53
# File 'lib/ruby2d/music.rb', line 53

def volume; Music.volume end

#volume=(v) ⇒ Object



54
# File 'lib/ruby2d/music.rb', line 54

def volume=(v); Music.volume=(v) end