2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "SC_CoreAudio.h"
24 #include "SC_HiddenWorld.h"
26 #include "SC_GraphDef.h"
28 #include "SC_UnitDef.h"
30 #include "SC_Lib_Cintf.h"
31 #include "SC_SequencedCommand.h"
33 #include "SC_Prototypes.h"
34 #include "scsynthsend.h"
35 #include "SC_WorldOptions.h"
37 extern int gMissingNodeID
;
39 // returns number of bytes in an OSC string.
40 int OSCstrlen(char *strin
);
42 Node
* Msg_GetNode(World
*inWorld
, sc_msg_iter
& msg
)
45 if (msg
.nextTag('i') == 's')
47 const char* loc
= msg
.gets();
48 int32 nodeID
= msg
.geti();
49 gMissingNodeID
= nodeID
;
50 node
= World_GetNode(inWorld
, nodeID
);
57 if (!node
->mIsGroup
) return 0;
58 node
= ((Group
*)node
)->mHead
;
61 if (!node
->mIsGroup
) return 0;
62 node
= ((Group
*)node
)->mTail
;
65 node
= &node
->mParent
->mNode
;
79 int32 nodeID
= msg
.geti();
80 gMissingNodeID
= nodeID
;
81 node
= World_GetNode(inWorld
, nodeID
);
86 Group
* Msg_GetGroup(World
*inWorld
, sc_msg_iter
& msg
)
88 Node
* node
= Msg_GetNode(inWorld
, msg
);
89 return node
&& node
->mIsGroup
? (Group
*)node
: 0;
92 Graph
* Msg_GetGraph(World
*inWorld
, sc_msg_iter
& msg
)
94 Node
* node
= Msg_GetNode(inWorld
, msg
);
95 return !node
|| node
->mIsGroup
? 0 : (Graph
*)node
;
98 SCErr
meth_none(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
99 SCErr
meth_none(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
104 SCErr
meth_sync(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
105 SCErr
meth_sync(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
107 CallSequencedCommand(SyncCmd
, inWorld
, inSize
, inData
, inReply
);
111 SCErr
meth_b_alloc(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
112 SCErr
meth_b_alloc(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
114 CallSequencedCommand(BufAllocCmd
, inWorld
, inSize
, inData
, inReply
);
118 SCErr
meth_b_free(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
119 SCErr
meth_b_free(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
121 CallSequencedCommand(BufFreeCmd
, inWorld
, inSize
, inData
, inReply
);
126 SCErr
meth_b_close(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
127 SCErr
meth_b_close(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
129 CallSequencedCommand(BufCloseCmd
, inWorld
, inSize
, inData
, inReply
);
134 SCErr
meth_b_allocRead(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
135 SCErr
meth_b_allocRead(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
137 CallSequencedCommand(BufAllocReadCmd
, inWorld
, inSize
, inData
, inReply
);
142 SCErr
meth_b_read(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
143 SCErr
meth_b_read(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
145 CallSequencedCommand(BufReadCmd
, inWorld
, inSize
, inData
, inReply
);
150 SCErr
meth_b_allocReadChannel(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
151 SCErr
meth_b_allocReadChannel(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
153 CallSequencedCommand(BufAllocReadChannelCmd
, inWorld
, inSize
, inData
, inReply
);
158 SCErr
meth_b_readChannel(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
159 SCErr
meth_b_readChannel(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
161 CallSequencedCommand(BufReadChannelCmd
, inWorld
, inSize
, inData
, inReply
);
166 SCErr
meth_b_write(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
167 SCErr
meth_b_write(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
169 CallSequencedCommand(BufWriteCmd
, inWorld
, inSize
, inData
, inReply
);
174 SCErr
meth_b_zero(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
175 SCErr
meth_b_zero(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
177 CallSequencedCommand(BufZeroCmd
, inWorld
, inSize
, inData
, inReply
);
182 SCErr
meth_u_cmd(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
183 SCErr
meth_u_cmd(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
185 return Unit_DoCmd(inWorld
, inSize
, inData
);
188 SCErr
meth_cmd(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
189 SCErr
meth_cmd(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
191 return PlugIn_DoCmd(inWorld
, inSize
, inData
, inReply
);
196 SCErr meth_n_cmd(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
197 SCErr meth_n_cmd(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
199 sc_msg_iter msg(inSize, inData);
200 Node *node = Msg_GetNode(inWorld, msg);
201 if (!node) return kSCErr_NodeNotFound;
203 char *args = msg.rdpos;
204 int arglen = msg.remain();
206 //!! (node->mDef->fNodeCmd)(node, arglen, args);
212 SCErr
meth_n_trace(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
213 SCErr
meth_n_trace(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
215 sc_msg_iter
msg(inSize
, inData
);
216 while (msg
.remain()) {
217 Node
*node
= Msg_GetNode(inWorld
, msg
);
218 if (!node
) return kSCErr_NodeNotFound
;
226 SCErr
meth_g_dumpTree(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
227 SCErr
meth_g_dumpTree(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
229 sc_msg_iter
msg(inSize
, inData
);
230 while (msg
.remain()) {
231 Group
*group
= Msg_GetGroup(inWorld
, msg
);
232 if (!group
) return kSCErr_GroupNotFound
;
233 int32 flag
= msg
.geti();
235 Group_DumpTreeAndControls(group
);
237 Group_DumpTree(group
);
244 //SCErr meth_g_queryTree(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
245 //SCErr meth_g_queryTree(World *inWorld, int inSize, char *inData, ReplyAddress* inReply)
247 // sc_msg_iter msg(inSize, inData);
248 // while (msg.remain()) {
249 // Group *group = Msg_GetGroup(inWorld, msg);
250 // if (!group) return kSCErr_GroupNotFound;
252 // // first count the total number of nodes to know how many tags the packet should have
253 // int numNodes = 1; // include this one
255 // Group_CountNodes(group, &numNodes);
257 // big_scpacket packet;
258 // packet.adds("/g_queryTree.reply");
259 // packet.maketags(numNodes * 3 + 1);
260 // packet.addtag(',');
262 // Group_QueryTree(group, &packet);
264 // if (packet.size()) {
265 // CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
268 // return kSCErr_None;
271 SCErr
meth_g_queryTree(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
272 SCErr
meth_g_queryTree(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
274 sc_msg_iter
msg(inSize
, inData
);
275 while (msg
.remain()) {
276 Group
*group
= Msg_GetGroup(inWorld
, msg
);
277 if (!group
) return kSCErr_GroupNotFound
;
279 packet
.adds("/g_queryTree.reply");
280 int32 flag
= msg
.geti();
282 // first count the total number of nodes to know how many tags the packet should have
283 int numNodes
= 1; // include this one
284 int numControlsAndDefs
= 0;
285 Group_CountNodeAndControlTags(group
, &numNodes
, &numControlsAndDefs
);
286 // nodeID and numChildren + numControlsAndDefs + controlFlag
287 packet
.maketags(numNodes
* 2 + numControlsAndDefs
+ 2);
290 packet
.addi(1); // include controls flag
291 Group_QueryTreeAndControls(group
, &packet
);
293 // first count the total number of nodes to know how many tags the packet should have
294 int numNodeTags
= 2; // include this one
295 Group_CountNodeTags(group
, &numNodeTags
);
296 packet
.maketags(numNodeTags
+ 2); // nodeID and numChildren
299 packet
.addi(0); // include controls flag
300 Group_QueryTree(group
, &packet
);
304 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
312 SCErr
meth_n_run(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
313 SCErr
meth_n_run(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
315 sc_msg_iter
msg(inSize
, inData
);
317 while (msg
.remain()) {
318 Node
*node
= Msg_GetNode(inWorld
, msg
);
319 if (!node
) return kSCErr_NodeNotFound
;
321 int32 run
= msg
.geti();
323 Node_SetRun(node
, run
);
329 SCErr
meth_n_map(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
330 SCErr
meth_n_map(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
332 sc_msg_iter
msg(inSize
, inData
);
333 Node
*node
= Msg_GetNode(inWorld
, msg
);
334 if (!node
) return kSCErr_NodeNotFound
;
336 while (msg
.remain() >= 8) {
337 if (msg
.nextTag('i') == 's') {
338 int32
* name
= msg
.gets4();
339 int bus
= msg
.geti();
340 Node_MapControl(node
, Hash(name
), name
, 0, bus
);
342 int32 index
= msg
.geti();
343 int32 bus
= msg
.geti();
344 Node_MapControl(node
, index
, bus
);
350 SCErr
meth_n_mapn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
351 SCErr
meth_n_mapn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
353 sc_msg_iter
msg(inSize
, inData
);
354 Node
*node
= Msg_GetNode(inWorld
, msg
);
355 if (!node
) return kSCErr_NodeNotFound
;
357 while (msg
.remain() >= 12) {
358 if (msg
.nextTag('i') == 's') {
359 int32
* name
= msg
.gets4();
360 int32 hash
= Hash(name
);
361 int bus
= msg
.geti();
363 for (int i
=0; i
<n
; ++i
) {
364 Node_MapControl(node
, hash
, name
, i
, bus
== -1 ? -1 : bus
+i
);
367 int32 index
= msg
.geti();
368 int32 bus
= msg
.geti();
370 for (int i
=0; i
<n
; ++i
) {
371 Node_MapControl(node
, index
+i
, bus
== -1 ? -1 : bus
+i
);
378 SCErr
meth_n_mapa(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
379 SCErr
meth_n_mapa(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
381 sc_msg_iter
msg(inSize
, inData
);
382 Node
*node
= Msg_GetNode(inWorld
, msg
);
383 if (!node
) return kSCErr_NodeNotFound
;
385 while (msg
.remain() >= 8) {
386 if (msg
.nextTag('i') == 's') {
387 int32
* name
= msg
.gets4();
388 int bus
= msg
.geti();
389 Node_MapAudioControl(node
, Hash(name
), name
, 0, bus
);
391 int32 index
= msg
.geti();
392 int32 bus
= msg
.geti();
393 Node_MapAudioControl(node
, index
, bus
);
399 SCErr
meth_n_mapan(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
400 SCErr
meth_n_mapan(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
402 sc_msg_iter
msg(inSize
, inData
);
403 Node
*node
= Msg_GetNode(inWorld
, msg
);
404 if (!node
) return kSCErr_NodeNotFound
;
406 while (msg
.remain() >= 12) {
407 if (msg
.nextTag('i') == 's') {
408 int32
* name
= msg
.gets4();
409 int32 hash
= Hash(name
);
410 int bus
= msg
.geti();
412 for (int i
=0; i
<n
; ++i
) {
413 Node_MapAudioControl(node
, hash
, name
, i
, bus
== -1 ? -1 : bus
+i
);
416 int32 index
= msg
.geti();
417 int32 bus
= msg
.geti();
419 for (int i
=0; i
<n
; ++i
) {
420 Node_MapAudioControl(node
, index
+i
, bus
== -1 ? -1 : bus
+i
);
427 SCErr
meth_n_set(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
428 SCErr
meth_n_set(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
430 sc_msg_iter
msg(inSize
, inData
);
431 Node
*node
= Msg_GetNode(inWorld
, msg
);
432 if (!node
) return kSCErr_NodeNotFound
;
433 while( msg
.remain()>=8) {
436 if (msg
.nextTag('i') == 's') {
437 int32
* name
= msg
.gets4();
438 int32 hash
= Hash(name
);
440 switch (msg
.nextTag('f') ) {
444 float32 value
= msg
.getf();
445 Node_SetControl(node
, hash
, name
, i
, value
);
451 const char* string
= msg
.gets();
452 if ( *string
== 'c') {
453 int bus
= sc_atoi(string
+1);
454 Node_MapControl(node
, hash
, name
, i
, bus
);
457 if ( *string
== 'a') {
458 int bus
= sc_atoi(string
+1);
459 Node_MapAudioControl(node
, hash
, name
, i
, bus
);
476 int32 index
= msg
.geti();
478 switch (msg
.nextTag('f') ) {
482 float32 value
= msg
.getf();
483 Node_SetControl(node
, index
+ i
, value
);
489 const char* string
= msg
.gets();
490 if ( *string
== 'c') {
491 int bus
= sc_atoi(string
+1);
492 Node_MapControl(node
, index
+ i
, bus
);
495 if ( *string
== 'a') {
496 int bus
= sc_atoi(string
+1);
497 Node_MapAudioControl(node
, index
+ i
, bus
);
519 // if (msg.nextTag('i') == 's') {
520 // int32* name = msg.gets4();
521 // int32 hash = Hash(name);
522 // if (msg.nextTag('f') == '[' ) {
527 // if (msg.nextTag('f') == 's' ) {
528 // const char* string = msg.gets();
529 // if ( *string == 'c') {
530 // int bus = sc_atoi(string+1);
531 // Node_MapControl(node, hash, name, i, bus);
534 // if (msg.nextTag('f') == ']' ) {
538 // float32 value = msg.getf();
539 // Node_SetControl(node, hash, name, i, value);
546 // int32 index = msg.geti();
547 // if (msg.nextTag('f') == '[' ) {
552 // if (msg.nextTag('f') == 's') {
553 // const char* string = msg.gets();
554 // if (*string == 'c') {
555 // int bus = sc_atoi(string+1);
556 // Node_MapControl(node, index + i, bus);
559 // if (msg.nextTag('f') == ']' ) {
563 // float32 value = msg.getf();
564 // Node_SetControl(node, index + i, value);
575 SCErr
meth_n_setn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
576 SCErr
meth_n_setn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
578 sc_msg_iter
msg(inSize
, inData
);
579 Node
*node
= Msg_GetNode(inWorld
, msg
);
580 if (!node
) return kSCErr_NodeNotFound
;
582 while (msg
.remain()) {
583 if (msg
.nextTag('i') == 's') {
584 int32
* name
= msg
.gets4();
585 int32 hash
= Hash(name
);
586 int32 n
= msg
.geti();
587 for (int i
=0; msg
.remain() && i
<n
; ++i
) {
588 if (msg
.nextTag('f') == 's') {
589 const char* string
= msg
.gets();
590 if (*string
== 'c') {
591 int bus
= sc_atoi(string
+1);
592 Node_MapControl(node
, hash
, name
, i
, bus
);
594 if (*string
== 'a') {
595 int bus
= sc_atoi(string
+1);
596 Node_MapAudioControl(node
, hash
, name
, i
, bus
);
600 float32 value
= msg
.getf();
601 Node_SetControl(node
, hash
, name
, i
, value
);
605 int32 index
= msg
.geti();
606 int32 n
= msg
.geti();
607 for (int i
=0; msg
.remain() && i
<n
; ++i
) {
608 if (msg
.nextTag('f') == 's') {
609 const char* string
= msg
.gets();
610 if (*string
== 'c') {
611 int bus
= sc_atoi(string
+1);
612 Node_MapControl(node
, index
+i
, bus
);
614 if (*string
== 'a') {
615 int bus
= sc_atoi(string
+1);
616 Node_MapAudioControl(node
, index
+i
, bus
);
619 float32 value
= msg
.getf();
620 Node_SetControl(node
, index
+i
, value
);
628 SCErr
meth_n_fill(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
629 SCErr
meth_n_fill(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
631 sc_msg_iter
msg(inSize
, inData
);
632 Node
*node
= Msg_GetNode(inWorld
, msg
);
633 if (!node
) return kSCErr_NodeNotFound
;
635 while (msg
.remain() >= 12)
637 if (msg
.nextTag('i') == 's') {
638 int32
* name
= msg
.gets4();
639 int32 hash
= Hash(name
);
640 int32 n
= msg
.geti();
641 float32 value
= msg
.getf();
643 for (int i
=0; i
<n
; ++i
) {
644 Node_SetControl(node
, hash
, name
, i
, value
);
647 if (msg
.nextTag('f') == 's') {
648 const char* string
= msg
.gets();
649 if (*string
== 'c') {
650 int bus
= sc_atoi(string
+1);
651 for (int i
=0; i
<n
; ++i
) {
652 Node_MapControl(node
, hash
, name
, i
, bus
+i
);
656 float32 value
= msg
.getf();
657 for (int i
=0; i
<n
; ++i
) {
658 Node_SetControl(node
, hash
, name
, i
, value
);
662 int32 index
= msg
.geti();
663 int32 n
= msg
.geti();
664 float32 value
= msg
.getf();
666 for (int i
=0; i
<n
; ++i
) {
667 Node_SetControl(node
, index
+i
, value
);
669 if (msg
.nextTag('f') == 's') {
670 const char* string
= msg
.gets();
671 if (*string
== 'c') {
672 int bus
= sc_atoi(string
+1);
673 for (int i
=0; i
<n
; ++i
) {
674 Node_MapControl(node
, index
+i
, bus
+i
);
678 float32 value
= msg
.getf();
679 for (int i
=0; i
<n
; ++i
) {
680 Node_SetControl(node
, index
+i
, value
);
690 SCErr
meth_n_query(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
691 SCErr
meth_n_query(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
693 sc_msg_iter
msg(inSize
, inData
);
695 while (msg
.remain()) {
696 Node
*node
= Msg_GetNode(inWorld
, msg
);
697 if (!node
) return kSCErr_NodeNotFound
;
699 Node_StateMsg(node
, kNode_Info
);
704 SCErr
meth_b_query(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
705 SCErr
meth_b_query(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
707 sc_msg_iter
msg(inSize
, inData
);
709 small_scpacket packet
;
711 int numbufs
= msg
.remain() >> 2;
712 packet
.adds("/b_info");
713 packet
.maketags(numbufs
* 4 + 1);
716 while (msg
.remain()) {
717 int bufindex
= msg
.geti();
718 SndBuf
* buf
= World_GetBuf(inWorld
, bufindex
);
724 packet
.addi(bufindex
);
725 packet
.addi(buf
->frames
);
726 packet
.addi(buf
->channels
);
727 packet
.addf(buf
->samplerate
);
731 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
739 SCErr
meth_d_load(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
740 SCErr
meth_d_load(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
742 CallSequencedCommand(LoadSynthDefCmd
, inWorld
, inSize
, inData
, inReply
);
748 SCErr
meth_d_recv(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
749 SCErr
meth_d_recv(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
751 CallSequencedCommand(RecvSynthDefCmd
, inWorld
, inSize
, inData
, inReply
);
757 SCErr
meth_d_loadDir(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
758 SCErr
meth_d_loadDir(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
760 CallSequencedCommand(LoadSynthDefDirCmd
, inWorld
, inSize
, inData
, inReply
);
765 SCErr
meth_d_freeAll(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
766 SCErr
meth_d_freeAll(World
*inWorld
, int /*inSize*/, char * /*inData*/, ReplyAddress
* /*inReply*/)
768 World_FreeAllGraphDefs(inWorld
);
772 SCErr
meth_d_free(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
773 SCErr
meth_d_free(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
775 sc_msg_iter
msg(inSize
, inData
);
776 while (msg
.remain()) {
777 int32
* defname
= msg
.gets4();
778 if (!defname
) return kSCErr_SynthDefNotFound
;
779 GraphDef_Remove(inWorld
, defname
);
785 SCErr
meth_s_new(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
786 SCErr
meth_s_new(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
789 sc_msg_iter
msg(inSize
, inData
);
790 int32
*defname
= msg
.gets4();
791 if (!defname
) return kSCErr_WrongArgType
;
793 int32 nodeID
= msg
.geti();
794 int32 addAction
= msg
.geti();
796 GraphDef
*def
= World_GetGraphDef(inWorld
, defname
);
798 scprintf("*** ERROR: SynthDef %s not found\n", (char*)defname
);
799 return kSCErr_SynthDefNotFound
;
805 Group
*group
= Msg_GetGroup(inWorld
, msg
);
806 if (!group
) return kSCErr_GroupNotFound
;
807 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,true);//true for normal args
809 if (!graph
) return kSCErr_Failed
;
810 Group_AddHead(group
, &graph
->mNode
);
813 Group
*group
= Msg_GetGroup(inWorld
, msg
);
814 if (!group
) return kSCErr_GroupNotFound
;
815 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,true);
817 Group_AddTail(group
, &graph
->mNode
);
820 Node
*beforeThisNode
= Msg_GetNode(inWorld
, msg
);
821 if (!beforeThisNode
) return kSCErr_NodeNotFound
;
822 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,true);
824 Node_AddBefore(&graph
->mNode
, beforeThisNode
);
827 Node
*afterThisNode
= Msg_GetNode(inWorld
, msg
);
828 if (!afterThisNode
) return kSCErr_NodeNotFound
;
829 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,true);
831 Node_AddAfter(&graph
->mNode
, afterThisNode
);
834 Node
*replaceThisNode
= Msg_GetNode(inWorld
, msg
);
835 if (!replaceThisNode
) return kSCErr_NodeNotFound
;
836 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,true);
838 Node_Replace(&graph
->mNode
, replaceThisNode
);
840 default: return kSCErr_Failed
;
842 Node_StateMsg(&graph
->mNode
, kNode_Go
);
846 SCErr
meth_s_newargs(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
847 SCErr
meth_s_newargs(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
850 sc_msg_iter
msg(inSize
, inData
);
851 int32
*defname
= msg
.gets4();
852 if (!defname
) return kSCErr_WrongArgType
;
854 int32 nodeID
= msg
.geti();
855 int32 addAction
= msg
.geti();
857 GraphDef
*def
= World_GetGraphDef(inWorld
, defname
);
859 scprintf("*** ERROR: SynthDef %s not found\n", (char*)defname
);
860 return kSCErr_SynthDefNotFound
;
866 Group
*group
= Msg_GetGroup(inWorld
, msg
);
867 if (!group
) return kSCErr_GroupNotFound
;
868 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,false);//false for setn type args
870 if (!graph
) return kSCErr_Failed
;
871 Group_AddHead(group
, &graph
->mNode
);
874 Group
*group
= Msg_GetGroup(inWorld
, msg
);
875 if (!group
) return kSCErr_GroupNotFound
;
876 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,false);
878 Group_AddTail(group
, &graph
->mNode
);
881 Node
*beforeThisNode
= Msg_GetNode(inWorld
, msg
);
882 if (!beforeThisNode
) return kSCErr_NodeNotFound
;
883 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,false);
885 Node_AddBefore(&graph
->mNode
, beforeThisNode
);
888 Node
*afterThisNode
= Msg_GetNode(inWorld
, msg
);
889 if (!afterThisNode
) return kSCErr_NodeNotFound
;
890 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,false);
892 Node_AddAfter(&graph
->mNode
, afterThisNode
);
895 Node
*replaceThisNode
= Msg_GetNode(inWorld
, msg
);
896 if (!replaceThisNode
) return kSCErr_NodeNotFound
;
897 err
= Graph_New(inWorld
, def
, nodeID
, &msg
, &graph
,false);
899 Node_Replace(&graph
->mNode
, replaceThisNode
);
901 default: return kSCErr_Failed
;
903 Node_StateMsg(&graph
->mNode
, kNode_Go
);
907 SCErr
meth_g_new(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
908 SCErr
meth_g_new(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
912 sc_msg_iter
msg(inSize
, inData
);
913 while (msg
.remain()) {
914 int32 newGroupID
= msg
.geti();
915 int32 addAction
= msg
.geti();
920 Group
*group
= Msg_GetGroup(inWorld
, msg
);
921 if (!group
) return kSCErr_GroupNotFound
;
922 err
= Group_New(inWorld
, newGroupID
, &newGroup
);
924 if (err
== kSCErr_DuplicateNodeID
) {
925 newGroup
= World_GetGroup(inWorld
, newGroupID
);
926 if (!newGroup
|| !newGroup
->mNode
.mParent
|| newGroup
->mNode
.mParent
!= group
)
930 Group_AddHead(group
, &newGroup
->mNode
);
934 Group
*group
= Msg_GetGroup(inWorld
, msg
);
935 if (!group
) return kSCErr_GroupNotFound
;
936 err
= Group_New(inWorld
, newGroupID
, &newGroup
);
938 if (err
== kSCErr_DuplicateNodeID
) {
939 newGroup
= World_GetGroup(inWorld
, newGroupID
);
940 if (!newGroup
|| !newGroup
->mNode
.mParent
|| newGroup
->mNode
.mParent
!= group
)
944 Group_AddTail(group
, &newGroup
->mNode
);
948 Node
*beforeThisNode
= Msg_GetNode(inWorld
, msg
);
949 if (!beforeThisNode
) return kSCErr_TargetNodeNotFound
;
950 err
= Group_New(inWorld
, newGroupID
, &newGroup
);
952 if (err
== kSCErr_DuplicateNodeID
) {
953 newGroup
= World_GetGroup(inWorld
, newGroupID
);
954 if (!newGroup
|| !newGroup
->mNode
.mParent
|| newGroup
->mNode
.mParent
->mNode
.mID
!= beforeThisNode
->mParent
->mNode
.mID
)
958 Node_AddBefore(&newGroup
->mNode
, beforeThisNode
);
962 Node
*afterThisNode
= Msg_GetNode(inWorld
, msg
);
963 if (!afterThisNode
) return kSCErr_TargetNodeNotFound
;
964 err
= Group_New(inWorld
, newGroupID
, &newGroup
);
966 if (err
== kSCErr_DuplicateNodeID
) {
967 newGroup
= World_GetGroup(inWorld
, newGroupID
);
968 if (!newGroup
|| !newGroup
->mNode
.mParent
|| newGroup
->mNode
.mParent
->mNode
.mID
!= afterThisNode
->mParent
->mNode
.mID
)
972 Node_AddAfter(&newGroup
->mNode
, afterThisNode
);
976 Node
*replaceThisNode
= Msg_GetNode(inWorld
, msg
);
977 if (!replaceThisNode
) return kSCErr_TargetNodeNotFound
;
978 err
= Group_New(inWorld
, newGroupID
, &newGroup
);
980 Node_Replace(&newGroup
->mNode
, replaceThisNode
);
982 default: return kSCErr_Failed
;
985 Node_StateMsg(&newGroup
->mNode
, kNode_Go
);
991 SCErr
meth_p_new(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
992 SCErr
meth_p_new(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
994 /* we emulate the concept of parallel groups by using sequential groups */
995 return meth_g_new(inWorld
, inSize
, inData
, inReply
);
998 SCErr
meth_n_free(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
999 SCErr
meth_n_free(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1001 sc_msg_iter
msg(inSize
, inData
);
1003 while (msg
.remain()) {
1004 Node
*node
= Msg_GetNode(inWorld
, msg
);
1005 if (!node
) return kSCErr_NodeNotFound
;
1013 SCErr
meth_n_before(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1014 SCErr
meth_n_before(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1016 sc_msg_iter
msg(inSize
, inData
);
1019 Node
*prevTarget
= 0;
1020 while (msg
.remain()) {
1021 Node
*node
= Msg_GetNode(inWorld
, msg
);
1022 Node
*target
= Msg_GetNode(inWorld
, msg
);
1024 if (!node
|| !target
) continue; // tolerate failure
1026 if (prevNode
&& prevNode
!= node
)
1028 // move the last pair that succeeded
1029 Node_Remove(prevNode
);
1030 Node_AddBefore(prevNode
, prevTarget
);
1031 Node_StateMsg(prevNode
, kNode_Move
);
1035 prevTarget
= target
;
1037 if (prevNode
&& prevNode
!= prevTarget
)
1039 // move the last pair that succeeded
1040 Node_Remove(prevNode
);
1041 Node_AddBefore(prevNode
, prevTarget
);
1042 Node_StateMsg(prevNode
, kNode_Move
);
1048 SCErr
meth_n_after(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1049 SCErr
meth_n_after(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1051 sc_msg_iter
msg(inSize
, inData
);
1054 Node
*prevTarget
= 0;
1055 while (msg
.remain()) {
1056 Node
*node
= Msg_GetNode(inWorld
, msg
);
1057 Node
*target
= Msg_GetNode(inWorld
, msg
);
1059 if (!node
|| !target
) continue; // tolerate failure
1061 if (prevNode
&& prevNode
!= node
)
1063 // move the last pair that succeeded
1064 Node_Remove(prevNode
);
1065 Node_AddAfter(prevNode
, prevTarget
);
1066 Node_StateMsg(prevNode
, kNode_Move
);
1070 prevTarget
= target
;
1074 // move the last pair that succeeded
1075 Node_Remove(prevNode
);
1076 Node_AddAfter(prevNode
, prevTarget
);
1077 Node_StateMsg(prevNode
, kNode_Move
);
1083 SCErr
meth_n_order(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1084 SCErr
meth_n_order(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1090 sc_msg_iter
msg(inSize
, inData
);
1091 int32 addAction
= msg
.geti();
1093 // place the first node in the list based on target and addAction
1094 switch (addAction
) {
1096 Group
*group
= Msg_GetGroup(inWorld
, msg
);
1097 if (!group
) return kSCErr_GroupNotFound
;
1098 while(!node
&& msg
.remain()) {
1099 node
= Msg_GetNode(inWorld
, msg
);
1100 if(!node
) scprintf("Warning Node not found\n");
1102 if (!node
) return kSCErr_NodeNotFound
;
1104 Group
*prevGroup
= node
->mParent
;
1108 Group_AddHead(group
, node
);
1110 if (group
!= prevGroup
) {
1111 Node_StateMsg(node
, kNode_Move
);
1118 Group
*group
= Msg_GetGroup(inWorld
, msg
);
1119 if (!group
) return kSCErr_GroupNotFound
;
1120 while(!node
&& msg
.remain()) {
1121 node
= Msg_GetNode(inWorld
, msg
);
1122 if(!node
) scprintf("Warning Node not found\n");
1124 if (!node
) return kSCErr_NodeNotFound
;
1126 Group
*prevGroup
= node
->mParent
;
1130 Group_AddTail(group
, node
);
1132 if (group
!= prevGroup
) {
1133 Node_StateMsg(node
, kNode_Move
);
1140 Node
*beforeNode
= Msg_GetNode(inWorld
, msg
);
1141 if (!beforeNode
) return kSCErr_TargetNodeNotFound
;
1142 while(!node
&& msg
.remain()) {
1143 node
= Msg_GetNode(inWorld
, msg
);
1144 if(!node
) scprintf("Warning Node not found\n");
1146 if (!node
) return kSCErr_NodeNotFound
;
1150 Node_AddBefore(node
, beforeNode
);
1151 Node_StateMsg(node
, kNode_Move
);
1156 Node
*afterNode
= Msg_GetNode(inWorld
, msg
);
1157 if (!afterNode
) return kSCErr_TargetNodeNotFound
;
1158 while(!node
&& msg
.remain()) {
1159 node
= Msg_GetNode(inWorld
, msg
);
1160 if(!node
) scprintf("Warning Node not found\n");
1162 if (!node
) return kSCErr_NodeNotFound
;
1166 Node_AddAfter(node
, afterNode
);
1167 Node_StateMsg(node
, kNode_Move
);
1171 default: return kSCErr_Failed
;
1174 // now iterate through in order
1175 while (msg
.remain()) {
1176 node
= Msg_GetNode(inWorld
, msg
);
1178 scprintf("Warning Node not found\n");
1182 Node_AddAfter(node
, prevNode
);
1183 Node_StateMsg(node
, kNode_Move
);
1191 SCErr
meth_g_head(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1192 SCErr
meth_g_head(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1194 sc_msg_iter
msg(inSize
, inData
);
1195 while (msg
.remain()) {
1196 Group
*group
= Msg_GetGroup(inWorld
, msg
);
1197 if (!group
) return kSCErr_GroupNotFound
;
1199 Node
*node
= Msg_GetNode(inWorld
, msg
);
1200 if (!node
) return kSCErr_NodeNotFound
;
1202 Group
*prevGroup
= node
->mParent
;
1206 Group_AddHead(group
, node
);
1208 if (group
!= prevGroup
) {
1209 Node_StateMsg(node
, kNode_Move
);
1215 SCErr
meth_g_tail(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1216 SCErr
meth_g_tail(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1218 sc_msg_iter
msg(inSize
, inData
);
1219 while (msg
.remain()) {
1220 Group
*group
= Msg_GetGroup(inWorld
, msg
);
1221 if (!group
) return kSCErr_GroupNotFound
;
1223 Node
*node
= Msg_GetNode(inWorld
, msg
);
1224 if (!node
) return kSCErr_NodeNotFound
;
1226 //Group *prevGroup = node->mParent;
1229 Group_AddTail(group
, node
);
1231 //if (group != prevGroup) {
1232 Node_StateMsg(node
, kNode_Move
);
1238 SCErr
meth_g_insert(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1239 SCErr
meth_g_insert(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1241 sc_msg_iter
msg(inSize
, inData
);
1242 while (msg
.remain()) {
1243 Group
*group
= Msg_GetGroup(inWorld
, msg
);
1244 if (!group
) return kSCErr_GroupNotFound
;
1246 Node
*node
= Msg_GetNode(inWorld
, msg
);
1247 if (!node
) return kSCErr_NodeNotFound
;
1249 Group
*prevGroup
= node
->mParent
;
1251 int index
= msg
.geti();
1254 Group_Insert(group
, node
, index
);
1256 if (group
!= prevGroup
) {
1257 Node_StateMsg(node
, kNode_Move
);
1263 SCErr
meth_g_freeAll(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1264 SCErr
meth_g_freeAll(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1266 sc_msg_iter
msg(inSize
, inData
);
1267 while (msg
.remain()) {
1268 Group
*group
= Msg_GetGroup(inWorld
, msg
);
1269 if (!group
) return kSCErr_GroupNotFound
;
1271 Group_DeleteAll(group
);
1276 SCErr
meth_g_deepFree(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1277 SCErr
meth_g_deepFree(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1279 sc_msg_iter
msg(inSize
, inData
);
1280 while (msg
.remain()) {
1281 Group
*group
= Msg_GetGroup(inWorld
, msg
);
1282 if (!group
) return kSCErr_GroupNotFound
;
1284 Group_DeepFreeGraphs(group
);
1291 SCErr
meth_status(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1292 SCErr
meth_status(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
1294 CallSequencedCommand(AudioStatusCmd
, inWorld
, inSize
, inData
, inReply
);
1298 SCErr
meth_quit(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1299 SCErr
meth_quit(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
1301 CallSequencedCommand(AudioQuitCmd
, inWorld
, inSize
, inData
, inReply
);
1305 SCErr
meth_clearSched(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1306 SCErr
meth_clearSched(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
1308 if(inWorld
->mRealTime
){
1309 inWorld
->hw
->mAudioDriver
->ClearSched();
1314 SCErr
meth_dumpOSC(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1315 SCErr
meth_dumpOSC(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
1317 sc_msg_iter
msg(inSize
, inData
);
1318 inWorld
->mDumpOSC
= msg
.geti();
1322 SCErr
meth_b_set(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1323 SCErr
meth_b_set(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1325 sc_msg_iter
msg(inSize
, inData
);
1326 int bufindex
= msg
.geti();
1327 SndBuf
* buf
= World_GetBuf(inWorld
, bufindex
);
1328 if (!buf
) return kSCErr_Failed
;
1330 float *data
= buf
->data
;
1331 uint32 numSamples
= buf
->samples
;
1333 while (msg
.remain() >= 8)
1335 uint32 sampleIndex
= msg
.geti();
1336 float32 value
= msg
.getf();
1337 if (sampleIndex
< numSamples
)
1339 data
[sampleIndex
] = value
;
1340 } else return kSCErr_IndexOutOfRange
;
1346 SCErr
meth_b_setn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1347 SCErr
meth_b_setn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1349 sc_msg_iter
msg(inSize
, inData
);
1350 int bufindex
= msg
.geti();
1351 SndBuf
* buf
= World_GetBuf(inWorld
, bufindex
);
1352 if (!buf
) return kSCErr_Failed
;
1354 float *data
= buf
->data
;
1355 int numSamples
= buf
->samples
;
1357 while (msg
.remain()) {
1358 int32 start
= msg
.geti();
1359 int32 n
= msg
.geti();
1360 int32 end
= start
+n
-1;
1362 if (end
< 0 || start
>= numSamples
) continue;
1364 start
= sc_clip(start
, 0, numSamples
-1);
1365 end
= sc_clip(end
, 0, numSamples
-1);
1367 for (int i
=start
; msg
.remain() && i
<=end
; ++i
) {
1368 float32 value
= msg
.getf();
1377 SCErr
meth_b_fill(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1378 SCErr
meth_b_fill(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1380 sc_msg_iter
msg(inSize
, inData
);
1381 int bufindex
= msg
.geti();
1382 SndBuf
* buf
= World_GetBuf(inWorld
, bufindex
);
1383 if (!buf
) return kSCErr_Failed
;
1385 float *data
= buf
->data
;
1386 int numSamples
= buf
->samples
;
1388 while (msg
.remain() >= 12)
1390 int32 start
= msg
.geti();
1391 int32 n
= msg
.geti();
1392 float32 value
= msg
.getf();
1393 int32 end
= start
+n
-1;
1395 if (end
< 0 || start
>= numSamples
) continue;
1397 start
= sc_clip(start
, 0, numSamples
-1);
1398 end
= sc_clip(end
, 0, numSamples
-1);
1400 for (int i
=start
; i
<=end
; ++i
) data
[i
] = value
;
1406 SCErr
meth_b_gen(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1407 SCErr
meth_b_gen(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
1409 CallSequencedCommand(BufGenCmd
, inWorld
, inSize
, inData
, inReply
);
1415 SCErr
meth_c_set(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1416 SCErr
meth_c_set(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1418 sc_msg_iter
msg(inSize
, inData
);
1420 float *data
= inWorld
->mControlBus
;
1421 int32
*touched
= inWorld
->mControlBusTouched
;
1422 int32 bufCounter
= inWorld
->mBufCounter
;
1423 uint32 maxIndex
= inWorld
->mNumControlBusChannels
;
1425 while (msg
.remain() >= 8)
1427 uint32 index
= msg
.geti();
1428 float32 value
= msg
.getf();
1429 if (index
< maxIndex
)
1431 data
[index
] = value
;
1432 touched
[index
] = bufCounter
;
1433 } else return kSCErr_IndexOutOfRange
;
1439 SCErr
meth_c_setn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1440 SCErr
meth_c_setn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1442 sc_msg_iter
msg(inSize
, inData
);
1444 float *data
= inWorld
->mControlBus
;
1445 int32
*touched
= inWorld
->mControlBusTouched
;
1446 int32 bufCounter
= inWorld
->mBufCounter
;
1447 int maxIndex
= inWorld
->mNumControlBusChannels
;
1449 while (msg
.remain()) {
1450 int32 start
= msg
.geti();
1451 int32 n
= msg
.geti();
1452 int32 end
= start
+n
-1;
1454 if (start
< 0 || end
>= maxIndex
|| start
> end
)
1455 return kSCErr_IndexOutOfRange
;
1457 for (int i
=start
; msg
.remain() && i
<=end
; ++i
) {
1458 float32 value
= msg
.getf();
1460 touched
[i
] = bufCounter
;
1468 SCErr
meth_c_get(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1469 SCErr
meth_c_get(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
1471 sc_msg_iter
msg(inSize
, inData
);
1473 float *data
= inWorld
->mControlBus
;
1474 uint32 maxIndex
= inWorld
->mNumControlBusChannels
;
1476 int numheads
= msg
.remain() >> 2;
1478 big_scpacket packet
;
1479 packet
.adds("/c_set");
1480 packet
.maketags(numheads
* 2 + 1);
1483 while (msg
.remain() >= 4)
1485 uint32 index
= msg
.geti();
1486 if (index
>= maxIndex
)
1487 return kSCErr_IndexOutOfRange
;
1491 packet
.addf(data
[index
]);
1494 if (packet
.size()) {
1495 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
1501 SCErr
meth_c_getn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1502 SCErr
meth_c_getn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
1504 sc_msg_iter
msg(inSize
, inData
);
1506 float *data
= inWorld
->mControlBus
;
1507 int maxIndex
= inWorld
->mNumControlBusChannels
;
1509 // figure out how many tags to allocate
1510 int numcontrols
= 0;
1511 int numheads
= msg
.remain() >> 3;
1513 while (msg
.remain()) {
1514 msg
.geti(); // skip start
1515 int32 n
= msg
.geti();
1519 big_scpacket packet
;
1520 packet
.adds("/c_setn");
1521 packet
.maketags(numheads
* 2 + numcontrols
+ 1);
1524 // start over at beginning of message
1525 msg
.init(inSize
, inData
);
1527 while (msg
.remain()) {
1528 int32 start
= msg
.geti();
1529 int32 n
= msg
.geti();
1530 int32 end
= start
+n
-1;
1532 if (start
< 0 || end
>= maxIndex
|| start
> end
)
1533 return kSCErr_IndexOutOfRange
;
1540 for (int i
=start
; i
<=end
; ++i
) {
1542 packet
.addf(data
[i
]);
1546 if (packet
.size()) {
1547 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
1554 SCErr
meth_c_fill(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1555 SCErr
meth_c_fill(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1557 sc_msg_iter
msg(inSize
, inData
);
1559 float *data
= inWorld
->mControlBus
;
1560 int32
*touched
= inWorld
->mControlBusTouched
;
1561 int32 bufCounter
= inWorld
->mBufCounter
;
1562 int maxIndex
= inWorld
->mNumControlBusChannels
;
1564 while (msg
.remain() >= 12)
1566 int32 start
= msg
.geti();
1567 int32 n
= msg
.geti();
1568 float32 value
= msg
.getf();
1569 int32 end
= start
+n
-1;
1571 if (end
< 0 || start
>= maxIndex
) continue;
1573 start
= sc_clip(start
, 0, maxIndex
-1);
1574 end
= sc_clip(end
, 0, maxIndex
-1);
1576 for (int i
=start
; i
<=end
; ++i
) {
1578 touched
[i
] = bufCounter
;
1587 SCErr
meth_b_get(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1588 SCErr
meth_b_get(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
1590 sc_msg_iter
msg(inSize
, inData
);
1591 int bufindex
= msg
.geti();
1592 SndBuf
* buf
= World_GetBuf(inWorld
, bufindex
);
1593 if (!buf
) return kSCErr_Failed
;
1595 float *data
= buf
->data
;
1596 uint32 maxIndex
= buf
->samples
;
1598 int numheads
= msg
.remain() >> 2;
1600 big_scpacket packet
;
1601 packet
.adds("/b_set");
1602 packet
.maketags(numheads
* 2 + 2);
1605 packet
.addi(bufindex
);
1607 while (msg
.remain() >= 4)
1609 uint32 index
= msg
.geti();
1610 if (index
>= maxIndex
)
1611 return kSCErr_IndexOutOfRange
;
1615 packet
.addf(data
[index
]);
1618 if (packet
.size()) {
1619 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
1625 SCErr
meth_b_getn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1626 SCErr
meth_b_getn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
1628 sc_msg_iter
msg(inSize
, inData
);
1629 int bufindex
= msg
.geti();
1630 SndBuf
* buf
= World_GetBuf(inWorld
, bufindex
);
1631 if (!buf
) return kSCErr_Failed
;
1633 float *data
= buf
->data
;
1634 int32 maxIndex
= buf
->samples
;
1636 // figure out how many tags to allocate
1637 int numcontrols
= 0;
1638 int numheads
= msg
.remain() >> 3;
1640 while (msg
.remain()) {
1641 msg
.geti(); // skip start
1642 int32 n
= msg
.geti();
1646 big_scpacket packet
;
1647 packet
.adds("/b_setn");
1648 packet
.maketags(numheads
* 2 + numcontrols
+ 2);
1651 // start over at beginning of message
1652 msg
.init(inSize
, inData
);
1653 msg
.geti(); // skip buf index
1656 packet
.addi(bufindex
);
1658 while (msg
.remain()) {
1659 int32 start
= msg
.geti();
1660 int32 n
= msg
.geti();
1661 int32 end
= start
+n
-1;
1663 if (start
< 0 || end
>= maxIndex
|| start
> end
)
1664 return kSCErr_IndexOutOfRange
;
1671 for (int i
=start
; i
<=end
; ++i
) {
1673 packet
.addf(data
[i
]);
1677 if (packet
.size()) {
1678 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
1685 SCErr
meth_s_get(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1686 SCErr
meth_s_get(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
1688 sc_msg_iter
msg(inSize
, inData
);
1690 Graph
*graph
= Msg_GetGraph(inWorld
, msg
);
1691 if (!graph
) return kSCErr_NodeNotFound
;
1693 int numheads
= msg
.tags
? strlen(msg
.tags
) - 1 : msg
.remain() >> 2;
1695 big_scpacket packet
;
1696 packet
.adds("/n_set");
1697 packet
.maketags(numheads
* 2 + 2);
1700 packet
.addi(graph
->mNode
.mID
);
1702 while (msg
.remain() >= 4) {
1703 if (msg
.nextTag('i') == 's') {
1704 int32
* name
= msg
.gets4();
1705 int32 hash
= Hash(name
);
1706 float32 value
= 0.f
;
1707 Graph_GetControl(graph
, hash
, name
, 0, value
);
1710 packet
.adds((char*)name
);
1713 int32 index
= msg
.geti();
1714 float32 value
= 0.f
;
1715 Graph_GetControl(graph
, index
, value
);
1723 if (packet
.size()) {
1724 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
1730 SCErr
meth_s_getn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1731 SCErr
meth_s_getn(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
1733 sc_msg_iter
msg(inSize
, inData
);
1735 Graph
*graph
= Msg_GetGraph(inWorld
, msg
);
1736 if (!graph
) return kSCErr_NodeNotFound
;
1738 // figure out how many tags to allocate
1739 int numcontrols
= 0;
1740 int numheads
= msg
.tags
? strlen(msg
.tags
) - 1 >> 1 : msg
.remain() >> 3;
1742 while (msg
.remain()) {
1743 msg
.geti(); // skip start
1744 int32 n
= msg
.geti();
1748 big_scpacket packet
;
1749 packet
.adds("/n_setn");
1750 packet
.maketags(numheads
* 2 + numcontrols
+ 2);
1753 // start over at beginning of message
1754 msg
.init(inSize
, inData
);
1755 msg
.geti(); // skip buf index
1758 packet
.addi(graph
->mNode
.mID
);
1760 while (msg
.remain()) {
1761 if (msg
.nextTag('i') == 's') {
1762 int32
* name
= msg
.gets4();
1763 int32 hash
= Hash(name
);
1764 int32 n
= msg
.geti();
1767 packet
.adds((char*)name
);
1769 for (int i
=0; i
<n
; ++i
) {
1770 float32 value
= 0.f
;
1771 Graph_GetControl(graph
, hash
, name
, i
, value
);
1776 int32 index
= msg
.geti();
1777 int32 n
= msg
.geti();
1782 for (int i
=0; i
<n
; ++i
) {
1783 float32 value
= 0.f
;
1784 Graph_GetControl(graph
, index
+i
, value
);
1791 if (packet
.size()) {
1792 CallSequencedCommand(SendReplyCmd
, inWorld
, packet
.size(), packet
.data(), inReply
);
1800 SCErr
meth_s_noid(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1801 SCErr
meth_s_noid(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* inReply
)
1803 sc_msg_iter
msg(inSize
, inData
);
1804 while (msg
.remain()) {
1806 Graph
*graph
= Msg_GetGraph(inWorld
, msg
);
1807 if (!graph
) continue;
1809 Graph_RemoveID(inWorld
, graph
);
1816 SCErr
meth_notify(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1817 SCErr
meth_notify(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
1819 CallSequencedCommand(NotifyCmd
, inWorld
, inSize
, inData
, inReply
);
1823 SCErr
meth_error(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
);
1824 SCErr
meth_error(World
*inWorld
, int inSize
, char *inData
, ReplyAddress
* /*inReply*/)
1826 sc_msg_iter
msg(inSize
, inData
);
1827 int mode
= msg
.geti();
1829 // inWorld->mLocalErrorNotification = mode;
1830 // // if non-zero, new state should be saved permanently
1831 // if(mode) { inWorld->mErrorNotification = mode; };
1833 // -1 = bundle off, -2 = bundle on, 0 = permanent off, 1 = permanent on
1835 case -1: inWorld
->mLocalErrorNotification
+= 1;
1837 case -2: inWorld
->mLocalErrorNotification
-= 1;
1839 case 0: inWorld
->mErrorNotification
= 0;
1841 case 1: inWorld
->mErrorNotification
= 1;
1846 #define NEW_COMMAND(name) NewCommand(#name, cmd_##name, meth_##name)
1848 void initMiscCommands();
1849 void initMiscCommands()
1854 NEW_COMMAND(notify
);
1855 NEW_COMMAND(status
);
1857 NEW_COMMAND(clearSched
);
1859 NEW_COMMAND(d_recv
);
1860 NEW_COMMAND(d_load
);
1861 NEW_COMMAND(d_loadDir
);
1862 NEW_COMMAND(d_freeAll
);
1863 NEW_COMMAND(d_free
);
1866 NEW_COMMAND(s_newargs
);
1868 NEW_COMMAND(n_trace
);
1869 NEW_COMMAND(n_free
);
1875 //NEW_COMMAND(n_cmd);
1877 NEW_COMMAND(n_mapn
);
1878 NEW_COMMAND(n_mapa
);
1879 NEW_COMMAND(n_mapan
);
1881 NEW_COMMAND(n_setn
);
1882 NEW_COMMAND(n_fill
);
1884 NEW_COMMAND(n_before
);
1885 NEW_COMMAND(n_after
);
1886 NEW_COMMAND(n_order
);
1889 NEW_COMMAND(g_head
);
1890 NEW_COMMAND(g_tail
);
1891 NEW_COMMAND(g_freeAll
);
1892 NEW_COMMAND(g_deepFree
);
1896 NEW_COMMAND(b_alloc
);
1897 NEW_COMMAND(b_allocRead
);
1898 NEW_COMMAND(b_allocReadChannel
);
1900 NEW_COMMAND(b_read
);
1901 NEW_COMMAND(b_readChannel
);
1902 NEW_COMMAND(b_write
);
1904 NEW_COMMAND(b_free
);
1905 NEW_COMMAND(b_close
);
1907 NEW_COMMAND(b_zero
);
1909 NEW_COMMAND(b_setn
);
1910 NEW_COMMAND(b_fill
);
1914 NEW_COMMAND(c_setn
);
1915 NEW_COMMAND(c_fill
);
1917 NEW_COMMAND(dumpOSC
);
1920 NEW_COMMAND(c_getn
);
1922 NEW_COMMAND(b_getn
);
1924 NEW_COMMAND(s_getn
);
1926 NEW_COMMAND(n_query
);
1927 NEW_COMMAND(b_query
);
1929 NEW_COMMAND(s_noid
);
1931 NEW_COMMAND(g_dumpTree
);
1932 NEW_COMMAND(g_queryTree
);