«Looping Station» by rukano

on 10 Feb'12 19:42 in looper

GUI for recording and playing quantized loops. If you change the tempo, hit on refresh. You can change the output bus for the click (first variable declared) If you have troubles with the font, change it to a font you might have installed, I'm using: Synchro LET You might use MIDI responders to activate the buttons, but you have to write that yourself.

Execute, record, play, have fun

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
var click_out = 0;
var win = Window("Super Looper", Rect(100, 200, 800, 600)).front;
var numbufs = 64;
var layout = win.addFlowLayout((0@0), (0@0));
var container = ();
var size = (40@40);
var metronome = ();
var font = Font("Synchro LET", 18);
var buffer = nil!numbufs;
var durations = [2,4,8,16];
var player = nil!numbufs;
var player_button = (nil!(numbufs/4))!4;
var recorder_button = (nil!(numbufs/4))!4;
var reload_func = {
	var tempo = TempoClock.default.tempo.reciprocal;
	numbufs.do{ |i|
		var slot = floor(i/(numbufs/4));
		buffer[i].free;
		buffer[i] = Buffer.alloc(s, s.sampleRate * durations[slot] * tempo);
	};
};

TempoClock.default.tempo = 90/60;

// Window
win.view.background_(Color.white);

// Controls
StaticText(win, (800@10));

StaticText(win, (100@30))
.font_(font)
.string_(" Tempo:");

NumberBox(win, (100@30))
.align_(\right)
.font_(font)
.step_(0.01)
.scroll_step_(0.1)
.clipLo_(40)
.clipHi_(400)
.value_(TempoClock.default.tempo * 60)
.action_{ |v| TempoClock.default.tempo = (v.value / 60).postln};

StaticText(win, (40@10));
Button(win, (120@30))
.font_(font)
.states_([["Reload", Color.red, Color.white]])
.action_{ reload_func.value };
StaticText(win, (40@10));


StaticText(win, (100@30))
.font_(font)
.align_(\center)
.string_(" Click:");

metronome.button = Button(win, (100@30)).states_([
	["OFF", Color.white, Color.black],
	["ON", Color.white, Color.red(0.75)],	
])
.font_(font)
.action_{ |v|
	if ( v.value.booleanValue )
		{ metronome.player_instance = metronome.player.play(quant:4) }
		{ metronome.player_instance.stop }
};

metronome.display = 4.collect{
	StaticText(win, (15@10));
	UserView(win, (30@30)).background_(Color.red(0.25))
};
StaticText(win, (15@10));
StaticText(win, (800@10));
layout.nextLine;

4.do{ |i| StaticText(win, (200@30)).align_(\center).font_(font).string_(durations[i]) };


// Loopers
4.do{ |i|
	var font = Font("Synchro LET", 14);
	var bsize = 43;
	container[i] = ();
	container[i].view = CompositeView(win, (200@400));
	container[i].view.background_([Color.black, Color.white, Color.black, Color.white][i]);
	container[i].layout = container[i].view.addFlowLayout((5@5),(5@5));
	(numbufs/4).do{ |j|
		var current_buffer = (i * (numbufs/4))+j;
		// REC
		recorder_button[i][j] = Button(container[i].view, (bsize@bsize))
		.font_(font)
		.states_([
			["REC", Color.red, Color.white],
			["-", Color.white, Color.red]
		])
		.action_{ |v|
			("will record buffer: "++current_buffer).postln;
			Pbind(
				\instrument, \buf_recorder,
				\buf, Pseq([buffer[current_buffer]], 1)
			).play(quant:4);
			AppClock.sched(
				(TempoClock.default.tempo.reciprocal * durations[i])
				+ ((TempoClock.default.nextBar - TempoClock.default.beats) * TempoClock.default.beatDur),
				{ v.value_(0) }
			);
		};
		
		// PLAY
		player_button[i][j] = Button(container[i].view, (bsize@bsize))
		.font_(font)
		.states_([
			["PLAY", Color.green, Color.white],
			["STOP", Color.black, Color.green(0.5)]
		])
		.action_{ |v|
			if (v.value.booleanValue) {
				("will play buffer: "++current_buffer).postln;
				buffer[current_buffer].postln;
				player[current_buffer] = Pbind(
					\instrument, \buf_player,
					\buf, buffer[current_buffer],
					\dur, durations[i]
				).play(quant:4);
			} {
				("stopping buffer: "++current_buffer).postln;
				player[current_buffer].stop;
			}
		};
	};
};

StaticText(win, (800@100)).font_(font).string_("Record and play loops in different lengths as you wish.
If you change the tempo, be sure to hit 'refresh'
Have fun!!!");

// Players
metronome.player = Pbind(
	\instrument, \click,
	\freq, Pseq([1000, Pn(500,3)], inf)
);

metronome.display_player = Pbind(
	\type, \setProperties,
	\args, #[\background],
	\receiver, Pstutter(2, Pseq(metronome.display, inf)),
	\background, Pseq([Color.green, Color.red(0.25)], inf),
	\dur, Pseq([9,1]/10, inf)
).play(quant:4);

win.onClose_{
	metronome.display_player.stop;
	metronome.player_instance.stop;
	numbufs.do{ |i| buffer[i].free };
	SystemClock.clear;
	AppClock.clear;
	TempoClock.default.clear;
};

s = Server.default;
s.waitForBoot {

reload_func.value;

SynthDef(\click, { |freq|
	var snd = SinOsc.ar(freq, 0.5pi) * EnvGen.ar(Env.perc(0.001,0.05), doneAction:2);
	OffsetOut.ar(click_out, snd!2);
}).add;

SynthDef(\buf_recorder, { |buf|
	RecordBuf.ar(SoundIn.ar(0), buf, loop:0, doneAction:2)
}).add;

SynthDef(\buf_player, { |out, buf, rate=1|
	var snd = PlayBuf.ar(1, buf, rate, loop:0, doneAction:2);
	OffsetOut.ar(out, snd!2)
}).add;
};
raw 4657 chars (focus & ctrl+a+c to copy)
reception
comments
redFrik user 11 Feb'12 13:02

really nice! though it breaks when the server is not booted before running. reload_func should be changed to waitForBoot

rukano user 11 Feb'12 15:07

changed, thanks!

zecraum user 20 Feb'20 23:37

Super nice and useful!!!!