File: History.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 (409 lines) | stat: -rw-r--r-- 11,476 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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
class:: History
summary:: keeps a history of interpreted lines of code
related:: Classes/Archive
categories:: Streams-Patterns-Events

description::

History stores all code strings as they are being evaluated, in order to reuse code written earlier, to forward code to other players, or to store, reproduce, edit and analyse live-coded performances. It records every evaluated code string into a singleton instance of History - code::History.current::.

First examples:
code::
History.clear.end;     // if needed, clear History first
History.start;         // starts recording, opens log file

// execute these lines one by one, as a little performance history
1 + 2;
p = ProxySpace.push(s.boot);
~a = {Dust.ar([1,1] * 30 ) * 0.3 };
~a.play;
~a.end(3);

History.started; // is it on now?

// stops recording history and ends logging.
History.end;
History.started;

History.document;      // creates a document with current history
History.showLogFolder; // opens the folder where logs are written.
History.showLogFile;   // opens the current log file as it was written.


// make a gui window, to access code history lines at will,
// e.g. for code reuse in performance, adaptation, sharing, etc:
g = History.makeWin;
// specify left-bottom position, and number of lines in textview
g = History.makeWin(0@20, 5);

// play back the recorded history line by line
History.play(0);


// history can even record and play back stops with CmdPeriod.
// run these lines one at a time:
History.clear.start;
1 + 2;
2 + 3;
s.boot;
(dur: inf).play;

CmdPeriod.run; // or hit the Stop key command, Cmd-., or ctrl-.
3 + 4; // continue recording into history
4 + 5;
History.end;

// Replays history, including a CmdPeriod, and keeps replaying history.
History.play;


::

ClassMethods::

Note::
Many class methods are redirected to the privileged instance of History, code:: History.current::. This is intended to provide a simple code user interface.
::

private::initClass, timeStamp, dateString, hasMovedOn, lineShorts
private:: addToLog, date, time0, saveFolder, logFolder, logFile, logPath, makeLogFolder, checkLogStarted, startLog, endLog, showLogFile.
private:: maxShortLength, getTimeFromString, asLines, cmdPeriod

method::start
start adding interpreted code to (current) history.

method::end
end adding interpreted code to (current) history.

method::started
boolean whether History is started.

method::document
post the history in a new document (as story). The document title is a string formatted as follows: code::"%Y-%m-%d-%Hh%M-History"::.

method::current
the current History instance

method::lines, lineShorts
the currently recorded lines in History.current.
lineShorts is a copy with shortened strings for display.

method::makeWin
make a HistoryGui for History.current.
argument: where
a point that sets left top of the HistoryGui window,
argument: numItems
the number of lines in the textview

subsection::Configuration

method::keepsLog
get and set flag whether to log History to a file.

method::verbose
get and set flag whether to post debug messages from History operations.

method::recordLocally
get and set flag to turn recording local code evaluation on and off

method::localOff, localOn
convenience to turn recording of local code evaluation on and off

method::forwardFunc
a function to run on incoming new lines, can be used to send code by network.
See the Utopia quark for examples of networking code history.

subsection::Save and load history logs

method::showLogFolder
open folder where logfiles are stored

method::showLogFile
open current log file

method::saveCS
store history as one compileString.

method::loadCS
load a history from (compilestring) file.

method::saveStory
store in a file, in historical order as individual code snippets.

method::loadStory
read history into current, from a file in story format.

method::rewrite
Write a properly formatted code file from a history.
argument::path
The filename is the original name with "_rewritten." appended.
argument::open
If open is true (default: true), open a text window with the string.

method::readFromDoc
read in a history from a code file created with .rewrite


subsection:: Editing history
method::clear
remove all items from (current) history.

method::enter
add an entry to (current) history by hand.

method::drop
drop the newest num lines from history. if n is negative, drop the oldest n lines.

method::keep
keep only the newest num lines from history. if n is negative, keep the oldest n lines.

method::removeAt
remove a specific line

method::removeLast
remove last line from history

subsection:: Repeating history
Repeating history can have different uses:
A. Reconstruction, e.g. redoing a history of coding steps as closely as possible,
or replaying a full performance as closely as possible; here, all errors are important and should be handled individually.
B. Experimental live performance, e.g. replaying snippets from a recorded networked live-coding show in nonlinear orders; here, errors will occur more often because the current state will not always fit with what a particular line would require. Thus, one will likely prefer the robustness to just keep going.

method:: ignoreErrors
global flag whether evaluating code lines via History will ignore errors or stop and throw them.

method::eval
evaluate codeString, and optionally, use ignoreError to override global ignoreErrors flag.

code::
History.ignoreErrors = true;
History.eval("2 + 1").postln; // correct code, so is just evaluated
History.eval("2 + qwe"); 123; // compile error, but keeps going and posts 123
History.eval("1.blonk"); 123; // runtime error, keeps going -> posts 123
History.eval("1.blonk", false); 123; // throws error and stops, code after it never happens.
::

method::evalLineAt
evaluate the line at index in History.current.lines

method::play
play back current history from start to end line, per default verbose.

method::stop
stop current history playback.


subsection:: Date, time, string functions
method::startTimeStamp
method::formatTime
method::unformatTime
method::shorten
method::prettyString

private:: checkPath

method::new
create a new instance containing the lines given.

InstanceMethods::

Note:: the instance methods code::[hasMovedOn_, hasMovedOn, play, stop, lines, lineShorts, removeAt, removeLast, keep, drop, clear, saveCS, loadCS, saveStory, evalLineAt, loadStory, makeWin, document]:: are also implemented as class methods, and documented above.
::

private:: hasMovedOn_, hasMovedOn, play, stop, lines, lineShorts, removeAt, removeLast, keep, drop, clear, saveCS, loadCS, saveStory, evalLineAt, loadStory, makeWin, document

method::isCurrent
flag whether this history is History.current

method::makeCurrent
make this history History.current

method::player
the player task for ths history

method::keys
all keys of code authors in this history

method::addLine
add a line to history with current time, id, and code string


method::indicesFor
find line indices created by keys and containing string. used for filtering.

private:: matchKeys, matchString, storyString

Examples::

code::
// same as first example:
History.clear.end;      // clear to start over
History.start;          // starts recording, opens log file

// execute these lines one by one
1 + 2;
p = ProxySpace.push(s.boot);
~a = {Dust.ar([1,1] * 30 ) * 0.3 };
~a.play;
~a.end;

History.end; // History.end ends logging as well.


History.document; // create a document with all the changes
History.showLogFile; // open the log file as it was written.

g = History.makeWin(0@20); // make a gui window, put it where you like
g = History.makeWin(0@20, 5); // number of lines in textview

History.play;                  // posts lines by default
History.play(verbose: false);  // just do it, no posting

// continue recording
History.start;

// enter 5 more lines
10 + 200;
p.push;
~b = { |freq=500| LFDNoise3.ar(freq.dup(2)) * 0.2 };
~b.play;
~b.set(\freq, 1000);
~b.end(2);

History.end;

// save current history to a file.
History.saveCS("~/Desktop/TestHist.scd");
h = History.new.loadCS("~/Desktop/TestHist.scd");
h.lines.printcsAll; "";

// Many History methods are redirected to History.current:

// History.current is where new codelines always go.
h = History.current;
h.lines.printcsAll; "";

// lineshorts are for gui display:
h.lineShorts.printcsAll; "";

// make a simple entry by hand.
History.enter("2 + 2");
h.lines.printcsAll; "";

// one can edit a history:
History.drop(-1); // drop the oldest memory
History.drop(1); // drop the newest memory

h.keep(9); h.lines.printAll; "";
h.drop(3); h.lines.printAll; "";
h.removeLast;       h.lines.printAll;"";
h.removeAt([3, 4]); h.lines.printAll;"";

// more examples
History.clear.start;

1 + 2; // code lines get stored

(nil + 2).postln; // error lines are ignored

// comment-only line is kept, empty lines not:
History.enter("// comment only");
History.enter(" ");


// save and load as text files

History.saveCS; // save as compilestring for reloading.

// save with name, in forward time order.
History.saveCS("~/Desktop/testHist.scd", forward: true);

// load back in from file
h = History.new.loadCS("~/Desktop/testHist.scd", forward: true);
h.lines.postcs; "";

// save as human-readable/hand-playable story
// write all to time-stamped file in historical order:
History.saveStory;

// ... with given filename.
History.saveStory("~/Desktop/myTestStory.scd");

// load from story format file
History.loadStory("~/Desktop/myTestStory.scd");

Document.open("~/Desktop/myTestStory.scd");	// the story file is human-readable.


// Various Internals
// make a new instance of History by hand:
h = History([
	[0, \me, "1+2"],
	[1.234, \me, "q = q ? ();"],
	[3, \me, "\"History\".postln"]]);
h.lines.printcsAll; "";
h.lineShorts.printcsAll; "";

h.play; // play it back
h.stop;


// string formatting utils
h.storyString;
History.formatTime(1234.56);
History.unformatTime("0:20:34.56");

(
History.prettyString("

/* removes line returns at start and end of code strings ... */

").postcs;
)

// convert a line to a short string of n characters for gui display
History.shorten(h.lines.first.postcs, 60).postcs;


// in networked setups, one may turn off local recording and rely on remote recording:
History.recordLocally
History.localOff
History.recordLocally
History.localOn
History.recordLocally


// by default, history always logs here (and makes the folder if not there yet):
History.logFolder;
History.showLogFolder;
History.logPath;
History.showLogFile; // current logfile...
// todo: optionally, one should be able to turn logging off?

// filtering lines, to get subsets of all lines by key and/or searchstring:

// get indices for specific keys
h = History([[0, \me, "a=1+2"], [1, \me, "3+5"], [1.234, \you, "q = q ? ();"], [3, \they, "\"The-story ==== \".postln"]]);
h.keys;
h.matchKeys(\me);
h.matchKeys(\you);
h.matchKeys(\they);
h.matchKeys;        // nil if no test
h.matchKeys(\all);  // all keys match
h.matchKeys([\me, \they])
h.matchKeys(\isidor) // empty array if no line found for this key

h.matchString("The-s");
h.matchString("q");
h.matchString("1+");
h.matchString("the-Story", false); // ignoreCase is false by default
h.matchString("the-Story", true); // ignoreCase

h.indicesFor([\me, \they], "=");	// indices for line written by \me or \her AND containing "=";

// searching is only an interface/access feature,
// so please read on at HistoryGui help ...
h.makeWin;

HistoryGui.help;
::