Class: RubySketch::Sound

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

Overview

Sound object.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(path) ⇒ Sound

Load a sound file.

Parameters:

  • path (String)

    file path

Returns:

  • (Sound)

    sound object



51
52
53
54
# File 'lib/rubysketch/sound.rb', line 51

def self.load(path)
  f = Beeps::FileIn.new path
  self.new Beeps::Sound.new(f, f.seconds, nchannels: f.nchannels)
end

Instance Method Details

#play(gain: 1.0) ⇒ nil

Play sound.

Parameters:

  • gain (Numeric) (defaults to: 1.0)

    volume for playing sound

Returns:

  • (nil)

    nil



20
21
22
23
24
# File 'lib/rubysketch/sound.rb', line 20

def play(gain: 1.0)
  clean_stopped_players
  @players.push @sound.play(gain: gain)
  nil
end

#playing?Boolean

Returns whether or not playback is in progress.

Returns:

  • (Boolean)

    playing or not



40
41
42
43
# File 'lib/rubysketch/sound.rb', line 40

def playing?()
  clean_stopped_players
  not @players.empty?
end

#stopnil

Stop playing sounds.

Returns:

  • (nil)

    nil



30
31
32
33
34
# File 'lib/rubysketch/sound.rb', line 30

def stop()
  @players.each &:stop
  @players.clear
  nil
end