SHARE
TWEET

general metronome

a guest Jul 5th, 2018 205 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // General Metronome v2018-07-01-A
  2. // Bloated metronome by Thomas Howe (thomashowemain@gmail.com)
  3.  
  4. // Set the Post window size to display 5 lines at a time.
  5. // Item 1: seconds elapsed
  6. // Item 2: current unadjusted BPM (will change if ‘slope’ is set to 1)
  7. // Item 3: rubato (will change if ‘variation’ is set to 1)
  8. // Item 4: current BPM
  9. // Item 5: current beat of bar (starting at 0)
  10.  
  11. // Set these variables.
  12. var amplitudeMultiplier = 0.05;
  13. var beatsPerBar = 4;
  14. var startBPM = 120;
  15. var slope = 0; // 0 = off, 1 = on
  16. var targetBPM = 121;
  17. var durationInSeconds = 60;
  18. var variation = 0; // 0 = off, 1 = on
  19. var variationNewGoalTimeLo = 5;
  20. var variationNewGoalTimeHi = 10;
  21. var variationOctaveLo = -0.05;
  22. var variationOctaveHi = 0.05;
  23.  
  24. // Set these metronome hits in beat offsets, and amplitudes.
  25. var hit00 = [0, 0.25];
  26. var hit01 = [1, 1];
  27. var hit02 = [2, 0.7];
  28. var hit03 = [3, 1];
  29. var hit04 = [0.63, 0.75];
  30. var hit05 = [1.63, 0.75];
  31. var hit06 = [2.63, 0.75];
  32. var hit07 = [3.63, 0.75];
  33. var hit08 = [0, 0];
  34. var hit09 = [0, 0];
  35. var hit10 = [0, 0];
  36. var hit11 = [0, 0];
  37. var hit12 = [0, 0];
  38. var hit13 = [0, 0];
  39. var hit14 = [0, 0];
  40. var hit15 = [0, 0];
  41. var hit16 = [0, 0];
  42. var hit17 = [0, 0];
  43. var hit18 = [0, 0];
  44. var hit19 = [0, 0];
  45.  
  46. // Tempo variation.
  47.     // samples remaining till new samples remaining time is chosen, minus 2
  48.     var fallerKR = {
  49.         arg min = 1, max = 2;
  50.         var buffer = Buffer.alloc(s, 1);
  51.         var random = round(((WhiteNoise.kr(0.5, 0.5) * (max - min)) + min) * s.sampleRate / s.options.blockSize, 1) - 2;
  52.         var previous = PlayBuf.kr(1, buffer);
  53.         var current = Select.kr(previous < 0, [previous - 1, random]);
  54.         RecordBuf.kr(current, buffer);
  55.         current;
  56.     };
  57.     // picks new point every fallerKR trigger
  58.     var stochasticLine = {
  59.         arg faller = fallerKR.value, min = -1, max = 1;
  60.         var buffer = Buffer.alloc(s, 1);
  61.         var random = TRand.kr(min, max, faller);
  62.         var previous = PlayBuf.kr(1, buffer);
  63.         var current = ((random - previous) / (faller + 2)) + previous;
  64.         RecordBuf.kr(current, buffer);
  65.         current;
  66.     };
  67.  
  68. {
  69.     // Don't mess with these ones.
  70.     var variationSamplesTillNextGoal = fallerKR.value(variationNewGoalTimeLo, variationNewGoalTimeHi);
  71.     var variationOctave = stochasticLine.value(variationSamplesTillNextGoal, variationOctaveLo, variationOctaveHi) * variation;
  72.     var tempoMultiplier = 2 ** variationOctave;
  73.     var secondsElapsed = Sweep.kr;
  74.     var bPSRadix = targetBPM / startBPM;
  75.     var bPSExponent = slope * secondsElapsed / durationInSeconds;
  76.     var unadjustedBPM = startBPM * (bPSRadix ** bPSExponent);
  77.     var currentBPM = tempoMultiplier * unadjustedBPM;
  78.     var currentBarsPS = currentBPM / (60 * beatsPerBar);
  79.     var lastHit = [hit00[0], hit01[0], hit02[0], hit03[0], hit04[0], hit05[0], hit06[0], hit07[0], hit08[0], hit09[0],
  80.                    hit10[0], hit11[0], hit12[0], hit13[0], hit14[0], hit15[0], hit16[0], hit17[0], hit18[0], hit19[0]].maxItem;
  81.     var firstBeat = ((lastHit / beatsPerBar) - 1) / 2;
  82.     var pushedBarProportion = Phasor.kr(0, (currentBarsPS / (s.sampleRate / s.options.blockSize)), firstBeat, firstBeat + 1);
  83.  
  84.     // Hit envelopes.
  85.     var hitEnv00 = EnvGen.kr(Env([0, hit00[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit00[0] / beatsPerBar));
  86.     var hitEnv01 = EnvGen.kr(Env([0, hit01[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit01[0] / beatsPerBar));
  87.     var hitEnv02 = EnvGen.kr(Env([0, hit02[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit02[0] / beatsPerBar));
  88.     var hitEnv03 = EnvGen.kr(Env([0, hit03[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit03[0] / beatsPerBar));
  89.     var hitEnv04 = EnvGen.kr(Env([0, hit04[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit04[0] / beatsPerBar));
  90.     var hitEnv05 = EnvGen.kr(Env([0, hit05[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit05[0] / beatsPerBar));
  91.     var hitEnv06 = EnvGen.kr(Env([0, hit06[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit06[0] / beatsPerBar));
  92.     var hitEnv07 = EnvGen.kr(Env([0, hit07[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit07[0] / beatsPerBar));
  93.     var hitEnv08 = EnvGen.kr(Env([0, hit08[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit08[0] / beatsPerBar));
  94.     var hitEnv09 = EnvGen.kr(Env([0, hit09[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit09[0] / beatsPerBar));
  95.     var hitEnv10 = EnvGen.kr(Env([0, hit10[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit10[0] / beatsPerBar));
  96.     var hitEnv11 = EnvGen.kr(Env([0, hit11[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit11[0] / beatsPerBar));
  97.     var hitEnv12 = EnvGen.kr(Env([0, hit12[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit12[0] / beatsPerBar));
  98.     var hitEnv13 = EnvGen.kr(Env([0, hit13[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit13[0] / beatsPerBar));
  99.     var hitEnv14 = EnvGen.kr(Env([0, hit14[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit14[0] / beatsPerBar));
  100.     var hitEnv15 = EnvGen.kr(Env([0, hit15[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit15[0] / beatsPerBar));
  101.     var hitEnv16 = EnvGen.kr(Env([0, hit16[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit16[0] / beatsPerBar));
  102.     var hitEnv17 = EnvGen.kr(Env([0, hit17[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit17[0] / beatsPerBar));
  103.     var hitEnv18 = EnvGen.kr(Env([0, hit18[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit18[0] / beatsPerBar));
  104.     var hitEnv19 = EnvGen.kr(Env([0, hit19[1], 0], [0.01, 0.04], \sin), pushedBarProportion - (hit19[0] / beatsPerBar));
  105.     var allEnvs = hitEnv00 + hitEnv01 + hitEnv02 + hitEnv03 + hitEnv04
  106.                 + hitEnv05 + hitEnv06 + hitEnv07 + hitEnv08 + hitEnv09
  107.                 + hitEnv10 + hitEnv11 + hitEnv12 + hitEnv13 + hitEnv14
  108.                 + hitEnv15 + hitEnv16 + hitEnv17 + hitEnv18 + hitEnv19;
  109.  
  110.     // Output.
  111.     var metronome = WhiteNoise.ar(allEnvs * amplitudeMultiplier);
  112.     var currentBeat = Wrap.kr(pushedBarProportion, 0, 1) * beatsPerBar;
  113.     var display = [secondsElapsed, unadjustedBPM, variationOctave, currentBPM, currentBeat];
  114.     Poll.kr(Impulse.kr(13), display);
  115.     [metronome, metronome];
  116. }.play
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top