Class: Feepogram

Inherits:
Object show all
Defined in:
lib/ext/bloops/songs/feepogram.rb

Overview

downloaded from github.com/aanand/feepogram

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bloops, &block) ⇒ Feepogram

Returns a new instance of Feepogram



5
6
7
8
9
10
11
12
13
14
# File 'lib/ext/bloops/songs/feepogram.rb', line 5

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

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

  instance_eval(&block)
end

Instance Attribute Details

#bloopsObject (readonly)

Returns the value of attribute bloops



3
4
5
# File 'lib/ext/bloops/songs/feepogram.rb', line 3

def bloops
  @bloops
end

#lengthObject (readonly)

Returns the value of attribute length



3
4
5
# File 'lib/ext/bloops/songs/feepogram.rb', line 3

def length
  @length
end

Instance Method Details

#dub(sound_name, notes) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/ext/bloops/songs/feepogram.rb', line 49

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

#metaclassObject



16
17
18
# File 'lib/ext/bloops/songs/feepogram.rb', line 16

def metaclass
  class << self; self; end
end

#metaclass_eval(&block) ⇒ Object



20
21
22
# File 'lib/ext/bloops/songs/feepogram.rb', line 20

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

#phrase(&block) ⇒ Object



44
45
46
47
# File 'lib/ext/bloops/songs/feepogram.rb', line 44

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

#playObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/ext/bloops/songs/feepogram.rb', line 57

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

#sound(name, base, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ext/bloops/songs/feepogram.rb', line 24

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