Fix scvim regsitry file for updated filename (thanks Carlo Capocasa)
[supercollider.git] / server / scsynth / SC_Lib.cpp
blob363317d05ef79f1aa1f602809326594915573b09
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_Lib_Cintf.h"
24 #include "SC_SequencedCommand.h"
25 #include "scsynthsend.h"
26 #include <string.h>
27 #include <ctype.h>
28 #include "SC_Prototypes.h"
29 #include "SC_Str4.h"
32 void SendDone(ReplyAddress *inReply, const char *inCommandName)
34 small_scpacket packet;
35 packet.adds("/done");
36 packet.maketags(2);
37 packet.addtag(',');
38 packet.addtag('s');
39 packet.adds(inCommandName);
40 SendReply(inReply, packet.data(), packet.size());
43 void SendDoneWithIntValue(ReplyAddress *inReply, const char *inCommandName, int value)
45 small_scpacket packet;
46 packet.adds("/done");
47 packet.maketags(3);
48 packet.addtag(',');
49 packet.addtag('s');
50 packet.adds(inCommandName);
51 packet.addtag('i');
52 packet.addi(value);
53 SendReply(inReply, packet.data(), packet.size());
56 void SendFailure(ReplyAddress *inReply, const char *inCommandName, const char *errString)
58 small_scpacket packet;
59 packet.adds("/fail");
60 packet.maketags(3);
61 packet.addtag(',');
62 packet.addtag('s');
63 packet.addtag('s');
64 packet.adds(inCommandName);
65 packet.adds(errString);
66 SendReply(inReply, packet.data(), packet.size());
69 void SendFailureWithBufnum(ReplyAddress *inReply, const char *inCommandName, const char *errString, uint32 index)
71 small_scpacket packet;
72 packet.adds("/fail");
73 packet.maketags(4);
74 packet.addtag(',');
75 packet.addtag('s');
76 packet.addtag('s');
77 packet.adds(inCommandName);
78 packet.adds(errString);
79 packet.addtag('i');
80 packet.addi((int)index);
81 SendReply(inReply, packet.data(), packet.size());
84 void ReportLateness(ReplyAddress *inReply, float32 seconds)
86 small_scpacket packet;
87 packet.adds("/late");
88 packet.maketags(2);
89 packet.addtag(',');
90 packet.addtag('f');
91 packet.addf(seconds);
92 SendReply(inReply, packet.data(), packet.size());
95 SC_NamedObj::SC_NamedObj()
97 SetName("?");
100 SC_NamedObj::~SC_NamedObj()
103 void SC_NamedObj::SetName(const int32 *inName)
105 if (str4len(inName) > (int)kSCNameLen) return;
106 str4cpy(mName, inName);
107 mHash = Hash(mName);
110 void SC_NamedObj::SetName(const char *inName)
112 if (str4len(inName) > (int)kSCNameLen) return;
113 str4cpy(mName, inName);
114 mHash = Hash(mName);
117 SC_LibCmd::SC_LibCmd(SC_CommandFunc inFunc) : mFunc(inFunc)
120 SCErr SC_LibCmd::Perform(struct World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
122 SCErr err;
123 // int kSendError = 1; // i.e., 0x01 | 0x02;
124 try {
125 err = (mFunc)(inWorld, inSize, inData, inReply);
126 } catch (int iexc) {
127 err = iexc;
128 } catch (std::exception& exc) {
129 if(inWorld->mLocalErrorNotification <= 0 && inWorld->mErrorNotification) {
130 CallSendFailureCommand(inWorld, (char*)Name(), exc.what(), inReply);
131 scprintf("FAILURE IN SERVER %s %s\n", (char*)Name(), exc.what());
133 return kSCErr_Failed;
134 } catch (...) {
135 err = kSCErr_Failed;
137 if (err && (inWorld->mLocalErrorNotification <= 0 && inWorld->mErrorNotification)) {
138 char errstr[25];
139 SC_ErrorString(err, errstr);
140 CallSendFailureCommand(inWorld, (char*)Name(), errstr, inReply);
141 scprintf("FAILURE IN SERVER %s %s\n", (char*)Name(), errstr);
143 return err;
146 SCErr NewCommand(const char *inPath, uint32 inCommandNumber, SC_CommandFunc inFunc)
148 char path[256];
149 sprintf(path, "/%s", inPath);
151 SC_LibCmd *cmd = new SC_LibCmd(inFunc);
152 cmd->SetName(path);
153 gCmdLib->Add(cmd);
155 // support OSC commands without the leading slash
156 SC_LibCmd *cmd2 = new SC_LibCmd(inFunc);
157 cmd2->SetName(inPath);
158 gCmdLib->Add(cmd2);
160 // support integer OSC commands
161 gCmdArray[inCommandNumber] = cmd;
163 return kSCErr_None;