Class: Sound

Inherits:
Object
  • Object
show all
Defined in:
src/ruby/models/sound.rb,
mrb_doc/models/sound.rb

Overview

The Sound class holds shorter sounds, these are usually used for sound effects.

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame_count) ⇒ Sound

Creates a new instance of Sound

Parameters:

  • frame_count (Integer)


5
6
7
8
9
# File 'mrb_doc/models/sound.rb', line 5

def initialize(frame_count)
  # mrb_Sound_initialize
  # src/mruby_integration/models/sound.cpp
  Sound.new
end

Instance Attribute Details

#frame_countInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/sound.rb', line 4

def frame_count
  @frame_count
end

#pitchFloat

Returns:

  • (Float)


7
8
9
# File 'src/ruby/models/sound.rb', line 7

def pitch
  @pitch
end

#volumeFloat

Returns:

  • (Float)


7
8
9
# File 'src/ruby/models/sound.rb', line 7

def volume
  @volume
end

Class Method Details

.load(path) ⇒ Sound

Loads a sound file from the specified path

Parameters:

  • path (String)

Returns:

Raises:



21
22
23
24
25
26
27
# File 'src/ruby/models/sound.rb', line 21

def self.load(path)
  raise Sound::NotFound.new("Could not find file at path \"#{path}\"") unless File.exist?(path)
  load_sound(path).tap { |sound|
    sound.volume = 1
    sound.pitch = 1
  }
end

Instance Method Details

#pausenil

Pauses the sound, you will need to call Sound#resume to start it again

Returns:

  • (nil)


49
50
51
# File 'src/ruby/models/sound.rb', line 49

def pause
  pause_sound(self)
end

#playnil

Starts playing the sound

Returns:

  • (nil)


37
38
39
# File 'src/ruby/models/sound.rb', line 37

def play
  play_sound(self)
end

#playing?Boolean

Is the sound currently playing?

Returns:

  • (Boolean)


61
62
63
# File 'src/ruby/models/sound.rb', line 61

def playing?
  sound_playing?(self)
end

#resumenil

Resumes the sound

Returns:

  • (nil)


55
56
57
# File 'src/ruby/models/sound.rb', line 55

def resume
  resume_sound(self)
end

#stopnil

Stops the sound, you will need to call Sound#play to start it again.

Returns:

  • (nil)


43
44
45
# File 'src/ruby/models/sound.rb', line 43

def stop
  stop_sound(self)
end

#to_hHash

Return the object represented by a Hash

Returns:

  • (Hash)


11
12
13
14
15
# File 'src/ruby/models/sound.rb', line 11

def to_h
  {
    frame_count: frame_count,
  }
end

#unloadnil

Unloads the sound from memory

Returns:

  • (nil)


31
32
33
# File 'src/ruby/models/sound.rb', line 31

def unload
  unload_sound(self)
end