def __init__(self, Class, globalmedia, idfunc=None): """The collection will contain things belonging to the passed in class. @param Class: the Thing subclass that this is a collection of. @param idfunc: a function generating unique IDs. If None, a new generator will be formed. """ self.things = {} self.media = {} self.Class = Class self.globalmedia = globalmedia self.typename = Class.typename self._next_thing_id = idfunc or id_generator(start=config.THING_MIN_ID, prefix='').next
to remove media from the stage. Karena, Corey, Heath 24/08/2011 - Added tag variable to Thing class to store tags for a given thing. Notes: """ #siblings from upstage.util import id_generator from upstage.misc import UpstageError from upstage import config #twisted from twisted.python import log ## @brief _next_thing_id id_generator for things _next_thing_id = id_generator(start=config.THING_MIN_ID, prefix='').next _nullpos = (None,None,None) class Thing: """Base representation of a thing on stage""" def __init__(self, media, name="", position=_nullpos, ID=None): """ @param media -- id of media file @param name name of the thing @param position x, y and z position """ if ID is None: self.ID = _next_thing_id() else:
from cgi import parse_qs, parse_qsl #siblings from upstage import config from upstage.util import id_generator from upstage.misc import UpstageError #twisted from twisted.python import log from twisted.internet.protocol import Factory from twisted.protocols.basic import LineOnlyReceiver from twisted.internet import reactor from twisted.web import microdom ## @brief next_socket_id id_generator for sockets next_socket_id = id_generator(prefix='sock_').next class _UpstageSocket(LineOnlyReceiver): """Communicates with individual clients via a socket. Inherits from twisited.protocols.basic.LineOnlyReceiver""" # next 2 are twisted magic. delimiter = config.NUL # arbitrary length MAX_LENGTH = 2048 stage = None ID = None avatar = None client_hash = None # random string used to link the web and socket interfaces. unlogged_send_modes = ('DRAW_LINE', 'LOAD_CHAT')
from cgi import parse_qs, parse_qsl #siblings from upstage import config from upstage.util import id_generator from upstage.misc import UpstageError #twisted from twisted.python import log from twisted.internet.protocol import Factory from twisted.protocols.basic import LineOnlyReceiver from twisted.internet import reactor from twisted.web import microdom ## @brief next_socket_id id_generator for sockets next_socket_id = id_generator(prefix='sock_').next class _UpstageSocket(LineOnlyReceiver): """Communicates with individual clients via a socket. Inherits from twisited.protocols.basic.LineOnlyReceiver""" # next 2 are twisted magic. delimiter=config.NUL # arbitrary length MAX_LENGTH = 2048 stage = None ID = None avatar = None client_hash = None # random string used to link the web and socket interfaces. unlogged_send_modes = ('DRAW_LINE', 'LOAD_CHAT') unlogged_receive_modes = ('DRAW_LINE', 'DRAW_MOVE')
Modified by: David Daniels 2/10/2013 - Added get_tags() to get all the tags attached to a media type Modified by: Nitkalya Wiriyanuparb 05/10/2013 - Modified Audio class to support custom start/stop position Notes: """ import time #siblings from upstage.util import id_generator from upstage.misc import UpstageError from upstage import config #twisted from twisted.python import log ## @brief _next_thing_id id_generator for things _next_thing_id = id_generator(start=config.THING_MIN_ID, prefix='').next _nullpos = (None, None, None) class Thing: """Base representation of a thing on stage""" def __init__(self, media, name="", position=_nullpos, ID=None): """ @param media -- id of media file @param name name of the thing @param position x, y and z position """ if ID is None: self.ID = _next_thing_id() else:
class SpeechDirectory(Resource): """Handle requests for speech to be generated, and web requests for the generated speech file. """ children = {} # filename indexing child rersources. next_speech_id = id_generator(wrap=config.UTTERANCE_WRAP, prefix='utter-', suffix='.mp3').next def utter(self, msg, av=None, voice=None): """Start to make a speech file to be served via web. Call an external process to turn text into sound. A deferred waits on that process, and a _SpeechFile instance is made to render requests for it. The scripts run in the process are made or discovered by upstage.voices. """ if voice is None: print "av voice is %s " + av.voice try: # try for avatar's special voice voice = av.voice or 'default' except AttributeError: log.msg('avatar.voice missing for avatar %s' % av.ID) voice = 'default' # save voice mp3 in unique file. speechID = self.next_speech_id() speechfile = os.path.join(config.SPEECH_DIR, speechID) print voice cmd = VOICES.get(voice, VOICES['default']) log.msg('calling approximately echo "%s" | %s %s"' % (msg, cmd, speechfile)) d, process = _subprocess_with_timeout(cmd, (speechfile, )) process.write(msg) process.closeStdin() #process.closeStdout() d.addCallback(_debug_if_true) d.addErrback(log.msg) # web requests for the file can then wait on the deferred. self.children[speechID] = _SpeechFile(speechID, d) log.msg('speech.py-utter: speechID=%s' % (speechID)) reactor.callLater(config.MEDIA_DESTRUCT_TIME, self.infanticide, speechID) return config.SPEECH_URL + speechID def infanticide(self, speechID): """A child is too old to be any use -- if the clients haven't got it yet they are too far behind for it to make sense""" c = self.children.pop(speechID, None) if c is not None: c.expire() def getChild(self, path, request): """See twisted.web.Resource.getChild. The point of this is to temporarily ignore the non-existance of media files, because they are likely to be in production. 404s are generated eventually. Uses a dictionary to remember recent requests """ log.msg('asking for speech file %s' % path) try: #the_path = self.children[path] log.msg('self.children[path] = %s' % (self.children[path])) return self.children[path] except KeyError: return error.NoResource('not there') def render(self, resource): """A list of available speeches -- always falling out of date""" out = ["<html><body><h1>Speech</h1><ul>"] for p in self.children: out.append('<li><a href="%s%s">%s</a></li>' % (config.SPEECH_URL, p, p)) out.append('</ul></body></html>') return '\n'.join(out)