«Bossa Nova + PopChord class» by zepadovani

on 16 Nov'16 20:46 in jazzguitarmoogpluckbossabossa novainsensatezchords
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
//based on Andrea Valle class for jazz chords originally posted here: https://gist.github.com/vanderaalle/4a638991d313b20fc638f172e3b29add

//also available here: https://gist.github.com/zepadovani/9f6f714a5dec827be2e0ad11a9e4a552

//Class: (see bossa nova example below)

PopChord {
	var <>symbol, <>root, <>name, <>structure, <>transp ;
	classvar <>symbols ;
	classvar <>decay, <>release ;

	*initClass {
		var t ;
		decay = 0.5;
		release = 0.5 ;
		symbols = () ;
		t = " CM M Cmaj	{0,4,7}
Cm C- Cmin	{0,3,7}
C+ Ca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11	{0, 3, 6, 10, 13, 17}
C°11 Cº11	{0, 3, 6, 9, 13, 16}
CM13 Cmaj13	{0, 4, 7, 11, 14, 17, 21}
C13 Cdom13	{0, 4, 7, 10, 14, 17, 21}
CmM13 C−M13 Cminmaj13	{0, 3, 7, 11, 14, 17, 21}
Cm13 C−13 Cmin13	{0, 3, 7, 10, 14, 17, 21}
C+M13 Caugmaj13	{0, 4, 8, 11, 14, 17, 21}
C+13 C13#5 Caug13	{0, 4, 8, 10, 14, 17, 21}
CØ13	{0, 3, 6, 10, 14, 17, 21}
C6 CM6	{0,4,7,9}
C-6 CM-6 C6- CM6-	{0,4,7,8}
Cm6 Cminmaj6	{0,3,7,9}
Cm-6 Cm6-	{0,3,7,8}
C7#9  C7(#9)	{0, 4, 7, 10, 15}
C7b9  C7(b9)	{0, 4, 7, 10, 13}
C7#11 C7(#11)	{0, 4, 7, 10, 19}
C7b11 C7(b11)	{0, 4, 7, 10, 17}
C7b13 C7(b13)	{0, 4, 7, 10, 20}"
		.split($\n)
		.collect{|i| i.split($\t)}.collect{|i|
			[
				i[0].split($\ ).collect{|j|
//					(j != "C").if({
						j.replace("C", "").asSymbol

//				})
				},
				i[1].replace("{", "[").replace("}", "]").interpret

			]
		}.collect{|ch|
			ch[0].do{|key|
				symbols[key] = ch[1]
			}
		};
//		t[0].add(" ");
/*		t.postln;
		symbols.postln;*/

	}

	*new { arg symbol;
		^super.new.initC(symbol)
	}

	*audio {

		Server.local.waitForBoot{
			SynthDef(\piano, {|note = 60, vol = -6, decay, release|
				Out.ar(0,
					MdaPiano.ar(note.midicps, decay:decay, release:release)* vol.dbamp*Line.kr(1,1,6, doneAction:2))
			}).add

		}
	}

	/*
	~getbass = {arg symbol ;

	var hasdifbass,bass;
	hasdifbass = symbol.includes($/);
	bass = ~getRoot.(symbol.split($/).at(1);
	bass;
	}*/
	initC { arg aSymbol ;
		var data, sus, add ;
		var hasOtherBass=false, bass, bassString, bassIsLetter=false;
		var numBassDict;
		numBassDict = Dictionary.with(*[
			"4".asSymbol->5,
			"4+".asSymbol->6,
			"+4".asSymbol->6,
			"5-".asSymbol->6,
			"-5".asSymbol->6,
			"5°".asSymbol->6,
			"5º".asSymbol->6,
			"5".asSymbol->7,
			"5+".asSymbol->8,
			"+5".asSymbol->8,
			"6".asSymbol->9,
			"7-".asSymbol->9,
			"-7".asSymbol->9,
			"7°".asSymbol->9,
			"7º".asSymbol->9,
			"6+".asSymbol->10,
			"+6".asSymbol->10,
			"7".asSymbol->10,
			"7+".asSymbol->11,
			"+7".asSymbol->11,
			"9-".asSymbol->1,
			"-9".asSymbol->1,
			"9".asSymbol->2,
			"9".asSymbol->2,
			"9+".asSymbol->3,
			"+9".asSymbol->3,
			"-10".asSymbol->3,
			"10-".asSymbol->3,
			"10".asSymbol->4,
			"+10".asSymbol->5,
			"10+".asSymbol->5,
			"11-".asSymbol->4,
			"-11".asSymbol->4,
			"11".asSymbol->5,
			"11+".asSymbol->6,
			"+11".asSymbol->6,
			"13-".asSymbol->8,
			"-13".asSymbol->8,
			"13".asSymbol->9,
			"13+".asSymbol->10,
			"+13".asSymbol->10,
		]);

		symbol = aSymbol ;
		transp = 60 ;
		data =  this.getRoot(symbol.asString) ;
		hasOtherBass = symbol.asString.includes($/);
		root = data[0] ;
		name = data[1];
		//		hasOtherBass.postln;
		hasOtherBass.if({
			structure = symbols[symbol.asString.split($/).at(0).replace(name.asString, "")
				.replace("sus", "@").split($@)[0]
				.replace("add", "@").split($@)[0]
				.asSymbol] ;
			bassString = (symbol.asString.split($/).at(1));
			((bassString.at(0).ascii >= 65) && (bassString.at(0).ascii <= 71)).if({
				bassIsLetter = true;
			});
			bassIsLetter.if({
				bass =  this.getRoot(bassString)[0] - root;
			},{
				bass = numBassDict.at(bassString.asSymbol);
			}
			);
		},{
			structure = symbols[symbol.asString.replace(name.asString, "")
				.replace("sus", "@").split($@)[0]
				.replace("add", "@").split($@)[0]
				.asSymbol] ;
		}
		) ;
//		structure.postln;
		structure = structure.collect({arg i; i.asInteger});
		sus = this.processSus(symbol) ;
		if (sus.notNil) {
			structure.remove(3) ;
			structure.remove(4) ;
			structure.add(sus.asInteger)
		} ;
		add = this.processAdd(symbol) ;
		if (add.notNil) {
			structure.add(add.asInteger)
		} ;

		if (bass.notNil) {
			structure = [bass] ++ structure;
		} ;


		//
	}

	processSus {|symbol|
		var sus = nil ;
		if (symbol.asString.contains("sus")){
			sus = symbol.asString.replace("sus", "@").split($@)[1];
			case
			{sus == ""}{sus = 5}
			{sus == [4]}{sus = 5}
			{sus == [2]}{sus = 2}
		} ;
		^sus
	}

	processAdd {|symbol|
		var add = nil ;
		var base ;
		var dict = (\9: 14, \11: 17, \13: 21) ;
		if (symbol.asString.contains("add")){
			add = symbol.asString.replace("add", "@").split($@)[1];
			base = dict[add.replace("b", "").replace("#", "").asSymbol] ;
			add.postln ;
			case {add.split($b)[1].notNil}{
				add = base-1 ;
				"flatten".postln
			}
			{add.split($#)[1].notNil}{
				add = base+1 ;
				"sharpen".postln
			}
			{(add.split($#)[1].isNil) && (add.split($b)[1].isNil) }
			{add = base;
				"no alt".postln
			}
		} ;
		^add
	}

	// c = C('CMadd9') ; // c.structure

	getRoot  { arg symbol ;
		var chr, act, root, rootName, alt ;
		var noteBase = (\C:0,\D:2,\E:4,\F:5,\G:7,\A:9,\B:11) ;
		name = symbol[0] ;
		root = noteBase[name.asSymbol] ;
		if ([$b, $#].includes(symbol[1]) ){
			name = name++symbol[1] ;
			root = root + [-1,1][[$b, $#].indexOf(symbol[1])]
		} ;
		^[root, name.asSymbol] ;
	}

	play {|vol = -9|
		(transp+structure+root).do{|i|
			Synth(\piano,  [\note, i, \vol, vol, \decay, decay, \release, release])
		}
	}

	chordPitches {arg oct=4, men=0;
		var last;
		var sum = 0;
		var out;
		out = (structure.collect({arg i,j;
			(j == 0).if({
				last = i;
			},{
				(i < last).if({
					sum = sum + 12;
					last = i;
					i = i + sum;
				},{
					i = i + sum;
				}
				);
			});
			i - men
		})) + root + 12 + (oct*12);
		^out
	}


}

/*
(
SynthDef(\moogpluck, {arg outbus=0, freq=440, filter=3, amp=1,coef=0.5,dur=2,legato=1,mix=0,pan=0;
	var pluck,moog,noteOff,out;
	pluck =	Pluck.ar(PinkNoise.ar,1,0.2,freq.reciprocal,dur*legato,coef);
	moog = MoogFF.ar(pluck, (freq*filter),2);
	out = SelectX.ar(mix,[LPF.ar(pluck,2500),moog]);
	noteOff = DetectSilence.ar(out,doneAction:2);
	Out.ar(outbus, Pan2.ar(out,pan));
}).add;
)

(
{var chordnotes,bass,up;
	// https://www.youtube.com/watch?v=PHIe9B5plDI :))
	var insensatez = "Bm7 F#/A# Am6 E7/G# G6 C7M/G C#m7/5- F#7(b13) Bm7 D7/A G#º G7M Em7(9) Bm7 D7/A C#7/G# G7M/5- F#7(b13) Bm7 Bm7 F#/A# Am6 E7/G# G6 C7M C#m7/5- F#7(b13) Bm7 D7/A G#º G7M Em7(9) Bm7 D7/A C#7/G# G7M/5- F#7(b13) Bm7";
	var beatmul = (1!18 ++ 1.2 ++ 1!18 ++ 1.2).flat + ({(0.01).rand2}!insensatez.size);
	var upswing = 0.02;
	var insensatezsplit = insensatez.split($ );
	var insensatezChords = insensatezsplit.collect({arg i; PopChord(i)});

	inf.do({arg j;
		insensatezsplit[j.mod(insensatezsplit.size)].post;
		"\t".post;
		chordnotes = insensatezChords[j.mod(insensatezsplit.size)].chordPitches(2);

		chordnotes.midiname.postln;
		chordnotes = chordnotes;
		bass= [chordnotes[0]] ++ [chordnotes[1]] ++ [chordnotes[0]];
		up= [chordnotes[0]] ++ [chordnotes.copyToEnd(2)] ++ [chordnotes.copyToEnd(2)];

		Pbind(\instrument, \moogpluck,
			\freq, Pseq((bass).midicps,1),
			\amp, Pwhite(-2.0,0,3).dbamp,
			\dur, Pseq([0.5,0.5,1]*beatmul[j.mod(insensatezsplit.size)],1),
			\legato,2,
			\pan, Pwhite(-0.1,-0.3,3),
			\mix, Pwhite(0.2,0.3,3),
		).play;

		Pbind(\instrument, \moogpluck,
			\freq, Pseq(up.midicps,1),
			\amp, Pwhite(-10,-8,3).dbamp,
			\dur,Pseq(([0.5,0.75,0.75]*beatmul[j.mod(insensatezsplit.size)]),1) + Pwhite(0 - upswing,upswing,3),
			\coef,0.2,
			\legato,6,
			\mix, Pwhite(0.7,0.8,3),
			\pan, Pwhite(0.1,0.3,3)
		).play;

		(2*beatmul[j.mod(insensatezsplit.size)]).wait;
	});
}.fork
)
)*/
raw 9121 chars (focus & ctrl+a+c to copy)
reception
comments