Class: Ruby2D::Sound
- Inherits:
-
Object
- Object
- Ruby2D::Sound
- Defined in:
- lib/ruby2d/sound.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.mix_volume ⇒ Object
Get the volume of the sound mixer.
-
.mix_volume=(v) ⇒ Object
Set the volume of the sound mixer.
Instance Method Summary collapse
-
#initialize(path) ⇒ Sound
constructor
A new instance of Sound.
-
#length ⇒ Object
Returns the length in seconds.
-
#play ⇒ Object
Play the sound.
-
#volume ⇒ Object
Get the volume of the sound.
-
#volume=(v) ⇒ Object
Set the volume of the sound.
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
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/ruby2d/sound.rb', line 7 def data @data end |
#path ⇒ Object (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_volume ⇒ Object
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
#length ⇒ Object
Returns the length in seconds
25 26 27 |
# File 'lib/ruby2d/sound.rb', line 25 def length ext_length end |
#play ⇒ Object
Play the sound
20 21 22 |
# File 'lib/ruby2d/sound.rb', line 20 def play ext_play end |
#volume ⇒ Object
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 |