File: CmdPeriod.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (86 lines) | stat: -rw-r--r-- 2,136 bytes parent folder | download | duplicates (6)
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
class:: CmdPeriod
summary:: register objects to be cleared when Cmd-. is pressed
related:: Classes/ShutDown, Classes/ServerQuit
categories:: Control

description::

CmdPeriod allows you to register objects to perform an action when the user presses Cmd-. These objects must implement a method called strong::-cmdPeriod:: which performs the necessary tasks. (You can add such a method in your custom classes.) Note that since link::Classes/Function:: implements strong::-cmdPeriod:: as a synonym for strong::-value::, it is possible to register any function (and thus any arbitrary code) for evaluation when Cmd-. is pressed.

ClassMethods::

method::add
Registers an object to be cleared when Cmd-. is pressed. This object will stay registered until it is explicitly removed, and will thus respond to additional presses of Cmd-.

method::remove
Removes an object that was previously registered.

method::removeAll
Removes all objects that have been registered.

method::doOnce
Registers an object to be evaluated once, and then unregistered.

method::objects
Get or set the list of objects that are called when CmdPeriod is evaluated.

method::era
The number of times CmdPeriod has been called since startup.

Examples::

code::
(
f = {"foo".postln };
g = {"bar".postln };
CmdPeriod.add(f);
CmdPeriod.add(g);
)

// Now press Cmd-.

CmdPeriod.remove(g);

// Now press Cmd-. Only f executes

CmdPeriod.remove(f); // must explicitly cleanup


// Now press Cmd-.

CmdPeriod.add(g); // one object is added only once.
CmdPeriod.add(g); // one object is added only once.


// Now press Cmd-.

// remove it again.
CmdPeriod.remove(g);


// note that often you want to automatically remove the function once it is evaluated
// instead of

f = { "foo".postln; CmdPeriod.remove(f) };
CmdPeriod.add(f);

// you can write:

CmdPeriod.doOnce { "foo".postln }

// a typical example:
(
w = Window.new("close on cmd-.").front;
CmdPeriod.doOnce { w.close };
)


// in some cases you might need to defer the function by a short amount of time
a = { Synth(\default)};
a.value;
CmdPeriod.add({{a.value}.defer(0.01)});

// remove all
CmdPeriod.removeAll

::