-
Notifications
You must be signed in to change notification settings - Fork 3
/
MixerRecorder.sc
99 lines (87 loc) · 2.59 KB
/
MixerRecorder.sc
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
MixerRecorder {
// a reduced version of RecNodeProxy to work better with MixerChannels
classvar <dir; // = "sounds/";
var <mixer, <buffer, <path, <synth, <running = false;
*initClass {
StartUp.add {
this.dir = thisProcess.platform.recordingsDir;
}
}
*dir_ { |path|
dir = path;
(dir.last != thisProcess.platform.pathSeparator).if({
dir = dir ++ thisProcess.platform.pathSeparator;
});
}
*new { arg mixer, path, headerFormat = "aiff", sampleFormat = "float";
^super.new.init(mixer, path, headerFormat, sampleFormat);
}
init { arg mix, p, head, samp;
mixer = mix;
mixer.server.serverRunning.not.if({ "server not running".inform; ^this });
buffer.notNil.if({ "already recording. use pause/unpause".inform; ^this });
// if no name provided, name it after the mixer with a timestamp
path = p ?? { dir ++ mixer.name ++ Main.elapsedTime.trunc
++ "." ++ head };
buffer = Buffer.alloc(mixer.server, 65536, mixer.outChannels);
buffer.write(path, head, samp, 0, 0, true);
("Prepared for recording: " ++ path).postln;
CmdPeriod.add(this);
}
cmdPeriod {
CmdPeriod.remove(this);
this.close;
}
record { arg paused = false;
var bus;
buffer.isNil.if({ this.init });
// should not create a synth if already recording
synth.isNil.if({
bus = mixer.inbus;
synth = Synth.basicNew("mixers/Rec" ++ mixer.outChannels, mixer.server,
mixer.server.nodeAllocator.allocPerm);
mixer.server.sendBundle(nil, synth.newMsg(mixer.fadergroup,
[\i_in, bus.index, \i_bufNum, buffer.bufnum], \addToTail));
paused.if({
this.pause;
}, {
running = true;
("******** Recording begun: " ++ path).postln;
});
mixer.mcgui !? { mixer.mcgui.updateView(\record, mixer.isRecording.binaryValue) };
});
}
pause {
synth.notNil.if({
synth.run(false);
("******** Recording paused: " ++ path).postln;
});
running = false;
mixer.mcgui !? { mixer.mcgui.updateView(\record, mixer.isRecording.binaryValue) };
}
unpause {
synth.notNil.if({
synth.run(true);
("******** Recording resumed: " ++ path).postln;
running = true;
});
mixer.mcgui !? { mixer.mcgui.updateView(\record, mixer.isRecording.binaryValue) };
}
close {
synth.notNil.if({
synth.free;
synth.server.nodeAllocator.freePerm(synth.nodeID);
synth = nil;
});
buffer.notNil.if({
("******** Recording ended. File closed: " ++ path).postln;
buffer.close;
});
mixer.mcgui !? { mixer.mcgui.updateView(\record, false.binaryValue) };
path = nil;
buffer.free;
buffer = nil;
running = false;
CmdPeriod.remove(this); // does not need to respond to cmd-. any more
}
}