5
5
* OSC Address Spaces and OSC Addresses
6
6
* OSC Message Dispatching and Pattern Matching
7
7
8
- See the ``_demo() `` function below for a usage example .
8
+ See the unit tests in ``tests/ttest_dispatch.py `` for API usage examples .
9
9
10
- **Note:** Path-traversing wildcards (``//``) as specified by the OSC 1.1
10
+ **Note:** Path-traversing wildcards (``//``) as envisioned by the OSC 1.1
11
11
"specification" paper are **not** supported.
12
12
13
13
"""
@@ -46,6 +46,11 @@ def expand_curly_braces(s, offset=0):
46
46
47
47
48
48
class OSCAddressContainer (dict ):
49
+ """
50
+ Branch node in the OSC Address Space tree containing OSC Methods or
51
+ sub-branches.
52
+
53
+ """
49
54
def __init__ (self , name , parent = None ):
50
55
super ().__init__ ()
51
56
self .name = name
@@ -139,6 +144,13 @@ def _check_branch(node, ptn, nodetype, brace_expansion=True):
139
144
140
145
141
146
class OSCMethod :
147
+ """
148
+ A leaf node in the OSC Address Space tree wrapping the callable for an OSC
149
+ Method.
150
+
151
+ """
152
+ __slots__ = ("name" , "callable_" , "typetags" , "parent" )
153
+
142
154
def __init__ (self , name , callable_ , typetags = TYPETAGS_ANY , parent = None ):
143
155
self .name = name
144
156
self .callable_ = callable_
@@ -155,28 +167,25 @@ def __repr__(self):
155
167
_root = None
156
168
157
169
158
- def get_default_root ():
159
- global _root
160
- if _root is None :
161
- _root = OSCAddressContainer ("/" )
162
- return _root
170
+ def get_global_root ():
171
+ """Return global OSC Address Space root OSCAdressContainer node instance.
163
172
173
+ The root node is created on demand, when this function is first called and
174
+ the tree will initially be unpopulated, i.e. have no branches or leaves.
164
175
165
- def _demo ():
166
- def fn ( * args ):
167
- pass
176
+ The global root node, as the name says, is a module global, so changes to
177
+ the tree it is the root of, will be visible via all references to it
178
+ retrieved via this function in the same program.
168
179
169
- import sys
180
+ To create a non-global OSC Adress Space tree, just create a new
181
+ ``OSCAddressContainer`` instance like so:
170
182
171
- root = get_default_root ()
172
- root .register_method (fn , "/ops/math/add" , "ii" )
173
- root .register_method (fn , "/ops/math/sum" , TYPETAGS_ANY )
174
- root .register_method (fn , "/ops/string/add" , "ii" )
175
- root .register_method (fn , "/ops/array/add" , "ii" )
176
- root .register_method (fn , "/ops/math/sub" , "ii" )
183
+ myroot = OSCAddressContainer(name="/")
177
184
178
- print (root .match (* sys .argv [1 :]))
185
+ """
186
+ global _root
179
187
188
+ if _root is None :
189
+ _root = OSCAddressContainer ("/" )
180
190
181
- if __name__ == "__main__" :
182
- _demo ()
191
+ return _root
0 commit comments