Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (45 sloc) 1.22 KB
require 'rubygems'
require 'mikka'
require File.dirname(__FILE__) + '/lib/jl1.0.1.jar'
java_import 'javazoom.jl.player.Player'
class Conductor < Mikka::Actor
def receive(msg)
if msg == "finale" # instrument wants end sound played
get_sender << "finale"
else
msg[0] << "play"
end
end
end
class Instrument < Mikka::Actor
def play(end_version=false)
file = "mp3/" + self.class.name + (end_version ? "End.mp3" : ".mp3")
puts "playing #{file}"
File.open(file) { |io| Player.new(io.to_inputstream).play }
puts "done playing #{file}"
end
def receive(instruction)
case instruction
when "play" then play
when "finale" then play(true)
end
end
end
class Guitar < Instrument; end
class Bass < Instrument; end
class Drum < Instrument
def play(end_version=false)
super
# Ask the conductor to request the end sound to be played
get_sender << "finale" unless end_version
end
end
system = Mikka.create_actor_system('systam')
conductor = system.actor_of(Mikka::Props[Conductor])
[Guitar, Drum, Bass].each do |inst_class|
# Why will this not work without wrapping?
conductor << [system.actor_of(Mikka::Props[inst_class])]
end
sleep 45
puts "Shutting down"
system.shutdown