Sha256: e6a447f6b9cef113508c76d4156de80f6371897c3684f0e1ed39a9618307dfda

Contents?: true

Size: 920 Bytes

Versions: 28

Compression:

Stored size: 920 Bytes

Contents

module RubySketch


  # Sound object.
  #
  class Sound

    # @private
    def initialize(sound)
      @sound   = sound
      @players = []
    end

    # Play sound.
    #
    # @param [Numeric] gain volume for playing sound
    #
    # @return [nil] nil
    #
    def play(gain: 1.0)
      clean_stopped_players
      @players.push @sound.play(gain: gain)
      nil
    end

    # Stop playing sounds.
    #
    # @return [nil] nil
    #
    def stop()
      @players.each &:stop
      @players.clear
      nil
    end

    # Load a sound file.
    #
    # @param [String] path file path
    #
    # @return [Sound] sound object
    #
    def self.load(path)
      f = Beeps::FileIn.new path
      self.new Beeps::Sound.new(f, f.seconds, nchannels: f.nchannels)
    end

    private

    # @private
    def clean_stopped_players()
      @players.delete_if {|p| not p.playing?}
    end

  end# Sound


end# RubySketch

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rubysketch-0.7.6 lib/rubysketch/sound.rb
rubysketch-0.7.5 lib/rubysketch/sound.rb
rubysketch-0.7.4 lib/rubysketch/sound.rb
rubysketch-0.7.3 lib/rubysketch/sound.rb
rubysketch-0.7.2 lib/rubysketch/sound.rb
rubysketch-0.7.1 lib/rubysketch/sound.rb
rubysketch-0.7 lib/rubysketch/sound.rb
rubysketch-0.6.3 lib/rubysketch/sound.rb
rubysketch-0.6.2 lib/rubysketch/sound.rb
rubysketch-0.5.38 lib/rubysketch/sound.rb
rubysketch-0.5.37 lib/rubysketch/sound.rb
rubysketch-0.5.36 lib/rubysketch/sound.rb
rubysketch-0.5.35 lib/rubysketch/sound.rb
rubysketch-0.5.34 lib/rubysketch/sound.rb
rubysketch-0.5.33 lib/rubysketch/sound.rb
rubysketch-0.5.32 lib/rubysketch/sound.rb
rubysketch-0.5.31 lib/rubysketch/sound.rb
rubysketch-0.5.30 lib/rubysketch/sound.rb
rubysketch-0.5.28 lib/rubysketch/sound.rb
rubysketch-0.5.27 lib/rubysketch/sound.rb