// play returns an http handler that plays a sample func (self *samples) play() websocket.Handler { return func(conn *websocket.Conn) { for { note, err := lightning.ReadNote(conn) if err == io.EOF { continue } if err != nil { response{false, err.Error()}.writeJSON(conn) return } if samplePath, exists := self.pool[note.Sample]; !exists { msg := fmt.Sprintf("sample %s does not exist", samplePath) response{false, msg}.writeJSON(conn) return } else { note.Sample = samplePath } err = self.engine.PlayNote(note) if err != nil { response{false, err.Error()}.writeJSON(conn) } response{true, "played " + note.Sample}.writeJSON(conn) } } }
// samplePlay exposes a websocket endpoint for playing a sample func (self *server) samplePlay() websocket.Handler { return func(conn *websocket.Conn) { for { var res Response note, re := lightning.ReadNote(conn) if re != nil { panic(re) } ep := self.engine.PlayNote(note) if ep != nil { panic(ep) } res = Response{"ok", "played " + note.Sample} ew := res.writeJSON(conn) if ew != nil { panic(ew) } } } }