aboutsummaryrefslogtreecommitdiff
path: root/sc4pd/headers/server/SC_Prototypes.h
blob: c2f353efcb87173ebb545f4d5752827e98ca4c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
	SuperCollider real time audio synthesis system
    Copyright (c) 2002 James McCartney. All rights reserved.
	http://www.audiosynth.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#ifndef _SC_Prototypes_
#define _SC_Prototypes_

#include <ctype.h> // for size_t

#include "SC_Types.h"

////////////////////////////////////////////////////////////////////////

// replacement for calloc. 
// calloc lazily zeroes memory on first touch. This is good for most purposes, but bad for realtime audio.
void* zalloc(size_t n, size_t size);

////////////////////////////////////////////////////////////////////////

void World_Run(struct World *inWorld);
void World_Start(World *inWorld);
void World_Cleanup(World *inWorld);
void World_SetSampleRate(struct World *inWorld, double inSampleRate);

extern "C" {
void* World_Alloc(struct World *inWorld, size_t inByteSize);
void* World_Realloc(struct World *inWorld, void *inPtr, size_t inByteSize);
void World_Free(struct World *inWorld, void *inPtr);
void World_NRTLock(World *world);
void World_NRTUnlock(World *world);
}

size_t World_TotalFree(struct World *inWorld);
size_t World_LargestFreeChunk(struct World *inWorld);


int32 GetKey(struct Node *inNode);
int32 GetHash(struct Node *inNode);
bool World_AddNode(struct World *inWorld, struct Node* inNode);
bool World_RemoveNode(struct World *inWorld, struct Node* inNode);

extern "C" {
struct Node* World_GetNode(struct World *inWorld, int32 inID);
struct Graph* World_GetGraph(struct World *inWorld, int32 inID);
}

struct Group* World_GetGroup(struct World *inWorld, int32 inID);

int32 *GetKey(struct UnitDef *inUnitDef);
int32 GetHash(struct UnitDef *inUnitDef);
bool AddUnitDef(struct UnitDef* inUnitDef);
bool RemoveUnitDef(struct UnitDef* inUnitDef);
struct UnitDef* GetUnitDef(int32* inKey);

int32 *GetKey(struct BufGen *inBufGen);
int32 GetHash(struct BufGen *inBufGen);
bool AddBufGen(struct BufGen* inBufGen);
bool RemoveBufGen(struct BufGen* inBufGen);
struct BufGen* GetBufGen(int32* inKey);

int32 *GetKey(struct PlugInCmd *inPlugInCmd);
int32 GetHash(struct PlugInCmd *inPlugInCmd);
bool AddPlugInCmd(struct PlugInCmd* inPlugInCmd);
bool RemovePlugInCmd(struct PlugInCmd* inPlugInCmd);
struct PlugInCmd* GetPlugInCmd(int32* inKey);
int PlugIn_DoCmd(struct World *inWorld, int inSize, char *inArgs, struct ReplyAddress *inReply);

int32 *GetKey(struct GraphDef *inGraphDef);
int32 GetHash(struct GraphDef *inGraphDef);
bool World_AddGraphDef(struct World *inWorld, struct GraphDef* inGraphDef);
bool World_FreeGraphDef(struct World *inWorld, struct GraphDef* inGraphDef);
bool World_RemoveGraphDef(struct World *inWorld, struct GraphDef* inGraphDef);
struct GraphDef* World_GetGraphDef(struct World *inWorld, int32* inKey);
void World_FreeAllGraphDefs(World *inWorld);
void GraphDef_Free(GraphDef *inGraphDef);
void GraphDef_Define(World *inWorld, GraphDef *inList);
void GraphDef_FreeOverwritten(World *inWorld);

SCErr bufAlloc(struct SndBuf* buf, int numChannels, int numFrames, double sampleRate);

////////////////////////////////////////////////////////////////////////

void Rate_Init(struct Rate *inRate, double inSampleRate, int inBufLength);

void Dimension_Init(struct SC_Dimension *inDimension, int inWidth, int inHeight);

////////////////////////////////////////////////////////////////////////

#define GRAPHDEF(inGraph) ((GraphDef*)((inGraph)->mNode.mDef))
#define GRAPH_PARAM_TABLE(inGraph) (GRAPHDEF(inGraph)->mParamSpecTable)

int Graph_New(struct World *inWorld, struct GraphDef *def, int32 inID, struct sc_msg_iter* args, struct Graph** outGraph);
void Graph_Ctor(struct World *inWorld, struct GraphDef *inGraphDef, struct Graph *graph, struct sc_msg_iter *msg);
void Graph_Dtor(struct Graph *inGraph);
int  Graph_GetControl(struct Graph* inGraph, uint32 inIndex, float& outValue);
int  Graph_GetControl(struct Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float& outValue);
void Graph_SetControl(struct Graph* inGraph, uint32 inIndex, float inValue);
void Graph_SetControl(struct Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float inValue);
void Graph_MapControl(Graph* inGraph, uint32 inIndex, uint32 inBus);
void Graph_MapControl(Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, uint32 inBus);
void Graph_Trace(Graph *inGraph);
void Graph_RemoveID(World* inWorld, Graph *inGraph);

////////////////////////////////////////////////////////////////////////

int Node_New(struct World *inWorld, struct NodeDef *def, int32 inID, struct Node **outNode);
void Node_Dtor(struct Node *inNode);
void Node_Remove(struct Node* s);
void Node_Delete(struct Node* inNode);
void Node_AddAfter(struct Node* s, struct Node *afterThisOne);
void Node_AddBefore(struct Node* s, struct Node *beforeThisOne);
void Node_Replace(struct Node* s, struct Node *replaceThisOne);
void Node_SetControl(Node* inNode, int inIndex, float inValue);
void Node_SetControl(Node* inNode, int32 inHash, int32 *inName, int inIndex, float inValue);
void Node_MapControl(Node* inNode, int inIndex, int inBus);
void Node_MapControl(Node* inNode, int32 inHash, int32 *inName, int inIndex, int inBus);
void Node_StateMsg(Node* inNode, int inState);
void Node_Trace(Node* inNode);

extern "C" {
void Node_SetRun(Node* inNode, int inRun);
void Node_SendTrigger(Node* inNode, int triggerID, float value);
void Node_End(struct Node* inNode);
void Node_NullCalc(struct Node* inNode);
void Unit_DoneAction(int doneAction, struct Unit* unit);
}

////////////////////////////////////////////////////////////////////////

extern "C" {
void Group_Calc(Group *inGroup);
void Graph_Calc(struct Graph *inGraph);
}

int Group_New(World *inWorld, int32 inID, Group** outGroup);
void Group_Dtor(Group *inGroup);
void Group_DeleteAll(Group *inGroup);
void Group_DeepFreeGraphs(Group *inGroup);
void Group_AddHead (Group *s, Node *child);
void Group_AddTail (Group *s, Node *child);
void Group_Insert(Group *s, Node *child, int inIndex);
void Group_SetControl(struct Group* inGroup, uint32 inIndex, float inValue);
void Group_SetControl(struct Group *inGroup, int32 inHash, int32 *inName, uint32 inIndex, float inValue);
void Group_MapControl(Group* inGroup, uint32 inIndex, uint32 inBus);
void Group_MapControl(Group* inGroup, int32 inHash, int32 *inName, uint32 inIndex, uint32 inBus);
void Group_Trace(Group* inGroup);

////////////////////////////////////////////////////////////////////////

struct Unit* Unit_New(struct World *inWorld, struct UnitSpec *inUnitSpec, char*& memory);
void Unit_EndCalc(struct Unit *inUnit, int inNumSamples);
void Unit_End(struct Unit *inUnit);

void Unit_Dtor(struct Unit *inUnit);

extern "C" {
void Unit_ZeroOutputs(struct Unit *inUnit, int inNumSamples);
}

////////////////////////////////////////////////////////////////////////

void SendDone(struct ReplyAddress *inReply, char *inCommandName);
void SendFailure(struct ReplyAddress *inReply, char *inCommandName, char *errString);
void ReportLateness(struct ReplyAddress *inReply, float32 seconds);
void DumpReplyAddress(struct ReplyAddress *inReplyAddress);
int32 Hash(struct ReplyAddress *inReplyAddress);

////////////////////////////////////////////////////////////////////////

extern "C" {
int32 timeseed();
}

////////////////////////////////////////////////////////////////////////

typedef bool (*AsyncStageFn)(World *inWorld, void* cmdData);
typedef void (*AsyncFreeFn)(World *inWorld, void* cmdData);

int PerformAsynchronousCommand
	(
		World *inWorld,
		void* replyAddr,
		const char* cmdName,
		void *cmdData,
		AsyncStageFn stage2, // stage2 is non real time
		AsyncStageFn stage3, // stage3 is real time - completion msg performed if stage3 returns true
		AsyncStageFn stage4, // stage4 is non real time - sends done if stage4 returns true
		AsyncFreeFn cleanup,
		int completionMsgSize,
		void* completionMsgData
	);

////////////////////////////////////////////////////////////////////////

#endif