1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
5
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.
10
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.
15
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
19 */
20
21
22 #pragma once
23
24 #include "SC_Types.h"
25 #include "SC_Rate.h"
26 #include "SC_SndBuf.h"
27 #include "SC_RGen.h"
28 #include "HashTable.h"
29 #include "SC_World.h"
30 #include "SC_Reply.h"
31 #include "MsgFifo.h"
32 #include <map>
33 #include <deque>
34 #include <set>
35
36 #include "boost/sync/semaphore.hpp"
37
38 #include "../../common/server_shm.hpp"
39
40 extern HashTable<struct UnitDef, Malloc>* gUnitDefLib;
41
42
43 struct TriggerMsg {
44 World* mWorld;
45 int32 mNodeID;
46 int32 mTriggerID;
47 float mValue;
48
49 void Perform();
50 };
51
52
53 struct NodeReplyMsg {
54 World* mWorld;
55 int32 mNodeID;
56 int32 mID;
57 int32 mNumArgs;
58 float* mValues;
59 int32 mCmdNameSize;
60 char* mCmdName;
61 void* mRTMemory;
62 void Perform();
63 };
64
65
66 struct NodeEndMsg {
67 World* mWorld;
68 int32 mNodeID;
69 int32 mGroupID;
70 int32 mPrevNodeID;
71 int32 mNextNodeID;
72 int32 mIsGroup;
73 int32 mHeadID;
74 int32 mTailID;
75 int32 mState;
76
77 void Perform();
78 };
79
80 struct DeleteGraphDefMsg {
81 struct GraphDef* mDef;
82
83 void Perform();
84 };
85
86
87 typedef MsgFifoNoFree<TriggerMsg, 1024> TriggersFifo;
88 typedef MsgFifoNoFree<NodeReplyMsg, 1024> NodeReplyFifo;
89 typedef MsgFifoNoFree<NodeEndMsg, 1024> NodeEndsFifo;
90 typedef MsgFifoNoFree<DeleteGraphDefMsg, 512> DeleteGraphDefsFifo;
91 typedef HashTable<struct GraphDef, Malloc> GrafDefTable;
92
93 typedef std::map<struct ReplyAddress, uint32> ClientIDDict;
94 typedef std::deque<int> ClientIDs;
95 typedef std::set<ReplyAddress> Clients;
96
97 struct HiddenWorld {
98 class AllocPool* mAllocPool;
99 IntHashTable<struct Node, AllocPool>* mNodeLib;
100 GrafDefTable* mGraphDefLib;
101 uint32 mMaxUsers;
102 Clients* mUsers;
103 ClientIDs* mAvailableClientIDs;
104 ClientIDDict* mClientIDdict;
105
106 class SC_AudioDriver* mAudioDriver;
107 char mPassword[32];
108
109 uint32 mMaxWireBufs;
110 float* mWireBufSpace;
111
112 TriggersFifo mTriggers;
113 NodeReplyFifo mNodeMsgs;
114 NodeEndsFifo mNodeEnds;
115 DeleteGraphDefsFifo mDeleteGraphDefs;
116
117 boost::sync::semaphore* mQuitProgram;
118 bool mTerminating;
119
120 #ifndef NO_LIBSNDFILE
121 SNDFILE* mNRTInputFile;
122 SNDFILE* mNRTOutputFile;
123 FILE* mNRTCmdFile;
124 #endif
125
126 int32 mHiddenID;
127 int32 mRecentID;
128
129 #ifdef __APPLE__
130 const char* mInputStreamsEnabled;
131 const char* mOutputStreamsEnabled;
132 #endif
133 const char* mInDeviceName;
134 const char* mOutDeviceName;
135 class server_shared_memory_creator* mShmem;
136 };
137
138 typedef struct HiddenWorld HiddenWorld;
139
AudioDriver(World * inWorld)140 inline SC_AudioDriver* AudioDriver(World* inWorld) { return inWorld->hw->mAudioDriver; }
141