from boodle.agent import *
import random

# Laughs - a module for Andrew Plotkin's boodler
#
# (See http://www.eblong.com/zarf/boodler/index.html)

# Written by Bob Igo. This code file is in the public domain, with no
# warranty whatsoever. All sounds Copyright 2001 by Bob Igo
# (bobigo@attbi.com), and are free for non-commercial use.

# This module consists of this file, which should be placed in your
# boodler effects path, and the sound files listed below, which should
# be placed in the boodler sound repository, under the directory
# voice/laughter/bob.

# Several options are available:

# python boodler.py laughs.Many
# python boodler.py laughs.Wild
# python boodler.py laughs.Deep
# python boodler.py laughs.High
# python boodler.py laughs.Higher

laughs = [
	'voice/laughter/bob/laughing1.aiff',
	'voice/laughter/bob/laughing2.aiff',
	'voice/laughter/bob/laughing3.aiff',
	'voice/laughter/bob/laughing4.aiff',
	'voice/laughter/bob/laughing5.aiff',
	'voice/laughter/bob/laughing6.aiff',
	'voice/laughter/bob/laughing7.aiff',
	'voice/laughter/bob/laughing8.aiff',
	'voice/laughter/bob/laughing9.aiff',
	'voice/laughter/bob/laughing10.aiff',
	'voice/laughter/bob/laughing11.aiff',
	'voice/laughter/bob/laughing12.aiff',
	'voice/laughter/bob/laughing13.aiff',
	'voice/laughter/bob/laughing14.aiff',
	'voice/laughter/bob/laughing15.aiff'
]

class One(Agent):
	name = 'play a random laugh'
	def __init__(self, pitch=1.0):
		Agent.__init__(self)
		self.pitch = float(pitch)
		self.pan = random.uniform(-0.95, 0.95)
		self.vol = random.uniform(0.6, 1)
		self.lastsnd = ''
	def run(self):
		laugh = random.choice(laughs)
		if (laugh == self.lastsnd):
			laugh = random.choice(laughs)
		dur = self.sched_note_pan(laugh, self.pan, self.pitch, self.vol)
		self.lastsnd = laugh
		self.resched(dur)

class Many(Agent):
	name = 'chamber of laughs'
	def run(self):
		pitch = random.uniform(0.9, 1.1)
		self.sched_agent(FadeInOutAgent(One(pitch), 1, 8))
		delay = random.uniform(4, 8)
		self.resched(delay)

class Wild(Agent):
	name = 'mad range of laughing'
	def run(self):
		pitch = random.uniform(0.66, 1.25)
		self.sched_agent(FadeInOutAgent(One(pitch), 1, 8))
		delay = random.uniform(4, 8)
		self.resched(delay)

class Deep(Agent):
	name = 'giants laughing'
	def run(self):
		pitch = random.uniform(0.55, 0.80)
		self.sched_agent(FadeInOutAgent(One(pitch), 1, 10))
		delay = random.uniform(6, 10)
		self.resched(delay)

class High(Agent):
	name = 'gnomes laughing'
	def run(self):
		pitch = random.uniform(1.15, 1.45)
		self.sched_agent(FadeInOutAgent(One(pitch), 1, 8))
		delay = random.uniform(4, 8)
		self.resched(delay)

class Higher(Agent):
	name = 'psychotic pixies laughing'
	def run(self):
		pitch = random.uniform(1.7, 2.5)
		self.sched_agent(FadeInOutAgent(One(pitch), 1, 4))
		delay = random.uniform(2, 4)
		self.resched(delay)

