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 #ifndef _SC_Prototypes_
23 #define _SC_Prototypes_
25 #include <ctype.h> // for size_t
30 #include "scsynthsend.h"
32 ////////////////////////////////////////////////////////////////////////
34 // replacement for calloc.
35 // calloc lazily zeroes memory on first touch. This is good for most purposes, but bad for realtime audio.
36 void* zalloc(size_t n
, size_t size
);
37 void zfree(void* ptr
);
39 ////////////////////////////////////////////////////////////////////////
41 void World_Run(struct World
*inWorld
);
42 void World_Start(World
*inWorld
);
43 void World_SetSampleRate(struct World
*inWorld
, double inSampleRate
);
46 void World_Cleanup(World
*inWorld
);
47 void* World_Alloc(struct World
*inWorld
, size_t inByteSize
);
48 void* World_Realloc(struct World
*inWorld
, void *inPtr
, size_t inByteSize
);
49 void World_Free(struct World
*inWorld
, void *inPtr
);
50 void World_NRTLock(World
*world
);
51 void World_NRTUnlock(World
*world
);
54 size_t World_TotalFree(struct World
*inWorld
);
55 size_t World_LargestFreeChunk(struct World
*inWorld
);
58 int32
GetKey(struct Node
*inNode
);
59 int32
GetHash(struct Node
*inNode
);
60 bool World_AddNode(struct World
*inWorld
, struct Node
* inNode
);
61 bool World_RemoveNode(struct World
*inWorld
, struct Node
* inNode
);
64 struct Node
* World_GetNode(struct World
*inWorld
, int32 inID
);
65 struct Graph
* World_GetGraph(struct World
*inWorld
, int32 inID
);
68 struct Group
* World_GetGroup(struct World
*inWorld
, int32 inID
);
70 int32
*GetKey(struct UnitDef
*inUnitDef
);
71 int32
GetHash(struct UnitDef
*inUnitDef
);
72 bool AddUnitDef(struct UnitDef
* inUnitDef
);
73 bool RemoveUnitDef(struct UnitDef
* inUnitDef
);
74 struct UnitDef
* GetUnitDef(int32
* inKey
);
76 int32
*GetKey(struct BufGen
*inBufGen
);
77 int32
GetHash(struct BufGen
*inBufGen
);
78 bool AddBufGen(struct BufGen
* inBufGen
);
79 bool RemoveBufGen(struct BufGen
* inBufGen
);
80 struct BufGen
* GetBufGen(int32
* inKey
);
82 int32
*GetKey(struct PlugInCmd
*inPlugInCmd
);
83 int32
GetHash(struct PlugInCmd
*inPlugInCmd
);
84 bool AddPlugInCmd(struct PlugInCmd
* inPlugInCmd
);
85 bool RemovePlugInCmd(struct PlugInCmd
* inPlugInCmd
);
86 struct PlugInCmd
* GetPlugInCmd(int32
* inKey
);
87 int PlugIn_DoCmd(struct World
*inWorld
, int inSize
, char *inArgs
, struct ReplyAddress
*inReply
);
89 int32
*GetKey(struct GraphDef
*inGraphDef
);
90 int32
GetHash(struct GraphDef
*inGraphDef
);
91 void World_AddGraphDef(struct World
*inWorld
, struct GraphDef
* inGraphDef
);
92 void World_RemoveGraphDef(struct World
*inWorld
, struct GraphDef
* inGraphDef
);
93 struct GraphDef
* World_GetGraphDef(struct World
*inWorld
, int32
* inKey
);
94 void World_FreeAllGraphDefs(World
*inWorld
);
95 void GraphDef_Free(GraphDef
*inGraphDef
);
96 void GraphDef_Define(World
*inWorld
, GraphDef
*inList
);
97 void GraphDef_FreeOverwritten(World
*inWorld
);
99 SCErr
bufAlloc(struct SndBuf
* buf
, int numChannels
, int numFrames
, double sampleRate
);
101 ////////////////////////////////////////////////////////////////////////
103 void Rate_Init(struct Rate
*inRate
, double inSampleRate
, int inBufLength
);
105 ////////////////////////////////////////////////////////////////////////
107 #define GRAPHDEF(inGraph) ((GraphDef*)((inGraph)->mNode.mDef))
108 #define GRAPH_PARAM_TABLE(inGraph) (GRAPHDEF(inGraph)->mParamSpecTable)
110 int Graph_New(struct World
*inWorld
, struct GraphDef
*def
, int32 inID
, struct sc_msg_iter
* args
, struct Graph
** outGraph
,bool argtype
=true);
111 void Graph_Ctor(struct World
*inWorld
, struct GraphDef
*inGraphDef
, struct Graph
*graph
, struct sc_msg_iter
*msg
,bool argtype
);
112 void Graph_Dtor(struct Graph
*inGraph
);
113 int Graph_GetControl(struct Graph
* inGraph
, uint32 inIndex
, float& outValue
);
114 int Graph_GetControl(struct Graph
* inGraph
, int32 inHash
, int32
*inName
, uint32 inIndex
, float& outValue
);
115 void Graph_SetControl(struct Graph
* inGraph
, uint32 inIndex
, float inValue
);
116 void Graph_SetControl(struct Graph
* inGraph
, int32 inHash
, int32
*inName
, uint32 inIndex
, float inValue
);
117 void Graph_MapControl(Graph
* inGraph
, uint32 inIndex
, uint32 inBus
);
118 void Graph_MapControl(Graph
* inGraph
, int32 inHash
, int32
*inName
, uint32 inIndex
, uint32 inBus
);
119 void Graph_MapAudioControl(Graph
* inGraph
, uint32 inIndex
, uint32 inBus
);
120 void Graph_MapAudioControl(Graph
* inGraph
, int32 inHash
, int32
*inName
, uint32 inIndex
, uint32 inBus
);
121 void Graph_Trace(Graph
*inGraph
);
122 void Graph_RemoveID(World
* inWorld
, Graph
*inGraph
);
124 ////////////////////////////////////////////////////////////////////////
126 int Node_New(struct World
*inWorld
, struct NodeDef
*def
, int32 inID
, struct Node
**outNode
);
127 void Node_Dtor(struct Node
*inNode
);
128 void Node_Remove(struct Node
* s
);
129 void Node_Delete(struct Node
* inNode
);
130 void Node_AddAfter(struct Node
* s
, struct Node
*afterThisOne
);
131 void Node_AddBefore(struct Node
* s
, struct Node
*beforeThisOne
);
132 void Node_Replace(struct Node
* s
, struct Node
*replaceThisOne
);
133 void Node_SetControl(Node
* inNode
, int inIndex
, float inValue
);
134 void Node_SetControl(Node
* inNode
, int32 inHash
, int32
*inName
, int inIndex
, float inValue
);
135 void Node_MapControl(Node
* inNode
, int inIndex
, int inBus
);
136 void Node_MapControl(Node
* inNode
, int32 inHash
, int32
*inName
, int inIndex
, int inBus
);
137 void Node_MapAudioControl(Node
* inNode
, int inIndex
, int inBus
);
138 void Node_MapAudioControl(Node
* inNode
, int32 inHash
, int32
*inName
, int inIndex
, int inBus
);
139 void Node_StateMsg(Node
* inNode
, int inState
);
140 void Node_Trace(Node
* inNode
);
141 void Node_SendReply(Node
* inNode
, int replyID
, const char* cmdName
, int numArgs
, const float* values
);
142 void Node_SendReply(Node
* inNode
, int replyID
, const char* cmdName
, float value
);
145 void Node_SetRun(Node
* inNode
, int inRun
);
146 void Node_SendTrigger(Node
* inNode
, int triggerID
, float value
);
147 void Node_End(struct Node
* inNode
);
148 void Node_NullCalc(struct Node
* inNode
);
149 void Unit_DoneAction(int doneAction
, struct Unit
* unit
);
152 ////////////////////////////////////////////////////////////////////////
155 void Group_Calc(Group
*inGroup
);
156 void Graph_Calc(struct Graph
*inGraph
);
159 int Group_New(World
*inWorld
, int32 inID
, Group
** outGroup
);
160 void Group_Dtor(Group
*inGroup
);
161 void Group_DeleteAll(Group
*inGroup
);
162 void Group_DeepFreeGraphs(Group
*inGroup
);
163 void Group_AddHead (Group
*s
, Node
*child
);
164 void Group_AddTail (Group
*s
, Node
*child
);
165 void Group_Insert(Group
*s
, Node
*child
, int inIndex
);
166 void Group_SetControl(struct Group
* inGroup
, uint32 inIndex
, float inValue
);
167 void Group_SetControl(struct Group
*inGroup
, int32 inHash
, int32
*inName
, uint32 inIndex
, float inValue
);
168 void Group_MapControl(Group
* inGroup
, uint32 inIndex
, uint32 inBus
);
169 void Group_MapControl(Group
* inGroup
, int32 inHash
, int32
*inName
, uint32 inIndex
, uint32 inBus
);
170 void Group_MapAudioControl(Group
* inGroup
, uint32 inIndex
, uint32 inBus
);
171 void Group_MapAudioControl(Group
* inGroup
, int32 inHash
, int32
*inName
, uint32 inIndex
, uint32 inBus
);
172 void Group_Trace(Group
* inGroup
);
173 void Group_DumpTree(Group
* inGroup
);
174 void Group_DumpTreeAndControls(Group
* inGroup
);
175 void Group_CountNodeTags(Group
* inGroup
, int* count
);
176 void Group_CountNodeAndControlTags(Group
* inGroup
, int* count
, int* controlAndDefCount
);
177 void Group_QueryTree(Group
* inGroup
, big_scpacket
* packet
);
178 void Group_QueryTreeAndControls(Group
* inGroup
, big_scpacket
*packet
);
180 ////////////////////////////////////////////////////////////////////////
182 struct Unit
* Unit_New(struct World
*inWorld
, struct UnitSpec
*inUnitSpec
, char*& memory
);
183 void Unit_EndCalc(struct Unit
*inUnit
, int inNumSamples
);
184 void Unit_End(struct Unit
*inUnit
);
186 void Unit_Dtor(struct Unit
*inUnit
);
189 void Unit_ZeroOutputs(struct Unit
*inUnit
, int inNumSamples
);
192 ////////////////////////////////////////////////////////////////////////
194 void SendDone(struct ReplyAddress
*inReply
, const char *inCommandName
);
195 void SendDoneWithIntValue(struct ReplyAddress
*inReply
, const char *inCommandName
, int value
);
196 void SendFailure(struct ReplyAddress
*inReply
, const char *inCommandName
, const char *errString
);
197 void SendFailureWithBufnum(struct ReplyAddress
*inReply
, const char *inCommandName
, const char *errString
, uint32 index
);
198 void ReportLateness(struct ReplyAddress
*inReply
, float32 seconds
);
199 int32
Hash(struct ReplyAddress
*inReplyAddress
);
201 ////////////////////////////////////////////////////////////////////////
204 int32
server_timeseed();
207 ////////////////////////////////////////////////////////////////////////
209 typedef bool (*AsyncStageFn
)(World
*inWorld
, void* cmdData
);
210 typedef void (*AsyncFreeFn
)(World
*inWorld
, void* cmdData
);
212 int PerformAsynchronousCommand
218 AsyncStageFn stage2
, // stage2 is non real time
219 AsyncStageFn stage3
, // stage3 is real time - completion msg performed if stage3 returns true
220 AsyncStageFn stage4
, // stage4 is non real time - sends done if stage4 returns true
222 int completionMsgSize
,
223 void* completionMsgData
226 ////////////////////////////////////////////////////////////////////////