本文整理匯總了Golang中github.com/scgolang/osc.NewMessage函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMessage函數的具體用法?Golang NewMessage怎麽用?Golang NewMessage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewMessage函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewGroup
// NewGroup creates a group
func (self *Client) NewGroup(id, action, target int32) error {
dumpReq := osc.NewMessage("/g_new")
dumpReq.Append(id)
dumpReq.Append(action)
dumpReq.Append(target)
return self.oscServer.SendTo(self.addr, dumpReq)
}
示例2: SendDef
// SendDef sends a synthdef to scsynth.
// This method blocks until a /done message is received
// indicating that the synthdef was loaded
func (self *Client) SendDef(def *Synthdef) error {
msg := osc.NewMessage("/d_recv")
db, err := def.Bytes()
if err != nil {
return err
}
msg.Append(db)
self.oscServer.SendTo(self.addr, msg)
var done *osc.Message
select {
case done = <-self.doneChan:
goto ParseMessage
case err = <-self.oscErrChan:
return err
}
ParseMessage:
// error if this message was not an ack of the synthdef
errmsg := "expected /done with /d_recv argument"
if done.CountArguments() != 1 {
return fmt.Errorf(errmsg)
}
if addr, isString := done.Arguments[0].(string); !isString || addr != "/d_recv" {
return fmt.Errorf(errmsg)
}
return nil
}
示例3: main
// Send a /quit message to scsynth
func main() {
addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:57130")
if err != nil {
log.Fatal(err)
}
oscServer := osc.NewServer(listenAddr, listenPort)
errChan := make(chan error)
doneChan := make(chan *osc.Message)
err = oscServer.AddMsgHandler("/done", func(msg *osc.Message) {
doneChan <- msg
})
if err != nil {
log.Println("could not send quit message")
log.Fatal(err)
}
go func() {
errChan <- oscServer.ListenAndDispatch()
}()
err = <-oscServer.Listening
if err != nil {
log.Fatal(err)
}
log.Println("sending quit request")
quitReq := osc.NewMessage("/quit")
err = oscServer.SendTo(addr, quitReq)
if err != nil {
log.Fatal(err)
}
select {
case quitResp := <-doneChan:
osc.PrintMessage(quitResp)
case err := <-errChan:
log.Fatal(err)
}
}
示例4: FreeAll
// FreeAll frees all nodes in a group
func (self *Client) FreeAll(gids ...int32) error {
freeReq := osc.NewMessage(groupFreeAllAddress)
for _, gid := range gids {
freeReq.Append(gid)
}
return self.oscServer.SendTo(self.conn, freeReq)
}
示例5: Gen
// Gen generates a buffer using a routine.
// A runtime panic will occur if routine is not one of the
// BufferRoutine constants.
func (self *Buffer) Gen(routine string, flags int, args ...float32) error {
if err := checkBufferRoutine(routine); err != nil {
return err
}
if err := checkBufferGenFlags(flags); err != nil {
return err
}
pat := bufferGenAddress
gen, err := osc.NewMessage(pat)
if err != nil {
return err
}
if err := gen.WriteInt32(self.Num); err != nil {
return err
}
if err := gen.WriteString(routine); err != nil {
return err
}
if err := gen.WriteInt32(int32(flags)); err != nil {
return err
}
for _, arg := range args {
if err := gen.WriteFloat32(arg); err != nil {
return err
}
}
if err := self.client.oscConn.Send(gen); err != nil {
return err
}
var done *osc.Message
select {
case done = <-self.client.doneChan:
case err = <-self.client.oscErrChan:
return err
}
if done.CountArguments() != 2 {
return errors.New("expected two arguments to /done message")
}
_, err = done.ReadString()
if err != nil {
return err
}
bufnum, err := done.ReadInt32()
if err != nil {
return err
}
// TODO:
// Don't error if we get a done message for a different buffer.
// We should probably requeue this particular done message on doneChan.
if bufnum != self.Num {
m := "expected done message for buffer %d, but got one for buffer %d"
return fmt.Errorf(m, self.Num, bufnum)
}
return nil
}
示例6: Synth
// Synth creates a synth node.
func (self *Client) Synth(defName string, id, action, target int32, ctls map[string]float32) (*Synth, error) {
synthReq, err := osc.NewMessage(synthNewAddress)
if err != nil {
return nil, err
}
if err := synthReq.WriteString(defName); err != nil {
return nil, err
}
if err := synthReq.WriteInt32(id); err != nil {
return nil, err
}
if err := synthReq.WriteInt32(action); err != nil {
return nil, err
}
if err := synthReq.WriteInt32(target); err != nil {
return nil, err
}
if ctls != nil {
for k, v := range ctls {
if err := synthReq.WriteString(k); err != nil {
return nil, err
}
if err := synthReq.WriteFloat32(v); err != nil {
return nil, err
}
}
}
if err := self.oscConn.Send(synthReq); err != nil {
return nil, err
}
return newSynth(self, defName, id), nil
}
示例7: FreeAll
// FreeAll frees all nodes in a group
func (self *Client) FreeAll(gids ...int32) error {
freeReq := osc.NewMessage("/g_freeAll")
for _, gid := range gids {
freeReq.Append(gid)
}
return self.oscServer.SendTo(self.addr, freeReq)
}
示例8: Set
// Set the value of a synth control.
func (self *Synth) Set(ctls map[string]float32) error {
set := osc.NewMessage(setSynthNodeAddress)
set.Append(self.id)
for name, value := range ctls {
set.Append(name, value)
}
return self.client.oscServer.SendTo(self.client.conn, set)
}
示例9: NewSynth
// NewSynth creates a synth
func (self *Client) NewSynth(name string, id, action, target int32) error {
synthReq := osc.NewMessage("/s_new")
synthReq.Append(name)
synthReq.Append(id)
synthReq.Append(action)
synthReq.Append(target)
synthReq.Append(int32(0))
return self.oscServer.SendTo(self.addr, synthReq)
}
示例10: Free
// Free a synth node.
func (self *Synth) Free() error {
free, err := osc.NewMessage(freeSynthNodeAddress)
if err != nil {
return err
}
if err := free.WriteInt32(self.id); err != nil {
return err
}
return self.client.oscConn.Send(free)
}
示例11: DumpOSC
// DumpOSC sends a /dumpOSC message to scsynth
// level should be DumpOff, DumpParsed, DumpContents, DumpAll
func (self *Client) DumpOSC(level int32) error {
dumpReq, err := osc.NewMessage(dumpOscAddress)
if err != nil {
return err
}
if err := dumpReq.WriteInt32(level); err != nil {
return err
}
return self.oscConn.Send(dumpReq)
}
示例12: Group
// NewGroup creates a group
func (self *Client) Group(id, action, target int32) (*Group, error) {
dumpReq := osc.NewMessage(groupNewAddress)
dumpReq.Append(id)
dumpReq.Append(action)
dumpReq.Append(target)
err := self.oscServer.SendTo(self.conn, dumpReq)
if err != nil {
return nil, err
}
return newGroup(self, id), nil
}
示例13: QueryGroup
// QueryGroup g_queryTree for a particular group
func (self *Client) QueryGroup(id int32) (*group, error) {
addr := "/g_queryTree"
gq := osc.NewMessage(addr)
gq.Append(int32(RootNodeID))
err := self.oscServer.SendTo(self.addr, gq)
if err != nil {
return nil, err
}
// wait for response
resp := <-self.gqueryTreeChan
return parseGroup(resp)
}
示例14: FreeAll
// FreeAll frees all nodes in a group
func (self *Client) FreeAll(gids ...int32) error {
freeReq, err := osc.NewMessage(groupFreeAllAddress)
if err != nil {
return err
}
for _, gid := range gids {
if err := freeReq.WriteInt32(gid); err != nil {
return err
}
}
return self.oscConn.Send(freeReq)
}
示例15: AllocBuffer
// AllocBuffer allocates a buffer on the server
func (self *Client) AllocBuffer(frames, channels int) (*Buffer, error) {
buf := newBuffer(self)
pat := bufferAllocAddress
alloc, err := osc.NewMessage(pat)
if err != nil {
return nil, err
}
if err := alloc.WriteInt32(buf.Num); err != nil {
return nil, err
}
if err := alloc.WriteInt32(int32(frames)); err != nil {
return nil, err
}
if err := alloc.WriteInt32(int32(channels)); err != nil {
return nil, err
}
if err := self.oscConn.Send(alloc); err != nil {
return nil, err
}
var done *osc.Message
select {
case done = <-self.doneChan:
break
case err = <-self.oscErrChan:
return nil, err
}
// error if this message was not an ack of the synthdef
if done.CountArguments() != 2 {
return nil, fmt.Errorf("expected two arguments to /done message")
}
addr, err := done.ReadString()
if err != nil {
return nil, err
}
if addr != pat {
return nil, fmt.Errorf("expected first argument to be %s but got %s", pat, addr)
}
bufnum, err := done.ReadInt32()
if err != nil {
return nil, err
}
// TODO:
// Don't error if we get a done message for a different buffer.
// We should probably requeue this particular done message on doneChan.
if bufnum != buf.Num {
m := "expected done message for buffer %d, but got one for buffer %d"
return nil, fmt.Errorf(m, buf.Num, bufnum)
}
return buf, nil
}