Skip to content

Commit 971a2c2

Browse files
committed
add Synths methods to Client to more efficiently create multiple synths at a single time
1 parent 5937fd3 commit 971a2c2

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

c.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sc
33
// C wraps a float32 and implements the Input interface.
44
type C float32
55

6+
// Max returns the maximum of one input and another.
67
func (c C) Max(other Input) Input {
78
if v, ok := other.(C); ok {
89
return C(maxFloat32(float32(c), float32(v)))

client.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,39 @@ func (c *Client) Synth(defName string, id, action, target int32, ctls map[string
280280
return newSynth(c, defName, id), nil
281281
}
282282

283+
// SynthArgs contains the arguments necessary to create a synth that is part of a group.
284+
type SynthArgs struct {
285+
DefName string
286+
ID int32
287+
Action int32
288+
Target int32
289+
Ctls map[string]float32
290+
}
291+
292+
// Synths creates multiple synth nodes at once with an OSC bundle.
293+
func (c *Client) Synths(args []SynthArgs) error {
294+
bun := osc.Bundle{
295+
Packets: make([]osc.Packet, len(args)),
296+
}
297+
for i, arg := range args {
298+
msg := osc.Message{
299+
Address: synthNewAddress,
300+
Arguments: osc.Arguments{
301+
osc.String(arg.DefName),
302+
osc.Int(arg.ID),
303+
osc.Int(arg.Action),
304+
osc.Int(arg.Target),
305+
},
306+
}
307+
for k, v := range arg.Ctls {
308+
msg.Arguments = append(msg.Arguments, osc.String(k))
309+
msg.Arguments = append(msg.Arguments, osc.Float(v))
310+
}
311+
bun.Packets[i] = msg
312+
}
313+
return c.oscConn.Send(bun)
314+
}
315+
283316
// Group creates a group.
284317
func (c *Client) Group(id, action, target int32) (*Group, error) {
285318
msg := osc.Message{

group.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ func (g *Group) Synth(defName string, id, action int32, ctls map[string]float32)
3131
return g.client.Synth(defName, id, action, g.Node.ID, ctls)
3232
}
3333

34-
// Free frees all the nodes in a group
34+
// Synths creates multiple synth nodes at once with an OSC bundle.
35+
func (g *Group) Synths(args []SynthArgs) error {
36+
for _, arg := range args {
37+
arg.Target = g.Node.ID
38+
}
39+
return g.client.Synths(args)
40+
}
41+
42+
// Free frees all the nodes in a group.
43+
// TODO
3544
func (g *Group) Free() error {
3645
return nil
3746
}
3847

39-
// FreeAll frees all the nodes in a group recursively
48+
// FreeAll frees all the nodes in a group recursively.
49+
// TODO
4050
func (g *Group) FreeAll() error {
4151
return nil
4252
}

server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (s *Server) args() ([]string, error) {
9191
return args, nil
9292
}
9393

94-
const ServerReadyMessage = "server ready"
94+
const serverReadyMessage = "server ready"
9595

9696
// Start starts a new instance of scsynth.
9797
// If the server doesn't print a line containing ServerReadyMessage
@@ -129,7 +129,7 @@ func (s *Server) Start(timeout time.Duration) (io.ReadCloser, io.ReadCloser, err
129129
if time.Now().Sub(start) > timeout {
130130
return nil, nil, ErrTimeout
131131
}
132-
if strings.Index(scanner.Text(), ServerReadyMessage) == -1 {
132+
if strings.Index(scanner.Text(), serverReadyMessage) == -1 {
133133
continue
134134
} else {
135135
break

0 commit comments

Comments
 (0)