 window.WEB_SOCKET_SWF_LOCATION = "/public/vendor/socket.io/WebSocketMain.swf"
 class Mpd
+  ######################### private #####################
+  
   MPD_INIT = /^OK MPD .+\n$/
   MPD_SENTINEL = /OK\n$/
   MPD_ACK = /^ACK \[\d+@\d+\].*\n$/

        results.push {track: track, file: file}
    return results

  handleMessage: (msg) ->
    [cmd, handler] = @expectStack.pop()
    cb handler(msg) for cb in @callbacks[cmd]

  send: (msg) ->
    @socket.emit 'ToMpd', msg + "\n"

  ######################### public #####################
  
  constructor: ->
    @socket = io.connect "http://localhost"
    @buffer = ""

    # queue of callbacks to call when we get data from mpd, indexed by command
    @callbacks = {}
    # what kind of response to expect back
    @expectStack = []

    @socket.on 'FromMpd', (data) =>
      @buffer += data

      if MPD_INIT.test @buffer
        @buffer = ""
      else if MPD_ACK.test @buffer
        @raiseEvent 'onError', @buffer
        @buffer = ""
      else if MPD_SENTINEL.test @buffer
        @handleMessage @buffer.substring(0, @buffer.length-3)
        @buffer = ""

    @createEventHandlers()

  removeListener: (registrar, handler) ->
    handlers = @nameToHandlers[registrar._name]
    for h, i in handlers
      if h is handler
        handlers.splice i, 1
        return

  getArtistList: (callback) ->
    @pushSend 'list artist', onListArtistMsg, callback
