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_Lib_Cintf.h"
24 #include "SC_ComPort.h"
25 #include "SC_SequencedCommand.h"
26 #include "scsynthsend.h"
29 #include "SC_Prototypes.h"
33 void SendDone(ReplyAddress
*inReply
, const char *inCommandName
)
35 small_scpacket packet
;
40 packet
.adds(inCommandName
);
41 SendReply(inReply
, packet
.data(), packet
.size());
44 void SendDoneWithIntValue(ReplyAddress
*inReply
, const char *inCommandName
, int value
)
46 small_scpacket packet
;
51 packet
.adds(inCommandName
);
54 SendReply(inReply
, packet
.data(), packet
.size());
57 void SendFailure(ReplyAddress
*inReply
, const char *inCommandName
, const char *errString
)
59 small_scpacket packet
;
65 packet
.adds(inCommandName
);
66 packet
.adds(errString
);
67 SendReply(inReply
, packet
.data(), packet
.size());
70 void SendFailureWithBufnum(ReplyAddress
*inReply
, const char *inCommandName
, const char *errString
, uint32 index
)
72 small_scpacket packet
;
78 packet
.adds(inCommandName
);
79 packet
.adds(errString
);
81 packet
.addi((int)index
);
82 SendReply(inReply
, packet
.data(), packet
.size());
85 void ReportLateness(ReplyAddress
*inReply
, float32 seconds
)
87 small_scpacket packet
;
93 SendReply(inReply
, packet
.data(), packet
.size());
96 SC_NamedObj::SC_NamedObj()
101 SC_NamedObj::~SC_NamedObj()
104 void SC_NamedObj::SetName(const int32
*inName
)
106 if (str4len(inName
) > (int)kSCNameLen
) return;
107 str4cpy(mName
, inName
);
111 void SC_NamedObj::SetName(const char *inName
)
113 if (str4len(inName
) > (int)kSCNameLen
) return;
114 str4cpy(mName
, inName
);
118 SC_LibCmd::SC_LibCmd(SC_CommandFunc inFunc
) : mFunc(inFunc
)
121 SCErr
SC_LibCmd::Perform(struct World
*inWorld
, int inSize
, char *inData
, ReplyAddress
*inReply
)
124 // int kSendError = 1; // i.e., 0x01 | 0x02;
126 err
= (mFunc
)(inWorld
, inSize
, inData
, inReply
);
129 } catch (std::exception
& exc
) {
130 if(inWorld
->mLocalErrorNotification
<= 0 && inWorld
->mErrorNotification
) {
131 CallSendFailureCommand(inWorld
, (char*)Name(), exc
.what(), inReply
);
132 scprintf("FAILURE %s %s\n", (char*)Name(), exc
.what());
134 return kSCErr_Failed
;
138 if (err
&& (inWorld
->mLocalErrorNotification
<= 0 && inWorld
->mErrorNotification
)) {
140 SC_ErrorString(err
, errstr
);
141 CallSendFailureCommand(inWorld
, (char*)Name(), errstr
, inReply
);
142 scprintf("FAILURE %s %s\n", (char*)Name(), errstr
);
147 SCErr
NewCommand(const char *inPath
, uint32 inCommandNumber
, SC_CommandFunc inFunc
)
150 sprintf(path
, "/%s", inPath
);
152 SC_LibCmd
*cmd
= new SC_LibCmd(inFunc
);
156 // support OSC commands without the leading slash
157 SC_LibCmd
*cmd2
= new SC_LibCmd(inFunc
);
158 cmd2
->SetName(inPath
);
161 // support integer OSC commands
162 gCmdArray
[inCommandNumber
] = cmd
;