Class: Feepogram

Inherits:
Object
  • Object
show all
Defined in:
lib/feepogram.rb,
lib/feepogram/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bloops, &block) ⇒ Feepogram

Returns a new instance of Feepogram.



4
5
6
7
8
9
10
11
12
13
# File 'lib/feepogram.rb', line 4

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.



2
3
4
# File 'lib/feepogram.rb', line 2

def bloops
  @bloops
end

#lengthObject (readonly)

Returns the value of attribute length.



2
3
4
# File 'lib/feepogram.rb', line 2

def length
  @length
end

Instance Method Details

#dub(sound_name, notes) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/feepogram.rb', line 48

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



15
16
17
# File 'lib/feepogram.rb', line 15

def metaclass
  class << self; self; end
end

#metaclass_eval(&block) ⇒ Object



19
20
21
# File 'lib/feepogram.rb', line 19

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

#phrase(&block) ⇒ Object



43
44
45
46
# File 'lib/feepogram.rb', line 43

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

#playObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/feepogram.rb', line 56

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



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

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