Class: Ruby2D::Sound

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Sound

Returns a new instance of Sound.



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

def initialize(path)
  unless File.exist? path
    raise Error, "Cannot find audio file `#{path}`"
  end
  @path = path
  unless ext_init(@path)
    raise Error, "Sound `#{@path}` cannot be created"
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.mix_volumeObject

Get the volume of the sound mixer



43
44
45
# File 'lib/ruby2d/sound.rb', line 43

def self.mix_volume
  ext_get_mix_volume
end

.mix_volume=(v) ⇒ Object

Set the volume of the sound mixer



48
49
50
51
52
53
# File 'lib/ruby2d/sound.rb', line 48

def self.mix_volume=(v)
  # Clamp value to between 0-100
  if v < 0 then v = 0 end
  if v > 100 then v = 100 end
  ext_set_mix_volume(v)
end

Instance Method Details

#lengthObject

Returns the length in seconds



25
26
27
# File 'lib/ruby2d/sound.rb', line 25

def length
  ext_length
end

#playObject

Play the sound



20
21
22
# File 'lib/ruby2d/sound.rb', line 20

def play
  ext_play
end

#volumeObject

Get the volume of the sound



30
31
32
# File 'lib/ruby2d/sound.rb', line 30

def volume
  ext_get_volume
end

#volume=(v) ⇒ Object

Set the volume of the sound



35
36
37
38
39
40
# File 'lib/ruby2d/sound.rb', line 35

def volume=(v)
  # Clamp value to between 0-100
  if v < 0 then v = 0 end
  if v > 100 then v = 100 end
  ext_set_volume(v)
end