File: NotificationCenter.schelp

package info (click to toggle)
supercollider 1%3A3.7.0~repack-4%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 34,364 kB
  • sloc: cpp: 197,140; ansic: 72,013; lisp: 63,505; sh: 14,009; python: 1,992; perl: 766; makefile: 679; java: 677; xml: 326; yacc: 309; lex: 175; ruby: 173; objc: 65
file content (45 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download | duplicates (2)
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
class:: NotificationCenter
summary:: let an object emit notifications
related:: Classes/SimpleController, Classes/NodeWatcher
categories:: Control

description::
One common OOP pattern is Model-View-Controller where one object (the controller) is a dependant of the model. Every time the model changes it notifies all of its dependants. In this case the model has a dictionary of dependants and iterates through those.

Another common pattern is NotificationCenter wherein an object emits a notification and clients can register functions that will be executed when that notification happens.

A link::Classes/Server:: emits a \newAllocators notification when it creates new node and bus allocators which it does when it quits or boots.

code::
NotificationCenter.notify(Server.default, \newAllocators);
::

You can listen for this:

code::
NotificationCenter.register(Server.default, \newAllocators, yourself, {
	// throw away all your node variables
	// or stop the music
});
::

The link::Classes/Buffer:: class register a function to clear its info cache whenever a server restarts. The server is emiting changed messages quite often (every 0.4 secs for the status updates), and the Buffer class is only interested in boot/quit events, so this is a more lightweight system for this purpose.

ClassMethods::

private::initClass

method::notify
The object emits a message and may also pass extra args.

method::register
An interested client can register the action function for the object/message notification. A listener may only register one action per object/message notification.

method::unregister
Remove the registrations.

method::registerOneShot
After the notification has been emited and handled, automatically unregister.

method::registrationExists
Simply confirms if a registration is already in place.