( //busses ~masterBus = Bus.audio(s, 1); ~guitarBusA = Bus.audio(s, 1); ~guitarBusB = Bus.audio(s, 1); ~accompHighBusA = Bus.audio(s, 1); ~accompHighBusB = Bus.audio(s, 1); ~accompLowBusA = Bus.audio(s, 1); ~accompLowBusB = Bus.audio(s, 1); SynthDef(\masterPlayerControl, { arg sel = 0, masterVol = 1, masterMute = 1, guitarVol = 1, guitarPan = 0, guitarMute = 1, accompHighVol = 1, accompHighPan = 0, accompHighMute = 1, accompLowVol = 1, accompLowPan = 0, accompLowMute = 1; var guitarSig, accompHighSig, accompLowSig, guitarSigPanned, accompHighSigPanned, accompLowSigPanned, masterSig, imp; guitarSig = SelectX.ar(sel, [In.ar(~guitarBusA), In.ar(~guitarBusB)]) * guitarVol; accompHighSig = SelectX.ar(sel, [In.ar(~accompHighBusA), In.ar(~accompHighBusB)]) * accompHighVol; accompLowSig = SelectX.ar(sel, [In.ar(~accompLowBusA), In.ar(~accompLowBusB)]) * accompLowVol; guitarSigPanned = Pan2.ar(guitarSig * guitarMute, guitarPan); accompHighSigPanned = Pan2.ar(accompHighSig * accompHighMute, accompHighPan); accompLowSigPanned = Pan2.ar(accompLowSig * accompLowMute, accompLowPan); masterSig = Mix.ar([guitarSigPanned, accompHighSigPanned, accompLowSigPanned]) * masterVol * masterMute; Out.ar(0, masterSig); imp = Impulse.kr(10); SendReply.kr(imp, '/masterLevels', values: [Amplitude.kr(masterSig)]); SendReply.kr(imp, '/trackLevels', values: [Amplitude.kr(guitarSig), Amplitude.kr(accompHighSig), Amplitude.kr(accompLowSig), DC.ar(0)]); }).add; //~~~~karplus SynthDef(\karplus, {arg freq, gate = 1, amp = 0.5, bus; Out.ar(bus, Pluck.ar(WhiteNoise.ar(0.1), Impulse.kr(0), 220.reciprocal, freq.reciprocal, 10, coef:0) * Linen.kr(gate, doneAction: Done.freeSelf) * amp ) }).add; //~~~~accompaniment SynthDef(\accompBass, {arg freq1 = 100, freq2 = 100, gate = 1, amp = 0.5, bus; var bassDrop; bassDrop = Mix.ar([SinOsc.ar(freq1, 0, 0.5), SinOsc.ar(freq2, 0, 0.5)]) * EnvGen.kr(Env.perc(0.1, 10, level: amp), Impulse.kr(0) + Changed.kr(freq2)); Out.ar(bus, bassDrop) }).add; SynthDef(\accompTreble, {arg freq, gate = 1, sustain, amp, bus; var treble; treble = SinOsc.ar( freq, 0, EnvGen.kr(Env.sine(sustain, amp * 0.1), gate)); Out.ar(bus, treble) }).add; ~droneBus = Bus.audio(s, 1); SynthDef(\drone, { arg out=0, freq=440, amp=0.1, pan=0, gate=1, bus; var z; z = LPF.ar( Mix.new(VarSaw.ar(freq + [0, Rand(-0.4,0.0), Rand(0.0,0.4)], 0, 0.3, 0.3)), XLine.kr(Rand(4000,5000), Rand(2500,3200), 1) ) * Linen.kr(gate, 0.01, 0.7, 0.3, 2); Out.ar(bus, Pan2.ar(z, pan, amp)); }, [\ir]).add; SynthDef(\droneOut, {arg gate, bus; Out.ar([0, 1], Clip.ar(In.ar(bus, 1), -1, 1) * 0.1 * EnvGen.ar(Env.asr(20, 1, 20), gate)) } ).add; ~dronePattern = Pbind( \instrument, \drone, \amp, 0.5, \dur, 0.02, \sustain, 0.05, \freq, Pseq(3000.collect({[[62.midicps, 250], [62.midicps, 250].choose].wchoose([10, 1].normalizeSum)}).flat / 2), \bus, ~droneBus.index ); //~~~~gen music ~genPatterns = {arg guitarSeqIn, accompLowSeqIn, accompHighSeqIn, sectionSeqIn; var calcSustains, genSectionSec, sectionLimits; //~~~~helper sus function calcSustains = {arg stringSeq, durSeq; var res = []; stringSeq.size.do({arg index; var curString, dur, count; if(stringSeq[index].isRest.not, { curString = stringSeq[index]; dur = durSeq[index]; count = 1; while({(stringSeq[(index + count).clip(0, stringSeq.size - 1)] != curString) && (dur < 16) && (count < 100)}, { dur = dur + durSeq[(index + count).clip(0, durSeq.size - 1)]; count = count + 1; }); res = res.add(dur.clip(0, 16)); }, { res.add(Rest()); }); }); res }; genSectionSec = {arg seq, startTime, endTime, type; var durSum, resSeqs, inSecs, mult; //sectionSeq.postln; durSum = 0; resSeqs = []; inSecs = switch(type, 0, {false}, 1, {false}, 2, {true}); mult = if(inSecs, {1}, {0.08}); seq.do({arg item; if(((durSum * mult) >= (startTime * 0.08)) && ((durSum * mult) < (endTime * 0.08)), { var dur = (durSum * mult) - (startTime * 0.08); if((resSeqs.size == 0) && (dur > 0), { switch(type, 0, {resSeqs = resSeqs.add([Rest(-1), Rest(-1), dur])}, 1, {resSeqs = resSeqs.add([Rest(-1), Rest(-1), dur])}, 2, {resSeqs = resSeqs.add([Rest(-1), dur.round(0.08), dur.round(0.08)])}) }); resSeqs = resSeqs.add(item); }); durSum = durSum + if(type == 2, {item[1]}, {item[2]}); }); //if(type == 1, {resSeqs = resSeqs.add([0, 0, 16])}); resSeqs }; sectionLimits = []; sectionSeqIn.slice(nil, 0).add(100000).doAdjacentPairs({arg a, b; sectionLimits = sectionLimits.add([a, b])}); sectionLimits.collect({arg timePair, secIndex; var startTime, endTime, guitarSecSeq, accompLowSecSeq, accompHighSecSeq, stringSeq, fretSeq, durSeq, susSeq, trigSeq, openStrings, pattern; startTime = timePair.postln[0]; endTime = timePair[1]; guitarSecSeq = genSectionSec.value(guitarSeqIn, startTime, endTime, 0); accompLowSecSeq = genSectionSec.value(accompLowSeqIn, startTime, endTime, 1); accompHighSecSeq = genSectionSec.value(accompHighSeqIn, startTime, endTime, 2); if(accompHighSecSeq == [], {accompHighSecSeq = [[Rest(-1), 1, 0], [Rest(-1), 1, 0]]}); guitarSecSeq.postln; accompLowSecSeq.postln; accompHighSecSeq.postln; openStrings = [1/1, 3/2, 2/1, 5/2, 35/12, 7/2]; stringSeq = guitarSecSeq.slice(nil, 0); fretSeq = guitarSecSeq.slice(nil, 1); durSeq = guitarSecSeq.slice(nil, 2); susSeq = calcSustains.value(stringSeq, durSeq); //trigSeq = guitarSeq.slice(nil, 3); //~player = EventPatternProxy.new; pattern = EventPatternProxy.new; pattern.source = Ppar([ Pbind( \instrument, \karplus, \amp, 0.3, \dur, Pseq(durSeq * 0.08), \sustain, Pseq(susSeq * 0.08), \freq, Pseq(stringSeq.collect({arg string, index; if(string.isRest, {Rest()}, { ((62.midicps * openStrings[string]).cpsmidi + fretSeq[index]).midicps})})), \bus, if(secIndex % 2 == 0, {~guitarBusA.index}, {~guitarBusB.index})), if(accompLowSecSeq.size > 1, { Pmono( \accompBass, \amp, 0.5, \freq1, Pseq(accompLowSecSeq.slice(nil, 0)), \freq2, Pseq(accompLowSecSeq.slice(nil, 1)), \dur, Pseq(accompLowSecSeq.slice(nil, 2)) * 0.08, \bus, if(secIndex % 2 == 0, {~accompLowBusA.index}, {~accompLowBusB.index})) }, { Pmono( \accompBass, \amp, 0.5, \freq1, Pseq([accompLowSecSeq[0][0]]), \freq2, Pseq([accompLowSecSeq[0][1]]), \dur, Pseq([accompLowSecSeq[0][2]]) * 0.08, \bus, if(secIndex % 2 == 0, {~accompLowBusA.index}, {~accompLowBusB.index})) }), Pbind( \instrument, \accompTreble, \freq, Pseq(accompHighSecSeq.slice(nil, 0)), \dur, Pseq(accompHighSecSeq.slice(nil, 1)), \sustain, Pseq(accompHighSecSeq.slice(nil, 2)), \amp, 0.5, \bus, if(secIndex % 2 == 0, {~accompHighBusA.index}, {~accompHighBusB.index})) ]); pattern }).postln; }; )