Class: Feepogram
- Inherits:
-
Object
- Object
- Feepogram
- Defined in:
- lib/feepogram.rb,
lib/feepogram/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#bloops ⇒ Object
readonly
Returns the value of attribute bloops.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
- #dub(sound_name, notes) ⇒ Object
-
#initialize(bloops, &block) ⇒ Feepogram
constructor
A new instance of Feepogram.
- #metaclass ⇒ Object
- #metaclass_eval(&block) ⇒ Object
- #phrase(&block) ⇒ Object
- #play ⇒ Object
- #sound(name, base, &block) ⇒ Object
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
#bloops ⇒ Object (readonly)
Returns the value of attribute bloops.
2 3 4 |
# File 'lib/feepogram.rb', line 2 def bloops @bloops end |
#length ⇒ Object (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 |
#metaclass ⇒ Object
15 16 17 |
# File 'lib/feepogram.rb', line 15 def class << self; self; end end |
#metaclass_eval(&block) ⇒ Object
19 20 21 |
# File 'lib/feepogram.rb', line 19 def (&block) .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 |
#play ⇒ Object
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) do define_method(name) do |notes| dub(name, notes) end end end |