Class: SFML::Sound

Inherits:
Object
  • Object
show all
Defined in:
lib/sfml/audio.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer = nil) ⇒ Sound

Returns a new instance of Sound.


86
87
88
89
90
91
92
93
94
# File 'lib/sfml/audio.rb', line 86

def initialize(buffer=nil)
  @sound = SFMLImporter.sfSound_create()
  raise "Failed create SFML::Sound" if @sound.null?
  @buffer = buffer
  if buffer
    SFMLImporter.sfSound_setBuffer(@sound, buffer.buffer)
  end
  ObjectSpace.define_finalizer @sound, SFML::Sound.dtor
end

Instance Attribute Details

#soundObject (readonly)

Returns the value of attribute sound


84
85
86
# File 'lib/sfml/audio.rb', line 84

def sound
  @sound
end

Class Method Details

.dtorObject


77
78
79
80
81
82
# File 'lib/sfml/audio.rb', line 77

def self.dtor
  proc { |id|
    SFMLImporter.sfSound_stop(id)
    SFMLImporter.sfSound_destroy(id)
  }
end

Instance Method Details

#get_bufferObject


103
104
105
# File 'lib/sfml/audio.rb', line 103

def get_buffer
  @buffer
end

#get_loopObject


128
129
130
# File 'lib/sfml/audio.rb', line 128

def get_loop
  SFMLImporter.sfSound_getLoop(@sound) > 0
end

#get_pitchObject


134
135
136
# File 'lib/sfml/audio.rb', line 134

def get_pitch
  SFMLImporter.sfSound_getPitch(@sound)
end

#get_playing_offsetObject


146
147
148
# File 'lib/sfml/audio.rb', line 146

def get_playing_offset
  SFMLImporter.sfSound_getPlayingOffset(@sound) / 1000000.0
end

#get_statusObject


115
116
117
118
119
120
121
122
123
124
# File 'lib/sfml/audio.rb', line 115

def get_status
  case SFMLImporter.sfSound_getStatus(@sound)
  when SFMLImporter::SFSTOPPED
    :stopped
  when SFMLImporter::SFPAUSED
    :paused
  when SFMLImporter::SFPLAYING
    :playing
  end
end

#get_volumeObject


140
141
142
# File 'lib/sfml/audio.rb', line 140

def get_volume
  SFMLImporter.sfSound_getVolume(@sound)
end

#initialize_copy(obj) ⇒ Object


95
96
97
98
# File 'lib/sfml/audio.rb', line 95

def initialize_copy(obj)
  @sound = SFMLImporter.sfSound_copy(obj.sound)
  @buffer = obj.buffer
end

#pauseObject


109
110
111
# File 'lib/sfml/audio.rb', line 109

def pause
  SFMLImporter.sfSound_pause(@sound)
end

#playObject


106
107
108
# File 'lib/sfml/audio.rb', line 106

def play
  SFMLImporter.sfSound_play(@sound)
end

#set_buffer(buffer) ⇒ Object


99
100
101
102
# File 'lib/sfml/audio.rb', line 99

def set_buffer(buffer)
  @buffer = buffer
  SFMLImporter.sfSound_setBuffer(@sound, buffer.buffer)
end

#set_loop(b) ⇒ Object


125
126
127
# File 'lib/sfml/audio.rb', line 125

def set_loop(b)
  SFMLImporter.sfSound_setLoop(@sound, (b ? 1 : 0))
end

#set_pitch(f) ⇒ Object


131
132
133
# File 'lib/sfml/audio.rb', line 131

def set_pitch(f)
  SFMLImporter.sfSound_setPitch(@sound, f)
end

#set_playing_offset(time) ⇒ Object


143
144
145
# File 'lib/sfml/audio.rb', line 143

def set_playing_offset(time)
  SFMLImporter.sfSound_setPlayingOffset(@sound, time * 1000000.0)
end

#set_volume(f) ⇒ Object


137
138
139
# File 'lib/sfml/audio.rb', line 137

def set_volume(f)
  SFMLImporter.sfSound_setVolume(@sound, f)
end

#stopObject


112
113
114
# File 'lib/sfml/audio.rb', line 112

def stop
  SFMLImporter.sfSound_stop(@sound)
end