Sha256: 249dbbf6322614cc8a4c797a513d345ce50daa99dc527aba90e841fa454c4b7a

Contents?: true

Size: 1.29 KB

Versions: 41

Compression:

Stored size: 1.29 KB

Contents

# downloaded from http://github.com/aanand/feepogram
class Feepogram
  attr_reader :bloops, :length

  def initialize(bloops, &block)
    @bloops = bloops
    @length = 0

    @sounds        = {}
    @tracks        = {}
    @track_lengths = {}

    instance_eval(&block)
  end

  def metaclass
    class << self; self; end
  end

  def metaclass_eval(&block)
    metaclass.class_eval(&block)
  end

  def sound(name, base, &block)
    name = name.to_sym

    sound = bloops.sound(base)

    @sounds[name]        = sound
    @tracks[name]        = ""
    @track_lengths[name] = 0

    block.call(sound)

    instance_variable_set("@#{name}", sound)

    metaclass_eval do
      define_method(name) do |notes|
        dub(name, notes)
      end
    end
  end

  def phrase(&block)
    instance_eval(&block)
    @length += 32
  end

  def dub sound_name, notes
    catchup = @length - @track_lengths[sound_name]

    @tracks[sound_name] << ("4 " * catchup)
    @tracks[sound_name] << notes
    @track_lengths[sound_name] = length+32
  end

  def play
    @tracks.each do |sound_name, notes|
      bloops.tune @sounds[sound_name], notes

      #puts "#{sound_name}: #{notes.gsub(/\s+/, ' ')}"
    end

    bloops.play
    sleep 1 while !bloops.stopped?
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
green_shoes-1.1.374 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.373 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.367 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.366 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.365 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.364 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.363 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.362 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.358 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.357 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.354 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.1.348 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.337 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.331 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.322 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.320 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.309 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.303 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.282 lib/ext/bloops/songs/feepogram.rb
green_shoes-1.0.273 lib/ext/bloops/songs/feepogram.rb