Fix scvim regsitry file for updated filename (thanks Carlo Capocasa)
[supercollider.git] / server / scsynth / SC_MiscCmds.cpp
blobd676135d0cb783f04b4de0d769c0a15b32333fe4
1 /*
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
22 #include "SC_Lib.h"
23 #include "SC_CoreAudio.h"
24 #include "SC_HiddenWorld.h"
25 #include "SC_Graph.h"
26 #include "SC_GraphDef.h"
27 #include "SC_Group.h"
28 #include "SC_UnitDef.h"
29 #include <stdexcept>
30 #include "SC_Lib_Cintf.h"
31 #include "SC_SequencedCommand.h"
32 #include <new>
33 #include "SC_Prototypes.h"
34 #include "scsynthsend.h"
36 extern int gMissingNodeID;
38 // returns number of bytes in an OSC string.
39 int OSCstrlen(char *strin);
41 Node* Msg_GetNode(World *inWorld, sc_msg_iter& msg)
43 Node *node;
44 if (msg.nextTag('i') == 's')
46 const char* loc = msg.gets();
47 int32 nodeID = msg.geti();
48 gMissingNodeID = nodeID;
49 node = World_GetNode(inWorld, nodeID);
50 while (*loc)
52 if (!node) return 0;
53 switch (*loc)
55 case 'h' :
56 if (!node->mIsGroup) return 0;
57 node = ((Group*)node)->mHead;
58 break;
59 case 't' :
60 if (!node->mIsGroup) return 0;
61 node = ((Group*)node)->mTail;
62 break;
63 case 'u' :
64 node = &node->mParent->mNode;
65 break;
66 case 'p' :
67 node = node->mPrev;
68 break;
69 case 'n' :
70 node = node->mNext;
71 break;
73 loc++;
76 else
78 int32 nodeID = msg.geti();
79 gMissingNodeID = nodeID;
80 node = World_GetNode(inWorld, nodeID);
82 return node;
85 Group* Msg_GetGroup(World *inWorld, sc_msg_iter& msg)
87 Node* node = Msg_GetNode(inWorld, msg);
88 return node && node->mIsGroup ? (Group*)node : 0;
91 Graph* Msg_GetGraph(World *inWorld, sc_msg_iter& msg)
93 Node* node = Msg_GetNode(inWorld, msg);
94 return !node || node->mIsGroup ? 0 : (Graph*)node;
97 SCErr meth_none(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
98 SCErr meth_none(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
100 return kSCErr_None;
103 SCErr meth_sync(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
104 SCErr meth_sync(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
106 CallSequencedCommand(SyncCmd, inWorld, inSize, inData, inReply);
107 return kSCErr_None;
110 SCErr meth_b_alloc(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
111 SCErr meth_b_alloc(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
113 CallSequencedCommand(BufAllocCmd, inWorld, inSize, inData, inReply);
114 return kSCErr_None;
117 SCErr meth_b_free(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
118 SCErr meth_b_free(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
120 CallSequencedCommand(BufFreeCmd, inWorld, inSize, inData, inReply);
122 return kSCErr_None;
125 SCErr meth_b_close(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
126 SCErr meth_b_close(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
128 CallSequencedCommand(BufCloseCmd, inWorld, inSize, inData, inReply);
130 return kSCErr_None;
133 SCErr meth_b_allocRead(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
134 SCErr meth_b_allocRead(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
136 CallSequencedCommand(BufAllocReadCmd, inWorld, inSize, inData, inReply);
138 return kSCErr_None;
141 SCErr meth_b_read(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
142 SCErr meth_b_read(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
144 CallSequencedCommand(BufReadCmd, inWorld, inSize, inData, inReply);
146 return kSCErr_None;
149 SCErr meth_b_allocReadChannel(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
150 SCErr meth_b_allocReadChannel(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
152 CallSequencedCommand(BufAllocReadChannelCmd, inWorld, inSize, inData, inReply);
154 return kSCErr_None;
157 SCErr meth_b_readChannel(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
158 SCErr meth_b_readChannel(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
160 CallSequencedCommand(BufReadChannelCmd, inWorld, inSize, inData, inReply);
162 return kSCErr_None;
165 SCErr meth_b_write(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
166 SCErr meth_b_write(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
168 CallSequencedCommand(BufWriteCmd, inWorld, inSize, inData, inReply);
170 return kSCErr_None;
173 SCErr meth_b_zero(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
174 SCErr meth_b_zero(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
176 CallSequencedCommand(BufZeroCmd, inWorld, inSize, inData, inReply);
177 return kSCErr_None;
181 SCErr meth_u_cmd(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
182 SCErr meth_u_cmd(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
184 return Unit_DoCmd(inWorld, inSize, inData);
187 SCErr meth_cmd(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
188 SCErr meth_cmd(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
190 return PlugIn_DoCmd(inWorld, inSize, inData, inReply);
195 SCErr meth_n_cmd(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
196 SCErr meth_n_cmd(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
198 sc_msg_iter msg(inSize, inData);
199 Node *node = Msg_GetNode(inWorld, msg);
200 if (!node) return kSCErr_NodeNotFound;
202 char *args = msg.rdpos;
203 int arglen = msg.remain();
205 //!! (node->mDef->fNodeCmd)(node, arglen, args);
207 return kSCErr_None;
211 SCErr meth_n_trace(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
212 SCErr meth_n_trace(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
214 sc_msg_iter msg(inSize, inData);
215 while (msg.remain()) {
216 Node *node = Msg_GetNode(inWorld, msg);
217 if (!node) return kSCErr_NodeNotFound;
219 Node_Trace(node);
222 return kSCErr_None;
225 SCErr meth_g_dumpTree(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
226 SCErr meth_g_dumpTree(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
228 sc_msg_iter msg(inSize, inData);
229 while (msg.remain()) {
230 Group *group = Msg_GetGroup(inWorld, msg);
231 if (!group) return kSCErr_GroupNotFound;
232 int32 flag = msg.geti();
233 if(flag) {
234 Group_DumpTreeAndControls(group);
235 } else {
236 Group_DumpTree(group);
240 return kSCErr_None;
243 //SCErr meth_g_queryTree(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
244 //SCErr meth_g_queryTree(World *inWorld, int inSize, char *inData, ReplyAddress* inReply)
246 // sc_msg_iter msg(inSize, inData);
247 // while (msg.remain()) {
248 // Group *group = Msg_GetGroup(inWorld, msg);
249 // if (!group) return kSCErr_GroupNotFound;
251 // // first count the total number of nodes to know how many tags the packet should have
252 // int numNodes = 1; // include this one
254 // Group_CountNodes(group, &numNodes);
256 // big_scpacket packet;
257 // packet.adds("/g_queryTree.reply");
258 // packet.maketags(numNodes * 3 + 1);
259 // packet.addtag(',');
261 // Group_QueryTree(group, &packet);
263 // if (packet.size()) {
264 // CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
265 // }
266 // }
267 // return kSCErr_None;
270 SCErr meth_g_queryTree(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
271 SCErr meth_g_queryTree(World *inWorld, int inSize, char *inData, ReplyAddress* inReply)
273 sc_msg_iter msg(inSize, inData);
274 while (msg.remain()) {
275 Group *group = Msg_GetGroup(inWorld, msg);
276 if (!group) return kSCErr_GroupNotFound;
277 big_scpacket packet;
278 packet.adds("/g_queryTree.reply");
279 int32 flag = msg.geti();
280 if(flag) {
281 // first count the total number of nodes to know how many tags the packet should have
282 int numNodes = 1; // include this one
283 int numControlsAndDefs = 0;
284 Group_CountNodeAndControlTags(group, &numNodes, &numControlsAndDefs);
285 // nodeID and numChildren + numControlsAndDefs + controlFlag
286 packet.maketags(numNodes * 2 + numControlsAndDefs + 2);
287 packet.addtag(',');
288 packet.addtag('i');
289 packet.addi(1); // include controls flag
290 Group_QueryTreeAndControls(group, &packet);
291 } else {
292 // first count the total number of nodes to know how many tags the packet should have
293 int numNodeTags = 2; // include this one
294 Group_CountNodeTags(group, &numNodeTags);
295 packet.maketags(numNodeTags + 2); // nodeID and numChildren
296 packet.addtag(',');
297 packet.addtag('i');
298 packet.addi(0); // include controls flag
299 Group_QueryTree(group, &packet);
302 if (packet.size()) {
303 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
306 return kSCErr_None;
311 SCErr meth_n_run(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
312 SCErr meth_n_run(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
314 sc_msg_iter msg(inSize, inData);
316 while (msg.remain()) {
317 Node *node = Msg_GetNode(inWorld, msg);
318 if (!node) return kSCErr_NodeNotFound;
320 int32 run = msg.geti();
322 Node_SetRun(node, run);
325 return kSCErr_None;
328 SCErr meth_n_map(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
329 SCErr meth_n_map(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
331 sc_msg_iter msg(inSize, inData);
332 Node *node = Msg_GetNode(inWorld, msg);
333 if (!node) return kSCErr_NodeNotFound;
335 while (msg.remain() >= 8) {
336 if (msg.nextTag('i') == 's') {
337 int32* name = msg.gets4();
338 int bus = msg.geti();
339 Node_MapControl(node, Hash(name), name, 0, bus);
340 } else {
341 int32 index = msg.geti();
342 int32 bus = msg.geti();
343 Node_MapControl(node, index, bus);
346 return kSCErr_None;
349 SCErr meth_n_mapn(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
350 SCErr meth_n_mapn(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
352 sc_msg_iter msg(inSize, inData);
353 Node *node = Msg_GetNode(inWorld, msg);
354 if (!node) return kSCErr_NodeNotFound;
356 while (msg.remain() >= 12) {
357 if (msg.nextTag('i') == 's') {
358 int32* name = msg.gets4();
359 int32 hash = Hash(name);
360 int bus = msg.geti();
361 int n = msg.geti();
362 for (int i=0; i<n; ++i) {
363 Node_MapControl(node, hash, name, i, bus == -1 ? -1 : bus+i);
365 } else {
366 int32 index = msg.geti();
367 int32 bus = msg.geti();
368 int n = msg.geti();
369 for (int i=0; i<n; ++i) {
370 Node_MapControl(node, index+i, bus == -1 ? -1 : bus+i);
374 return kSCErr_None;
377 SCErr meth_n_mapa(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
378 SCErr meth_n_mapa(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
380 sc_msg_iter msg(inSize, inData);
381 Node *node = Msg_GetNode(inWorld, msg);
382 if (!node) return kSCErr_NodeNotFound;
384 while (msg.remain() >= 8) {
385 if (msg.nextTag('i') == 's') {
386 int32* name = msg.gets4();
387 int bus = msg.geti();
388 Node_MapAudioControl(node, Hash(name), name, 0, bus);
389 } else {
390 int32 index = msg.geti();
391 int32 bus = msg.geti();
392 Node_MapAudioControl(node, index, bus);
395 return kSCErr_None;
398 SCErr meth_n_mapan(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
399 SCErr meth_n_mapan(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
401 sc_msg_iter msg(inSize, inData);
402 Node *node = Msg_GetNode(inWorld, msg);
403 if (!node) return kSCErr_NodeNotFound;
405 while (msg.remain() >= 12) {
406 if (msg.nextTag('i') == 's') {
407 int32* name = msg.gets4();
408 int32 hash = Hash(name);
409 int bus = msg.geti();
410 int n = msg.geti();
411 for (int i=0; i<n; ++i) {
412 Node_MapAudioControl(node, hash, name, i, bus == -1 ? -1 : bus+i);
414 } else {
415 int32 index = msg.geti();
416 int32 bus = msg.geti();
417 int n = msg.geti();
418 for (int i=0; i<n; ++i) {
419 Node_MapAudioControl(node, index+i, bus == -1 ? -1 : bus+i);
423 return kSCErr_None;
426 SCErr meth_n_set(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
427 SCErr meth_n_set(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
429 sc_msg_iter msg(inSize, inData);
430 Node *node = Msg_GetNode(inWorld, msg);
431 if (!node) return kSCErr_NodeNotFound;
432 while( msg.remain()>=8) {
433 int i = 0;
434 int loop = 0;
435 if (msg.nextTag('i') == 's') {
436 int32* name = msg.gets4();
437 int32 hash = Hash(name);
438 do {
439 switch (msg.nextTag('f') ) {
440 case 'f' :
441 case 'i' :
443 float32 value = msg.getf();
444 Node_SetControl(node, hash, name, i, value);
445 ++i;
446 break;
448 case 's' :
450 const char* string = msg.gets();
451 if ( *string == 'c') {
452 int bus = sc_atoi(string+1);
453 Node_MapControl(node, hash, name, i, bus);
454 ++i;
456 if ( *string == 'a') {
457 int bus = sc_atoi(string+1);
458 Node_MapAudioControl(node, hash, name, i, bus);
459 ++i;
461 break;
463 case ']':
464 msg.count++;
465 loop--;
466 break;
467 case '[':
468 msg.count++;
469 loop++;
470 break;
473 while (loop);
474 } else {
475 int32 index = msg.geti();
476 do {
477 switch (msg.nextTag('f') ) {
478 case 'f' :
479 case 'i' :
481 float32 value = msg.getf();
482 Node_SetControl(node, index + i, value);
483 ++i;
484 break;
486 case 's' :
488 const char* string = msg.gets();
489 if ( *string == 'c') {
490 int bus = sc_atoi(string+1);
491 Node_MapControl(node, index + i, bus);
492 ++i;
494 if ( *string == 'a') {
495 int bus = sc_atoi(string+1);
496 Node_MapAudioControl(node, index + i, bus);
497 ++i;
499 break;
501 case ']':
502 msg.count++;
503 loop--;
504 break;
505 case '[':
506 msg.count++;
507 loop++;
508 break;
511 while (loop);
516 // int i = 0;
517 // int loop = 0;
518 // if (msg.nextTag('i') == 's') {
519 // int32* name = msg.gets4();
520 // int32 hash = Hash(name);
521 // if (msg.nextTag('f') == '[' ) {
522 // msg.count++;
523 // loop = 1;
524 // }
525 // do {
526 // if (msg.nextTag('f') == 's' ) {
527 // const char* string = msg.gets();
528 // if ( *string == 'c') {
529 // int bus = sc_atoi(string+1);
530 // Node_MapControl(node, hash, name, i, bus);
531 // }
532 // } else {
533 // if (msg.nextTag('f') == ']' ) {
534 // msg.count++;
535 // loop = 0;
536 // } else {
537 // float32 value = msg.getf();
538 // Node_SetControl(node, hash, name, i, value);
539 // }
540 // }
541 // ++i;
542 // }
543 // while (loop);
544 // } else {
545 // int32 index = msg.geti();
546 // if (msg.nextTag('f') == '[' ) {
547 // msg.count++;
548 // loop = 1;
549 // }
550 // do {
551 // if (msg.nextTag('f') == 's') {
552 // const char* string = msg.gets();
553 // if (*string == 'c') {
554 // int bus = sc_atoi(string+1);
555 // Node_MapControl(node, index + i, bus);
556 // }
557 // } else {
558 // if (msg.nextTag('f') == ']' ) {
559 // msg.count++;
560 // loop = 0;
561 // } else {
562 // float32 value = msg.getf();
563 // Node_SetControl(node, index + i, value);
564 // }
565 // }
566 // ++i;
567 // }
568 // while (loop);
569 // }
570 // }
571 return kSCErr_None;
574 SCErr meth_n_setn(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
575 SCErr meth_n_setn(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
577 sc_msg_iter msg(inSize, inData);
578 Node *node = Msg_GetNode(inWorld, msg);
579 if (!node) return kSCErr_NodeNotFound;
581 while (msg.remain()) {
582 if (msg.nextTag('i') == 's') {
583 int32* name = msg.gets4();
584 int32 hash = Hash(name);
585 int32 n = msg.geti();
586 for (int i=0; msg.remain() && i<n; ++i) {
587 if (msg.nextTag('f') == 's') {
588 const char* string = msg.gets();
589 if (*string == 'c') {
590 int bus = sc_atoi(string+1);
591 Node_MapControl(node, hash, name, i, bus);
593 if (*string == 'a') {
594 int bus = sc_atoi(string+1);
595 Node_MapAudioControl(node, hash, name, i, bus);
598 } else {
599 float32 value = msg.getf();
600 Node_SetControl(node, hash, name, i, value);
603 } else {
604 int32 index = msg.geti();
605 int32 n = msg.geti();
606 for (int i=0; msg.remain() && i<n; ++i) {
607 if (msg.nextTag('f') == 's') {
608 const char* string = msg.gets();
609 if (*string == 'c') {
610 int bus = sc_atoi(string+1);
611 Node_MapControl(node, index+i, bus);
613 if (*string == 'a') {
614 int bus = sc_atoi(string+1);
615 Node_MapAudioControl(node, index+i, bus);
617 } else {
618 float32 value = msg.getf();
619 Node_SetControl(node, index+i, value);
624 return kSCErr_None;
627 SCErr meth_n_fill(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
628 SCErr meth_n_fill(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
630 sc_msg_iter msg(inSize, inData);
631 Node *node = Msg_GetNode(inWorld, msg);
632 if (!node) return kSCErr_NodeNotFound;
634 while (msg.remain() >= 12)
636 if (msg.nextTag('i') == 's') {
637 int32* name = msg.gets4();
638 int32 hash = Hash(name);
639 int32 n = msg.geti();
640 float32 value = msg.getf();
642 for (int i=0; i<n; ++i) {
643 Node_SetControl(node, hash, name, i, value);
646 if (msg.nextTag('f') == 's') {
647 const char* string = msg.gets();
648 if (*string == 'c') {
649 int bus = sc_atoi(string+1);
650 for (int i=0; i<n; ++i) {
651 Node_MapControl(node, hash, name, i, bus+i);
654 } else {
655 float32 value = msg.getf();
656 for (int i=0; i<n; ++i) {
657 Node_SetControl(node, hash, name, i, value);
660 } else {
661 int32 index = msg.geti();
662 int32 n = msg.geti();
663 float32 value = msg.getf();
665 for (int i=0; i<n; ++i) {
666 Node_SetControl(node, index+i, value);
668 if (msg.nextTag('f') == 's') {
669 const char* string = msg.gets();
670 if (*string == 'c') {
671 int bus = sc_atoi(string+1);
672 for (int i=0; i<n; ++i) {
673 Node_MapControl(node, index+i, bus+i);
676 } else {
677 float32 value = msg.getf();
678 for (int i=0; i<n; ++i) {
679 Node_SetControl(node, index+i, value);
685 return kSCErr_None;
689 SCErr meth_n_query(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
690 SCErr meth_n_query(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
692 sc_msg_iter msg(inSize, inData);
694 while (msg.remain()) {
695 Node *node = Msg_GetNode(inWorld, msg);
696 if (!node) return kSCErr_NodeNotFound;
698 Node_StateMsg(node, kNode_Info);
700 return kSCErr_None;
703 SCErr meth_b_query(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
704 SCErr meth_b_query(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
706 sc_msg_iter msg(inSize, inData);
708 small_scpacket packet;
710 int numbufs = msg.remain() >> 2;
711 packet.adds("/b_info");
712 packet.maketags(numbufs * 4 + 1);
713 packet.addtag(',');
715 while (msg.remain()) {
716 int bufindex = msg.geti();
717 SndBuf* buf = World_GetBuf(inWorld, bufindex);
719 packet.addtag('i');
720 packet.addtag('i');
721 packet.addtag('i');
722 packet.addtag('f');
723 packet.addi(bufindex);
724 packet.addi(buf->frames);
725 packet.addi(buf->channels);
726 packet.addf(buf->samplerate);
729 if (packet.size()) {
730 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
733 return kSCErr_None;
738 SCErr meth_d_load(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
739 SCErr meth_d_load(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
741 CallSequencedCommand(LoadSynthDefCmd, inWorld, inSize, inData, inReply);
743 return kSCErr_None;
747 SCErr meth_d_recv(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
748 SCErr meth_d_recv(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
750 CallSequencedCommand(RecvSynthDefCmd, inWorld, inSize, inData, inReply);
752 return kSCErr_None;
756 SCErr meth_d_loadDir(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
757 SCErr meth_d_loadDir(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
759 CallSequencedCommand(LoadSynthDefDirCmd, inWorld, inSize, inData, inReply);
761 return kSCErr_None;
764 SCErr meth_d_freeAll(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
765 SCErr meth_d_freeAll(World *inWorld, int /*inSize*/, char * /*inData*/, ReplyAddress* /*inReply*/)
767 World_FreeAllGraphDefs(inWorld);
768 return kSCErr_None;
771 SCErr meth_d_free(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
772 SCErr meth_d_free(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
774 sc_msg_iter msg(inSize, inData);
775 while (msg.remain()) {
776 int32* defname = msg.gets4();
777 if (!defname) return kSCErr_SynthDefNotFound;
778 GraphDef_Remove(inWorld, defname);
780 return kSCErr_None;
784 SCErr meth_s_new(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
785 SCErr meth_s_new(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
787 SCErr err;
788 sc_msg_iter msg(inSize, inData);
789 int32 *defname = msg.gets4();
790 if (!defname) return kSCErr_WrongArgType;
792 int32 nodeID = msg.geti();
793 int32 addAction = msg.geti();
795 GraphDef *def = World_GetGraphDef(inWorld, defname);
796 if (!def) {
797 scprintf("*** ERROR: SynthDef %s not found\n", (char*)defname);
798 return kSCErr_SynthDefNotFound;
801 Graph *graph = 0;
802 switch (addAction) {
803 case 0 : {
804 Group *group = Msg_GetGroup(inWorld, msg);
805 if (!group) return kSCErr_GroupNotFound;
806 err = Graph_New(inWorld, def, nodeID, &msg, &graph,true);//true for normal args
807 if (err) return err;
808 if (!graph) return kSCErr_Failed;
809 Group_AddHead(group, &graph->mNode);
810 } break;
811 case 1 : {
812 Group *group = Msg_GetGroup(inWorld, msg);
813 if (!group) return kSCErr_GroupNotFound;
814 err = Graph_New(inWorld, def, nodeID, &msg, &graph,true);
815 if (err) return err;
816 Group_AddTail(group, &graph->mNode);
817 } break;
818 case 2 : {
819 Node *beforeThisNode = Msg_GetNode(inWorld, msg);
820 if (!beforeThisNode) return kSCErr_NodeNotFound;
821 err = Graph_New(inWorld, def, nodeID, &msg, &graph,true);
822 if (err) return err;
823 Node_AddBefore(&graph->mNode, beforeThisNode);
824 } break;
825 case 3 : {
826 Node *afterThisNode = Msg_GetNode(inWorld, msg);
827 if (!afterThisNode) return kSCErr_NodeNotFound;
828 err = Graph_New(inWorld, def, nodeID, &msg, &graph,true);
829 if (err) return err;
830 Node_AddAfter(&graph->mNode, afterThisNode);
831 } break;
832 case 4 : {
833 Node *replaceThisNode = Msg_GetNode(inWorld, msg);
834 if (!replaceThisNode) return kSCErr_NodeNotFound;
835 err = Graph_New(inWorld, def, nodeID, &msg, &graph,true);
836 if (err) return err;
837 Node_Replace(&graph->mNode, replaceThisNode);
838 } break;
839 default: return kSCErr_Failed;
841 Node_StateMsg(&graph->mNode, kNode_Go);
842 return kSCErr_None;
845 SCErr meth_s_newargs(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
846 SCErr meth_s_newargs(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
848 SCErr err;
849 sc_msg_iter msg(inSize, inData);
850 int32 *defname = msg.gets4();
851 if (!defname) return kSCErr_WrongArgType;
853 int32 nodeID = msg.geti();
854 int32 addAction = msg.geti();
856 GraphDef *def = World_GetGraphDef(inWorld, defname);
857 if (!def) {
858 scprintf("*** ERROR: SynthDef %s not found\n", (char*)defname);
859 return kSCErr_SynthDefNotFound;
862 Graph *graph = 0;
863 switch (addAction) {
864 case 0 : {
865 Group *group = Msg_GetGroup(inWorld, msg);
866 if (!group) return kSCErr_GroupNotFound;
867 err = Graph_New(inWorld, def, nodeID, &msg, &graph,false);//false for setn type args
868 if (err) return err;
869 if (!graph) return kSCErr_Failed;
870 Group_AddHead(group, &graph->mNode);
871 } break;
872 case 1 : {
873 Group *group = Msg_GetGroup(inWorld, msg);
874 if (!group) return kSCErr_GroupNotFound;
875 err = Graph_New(inWorld, def, nodeID, &msg, &graph,false);
876 if (err) return err;
877 Group_AddTail(group, &graph->mNode);
878 } break;
879 case 2 : {
880 Node *beforeThisNode = Msg_GetNode(inWorld, msg);
881 if (!beforeThisNode) return kSCErr_NodeNotFound;
882 err = Graph_New(inWorld, def, nodeID, &msg, &graph,false);
883 if (err) return err;
884 Node_AddBefore(&graph->mNode, beforeThisNode);
885 } break;
886 case 3 : {
887 Node *afterThisNode = Msg_GetNode(inWorld, msg);
888 if (!afterThisNode) return kSCErr_NodeNotFound;
889 err = Graph_New(inWorld, def, nodeID, &msg, &graph,false);
890 if (err) return err;
891 Node_AddAfter(&graph->mNode, afterThisNode);
892 } break;
893 case 4 : {
894 Node *replaceThisNode = Msg_GetNode(inWorld, msg);
895 if (!replaceThisNode) return kSCErr_NodeNotFound;
896 err = Graph_New(inWorld, def, nodeID, &msg, &graph,false);
897 if (err) return err;
898 Node_Replace(&graph->mNode, replaceThisNode);
899 } break;
900 default: return kSCErr_Failed;
902 Node_StateMsg(&graph->mNode, kNode_Go);
903 return kSCErr_None;
906 SCErr meth_g_new(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
907 SCErr meth_g_new(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
909 SCErr err;
911 sc_msg_iter msg(inSize, inData);
912 while (msg.remain()) {
913 int32 newGroupID = msg.geti();
914 int32 addAction = msg.geti();
916 Group *newGroup = 0;
917 switch (addAction) {
918 case 0 : {
919 Group *group = Msg_GetGroup(inWorld, msg);
920 if (!group) return kSCErr_GroupNotFound;
921 err = Group_New(inWorld, newGroupID, &newGroup);
922 if (err) {
923 if (err == kSCErr_DuplicateNodeID) {
924 newGroup = World_GetGroup(inWorld, newGroupID);
925 if (!newGroup || !newGroup->mNode.mParent || newGroup->mNode.mParent != group)
926 return err;
927 } else return err;
928 } else {
929 Group_AddHead(group, &newGroup->mNode);
931 } break;
932 case 1 : {
933 Group *group = Msg_GetGroup(inWorld, msg);
934 if (!group) return kSCErr_GroupNotFound;
935 err = Group_New(inWorld, newGroupID, &newGroup);
936 if (err) {
937 if (err == kSCErr_DuplicateNodeID) {
938 newGroup = World_GetGroup(inWorld, newGroupID);
939 if (!newGroup || !newGroup->mNode.mParent || newGroup->mNode.mParent != group)
940 return err;
941 } else return err;
942 } else {
943 Group_AddTail(group, &newGroup->mNode);
945 } break;
946 case 2 : {
947 Node *beforeThisNode = Msg_GetNode(inWorld, msg);
948 if (!beforeThisNode) return kSCErr_TargetNodeNotFound;
949 err = Group_New(inWorld, newGroupID, &newGroup);
950 if (err) {
951 if (err == kSCErr_DuplicateNodeID) {
952 newGroup = World_GetGroup(inWorld, newGroupID);
953 if (!newGroup || !newGroup->mNode.mParent || newGroup->mNode.mParent->mNode.mID != beforeThisNode->mParent->mNode.mID)
954 return err;
955 } else return err;
956 } else {
957 Node_AddBefore(&newGroup->mNode, beforeThisNode);
959 } break;
960 case 3 : {
961 Node *afterThisNode = Msg_GetNode(inWorld, msg);
962 if (!afterThisNode) return kSCErr_TargetNodeNotFound;
963 err = Group_New(inWorld, newGroupID, &newGroup);
964 if (err) {
965 if (err == kSCErr_DuplicateNodeID) {
966 newGroup = World_GetGroup(inWorld, newGroupID);
967 if (!newGroup || !newGroup->mNode.mParent || newGroup->mNode.mParent->mNode.mID != afterThisNode->mParent->mNode.mID)
968 return err;
969 } else return err;
970 } else {
971 Node_AddAfter(&newGroup->mNode, afterThisNode);
973 } break;
974 case 4 : {
975 Node *replaceThisNode = Msg_GetNode(inWorld, msg);
976 if (!replaceThisNode) return kSCErr_TargetNodeNotFound;
977 err = Group_New(inWorld, newGroupID, &newGroup);
978 if (err) return err;
979 Node_Replace(&newGroup->mNode, replaceThisNode);
980 } break;
981 default: return kSCErr_Failed;
984 Node_StateMsg(&newGroup->mNode, kNode_Go);
987 return kSCErr_None;
990 SCErr meth_p_new(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
991 SCErr meth_p_new(World *inWorld, int inSize, char *inData, ReplyAddress* inReply)
993 /* we emulate the concept of parallel groups by using sequential groups */
994 return meth_g_new(inWorld, inSize, inData, inReply);
997 SCErr meth_n_free(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
998 SCErr meth_n_free(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
1000 sc_msg_iter msg(inSize, inData);
1002 while (msg.remain()) {
1003 Node *node = Msg_GetNode(inWorld, msg);
1004 if (!node) return kSCErr_NodeNotFound;
1006 Node_Delete(node);
1009 return kSCErr_None;
1012 SCErr meth_n_before(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
1013 SCErr meth_n_before(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
1015 sc_msg_iter msg(inSize, inData);
1017 Node *prevNode = 0;
1018 Node *prevTarget = 0;
1019 while (msg.remain()) {
1020 Node *node = Msg_GetNode(inWorld, msg);
1021 Node *target = Msg_GetNode(inWorld, msg);
1023 if (!node || !target) continue; // tolerate failure
1025 if (prevNode && prevNode != node)
1027 // move the last pair that succeeded
1028 Node_Remove(prevNode);
1029 Node_AddBefore(prevNode, prevTarget);
1030 Node_StateMsg(prevNode, kNode_Move);
1033 prevNode = node;
1034 prevTarget = target;
1036 if (prevNode && prevNode != prevTarget)
1038 // move the last pair that succeeded
1039 Node_Remove(prevNode);
1040 Node_AddBefore(prevNode, prevTarget);
1041 Node_StateMsg(prevNode, kNode_Move);
1044 return kSCErr_None;
1047 SCErr meth_n_after(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
1048 SCErr meth_n_after(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
1050 sc_msg_iter msg(inSize, inData);
1052 Node *prevNode = 0;
1053 Node *prevTarget = 0;
1054 while (msg.remain()) {
1055 Node *node = Msg_GetNode(inWorld, msg);
1056 Node *target = Msg_GetNode(inWorld, msg);
1058 if (!node || !target) continue; // tolerate failure
1060 if (prevNode && prevNode != node)
1062 // move the last pair that succeeded
1063 Node_Remove(prevNode);
1064 Node_AddAfter(prevNode, prevTarget);
1065 Node_StateMsg(prevNode, kNode_Move);
1068 prevNode = node;
1069 prevTarget = target;
1071 if (prevNode)
1073 // move the last pair that succeeded
1074 Node_Remove(prevNode);
1075 Node_AddAfter(prevNode, prevTarget);
1076 Node_StateMsg(prevNode, kNode_Move);
1079 return kSCErr_None;
1082 SCErr meth_n_order(World *inWorld, int inSize, char *inData, ReplyAddress *inReply);
1083 SCErr meth_n_order(World *inWorld, int inSize, char *inData, ReplyAddress* /*inReply*/)
1085 SCErr err;
1087 Node *prevNode = 0;
1088 Node *node = 0;
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) {
1095 case 0 : {
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;
1106 Node_Remove(node);
1108 Group_AddHead(group, node);
1110 if (group != prevGroup) {
1111 Node_StateMsg(node, kNode_Move);
1114 prevNode = node;
1116 } break;
1117 case 1 : {
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;
1128 Node_Remove(node);
1130 Group_AddTail(group, node);
1132 if (group != prevGroup) {
1133 Node_StateMsg(node, kNode_Move);
1136 prevNode = node;
1138 } break;
1139 case 2 : {
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;
1149 Node_Remove(node);
1150 Node_AddBefore(node, beforeNode);
1151 Node_StateMsg(node, kNode_Move);
1153 prevNode = node;
1154 } break;
1155 case 3 : {
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;
1165 Node_Remove(node);
1166 Node_AddAfter(node, afterNode);
1167 Node_StateMsg(node, kNode_Move);
1169 prevNode = node;
1170 } break;
1171 default: return kSCErr_Failed;
1174 // now iterate through in order
1175 while (msg.remain()) {
1176 node = Msg_GetNode(inWorld, msg);
1177 if(!node) {
1178 scprintf("Warning Node not found\n");
1179 continue;
1181 Node_Remove(node);
1182 Node_AddAfter(node, prevNode);
1183 Node_StateMsg(node, kNode_Move);
1185 prevNode = node;
1188 return kSCErr_None;
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;
1204 Node_Remove(node);
1206 Group_AddHead(group, node);
1208 if (group != prevGroup) {
1209 Node_StateMsg(node, kNode_Move);
1212 return kSCErr_None;
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;
1228 Node_Remove(node);
1229 Group_AddTail(group, node);
1231 //if (group != prevGroup) {
1232 Node_StateMsg(node, kNode_Move);
1235 return kSCErr_None;
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();
1253 Node_Remove(node);
1254 Group_Insert(group, node, index);
1256 if (group != prevGroup) {
1257 Node_StateMsg(node, kNode_Move);
1260 return kSCErr_None;
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);
1273 return kSCErr_None;
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);
1286 return kSCErr_None;
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);
1295 return kSCErr_None;
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);
1302 return kSCErr_None;
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();
1311 return kSCErr_None;
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();
1319 return kSCErr_None;
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;
1343 return kSCErr_None;
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();
1369 data[i] = value;
1373 return kSCErr_None;
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;
1403 return kSCErr_None;
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);
1411 return kSCErr_None;
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;
1436 return kSCErr_None;
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();
1459 data[i] = value;
1460 touched[i] = bufCounter;
1464 return kSCErr_None;
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);
1481 packet.addtag(',');
1483 while (msg.remain() >= 4)
1485 uint32 index = msg.geti();
1486 if (index >= maxIndex)
1487 return kSCErr_IndexOutOfRange;
1488 packet.addtag('i');
1489 packet.addtag('f');
1490 packet.addi(index);
1491 packet.addf(data[index]);
1494 if (packet.size()) {
1495 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
1498 return kSCErr_None;
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();
1516 numcontrols += n;
1519 big_scpacket packet;
1520 packet.adds("/c_setn");
1521 packet.maketags(numheads * 2 + numcontrols + 1);
1522 packet.addtag(',');
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;
1535 packet.addtag('i');
1536 packet.addtag('i');
1537 packet.addi(start);
1538 packet.addi(n);
1540 for (int i=start; i<=end; ++i) {
1541 packet.addtag('f');
1542 packet.addf(data[i]);
1546 if (packet.size()) {
1547 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
1550 return kSCErr_None;
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) {
1577 data[i] = value;
1578 touched[i] = bufCounter;
1582 return kSCErr_None;
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);
1603 packet.addtag(',');
1604 packet.addtag('i');
1605 packet.addi(bufindex);
1607 while (msg.remain() >= 4)
1609 uint32 index = msg.geti();
1610 if (index >= maxIndex)
1611 return kSCErr_IndexOutOfRange;
1612 packet.addtag('i');
1613 packet.addtag('f');
1614 packet.addi(index);
1615 packet.addf(data[index]);
1618 if (packet.size()) {
1619 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
1622 return kSCErr_None;
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();
1643 numcontrols += n;
1646 big_scpacket packet;
1647 packet.adds("/b_setn");
1648 packet.maketags(numheads * 2 + numcontrols + 2);
1649 packet.addtag(',');
1651 // start over at beginning of message
1652 msg.init(inSize, inData);
1653 msg.geti(); // skip buf index
1655 packet.addtag('i');
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;
1666 packet.addtag('i');
1667 packet.addtag('i');
1668 packet.addi(start);
1669 packet.addi(n);
1671 for (int i=start; i<=end; ++i) {
1672 packet.addtag('f');
1673 packet.addf(data[i]);
1677 if (packet.size()) {
1678 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
1681 return kSCErr_None;
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);
1698 packet.addtag(',');
1699 packet.addtag('i');
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);
1708 packet.addtag('s');
1709 packet.addtag('f');
1710 packet.adds((char*)name);
1711 packet.addf(value);
1712 } else {
1713 int32 index = msg.geti();
1714 float32 value = 0.f;
1715 Graph_GetControl(graph, index, value);
1716 packet.addtag('i');
1717 packet.addtag('f');
1718 packet.addi(index);
1719 packet.addf(value);
1723 if (packet.size()) {
1724 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
1727 return kSCErr_None;
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();
1745 numcontrols += n;
1748 big_scpacket packet;
1749 packet.adds("/n_setn");
1750 packet.maketags(numheads * 2 + numcontrols + 2);
1751 packet.addtag(',');
1753 // start over at beginning of message
1754 msg.init(inSize, inData);
1755 msg.geti(); // skip buf index
1757 packet.addtag('i');
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();
1765 packet.addtag('s');
1766 packet.addtag('i');
1767 packet.adds((char*)name);
1768 packet.addi(n);
1769 for (int i=0; i<n; ++i) {
1770 float32 value = 0.f;
1771 Graph_GetControl(graph, hash, name, i, value);
1772 packet.addtag('f');
1773 packet.addf(value);
1775 } else {
1776 int32 index = msg.geti();
1777 int32 n = msg.geti();
1778 packet.addtag('i');
1779 packet.addtag('i');
1780 packet.addi(index);
1781 packet.addi(n);
1782 for (int i=0; i<n; ++i) {
1783 float32 value = 0.f;
1784 Graph_GetControl(graph, index+i, value);
1785 packet.addtag('f');
1786 packet.addf(value);
1791 if (packet.size()) {
1792 CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
1795 return kSCErr_None;
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);
1812 return kSCErr_None;
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);
1820 return kSCErr_None;
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
1834 switch(mode) {
1835 case -1: inWorld->mLocalErrorNotification += 1;
1836 break;
1837 case -2: inWorld->mLocalErrorNotification -= 1;
1838 break;
1839 case 0: inWorld->mErrorNotification = 0;
1840 break;
1841 case 1: inWorld->mErrorNotification = 1;
1843 return kSCErr_None;
1846 #define NEW_COMMAND(name) NewCommand(#name, cmd_##name, meth_##name)
1848 void initMiscCommands();
1849 void initMiscCommands()
1852 // nrt
1853 NEW_COMMAND(none);
1854 NEW_COMMAND(notify);
1855 NEW_COMMAND(status);
1856 NEW_COMMAND(quit);
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);
1865 NEW_COMMAND(s_new);
1866 NEW_COMMAND(s_newargs);
1868 NEW_COMMAND(n_trace);
1869 NEW_COMMAND(n_free);
1870 NEW_COMMAND(n_run);
1872 NEW_COMMAND(u_cmd);
1873 NEW_COMMAND(cmd);
1875 //NEW_COMMAND(n_cmd);
1876 NEW_COMMAND(n_map);
1877 NEW_COMMAND(n_mapn);
1878 NEW_COMMAND(n_mapa);
1879 NEW_COMMAND(n_mapan);
1880 NEW_COMMAND(n_set);
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);
1888 NEW_COMMAND(g_new);
1889 NEW_COMMAND(g_head);
1890 NEW_COMMAND(g_tail);
1891 NEW_COMMAND(g_freeAll);
1892 NEW_COMMAND(g_deepFree);
1894 NEW_COMMAND(p_new);
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);
1908 NEW_COMMAND(b_set);
1909 NEW_COMMAND(b_setn);
1910 NEW_COMMAND(b_fill);
1911 NEW_COMMAND(b_gen);
1913 NEW_COMMAND(c_set);
1914 NEW_COMMAND(c_setn);
1915 NEW_COMMAND(c_fill);
1917 NEW_COMMAND(dumpOSC);
1919 NEW_COMMAND(c_get);
1920 NEW_COMMAND(c_getn);
1921 NEW_COMMAND(b_get);
1922 NEW_COMMAND(b_getn);
1923 NEW_COMMAND(s_get);
1924 NEW_COMMAND(s_getn);
1926 NEW_COMMAND(n_query);
1927 NEW_COMMAND(b_query);
1929 NEW_COMMAND(s_noid);
1930 NEW_COMMAND(sync);
1931 NEW_COMMAND(g_dumpTree);
1932 NEW_COMMAND(g_queryTree);
1934 NEW_COMMAND(error);