SHARE
TWEET

fractal speeding up metronome

a guest May 31st, 2018 217 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.     // Set these variables.
  3.     var subdivision = 5; // Must be a whole number.
  4.     var tempoDirection = "up"; // Must be either "up" or "down". Doesn't do anything yet.
  5.     var bars = 60; // Must be a positive whole number.
  6.     var duration = 240; // Must be positive.
  7.     var choruses = 1; // Should be a whole number from 0 to 3.
  8.     var fade = 1; // Should be a whole number from 1 to 3.
  9.     var volume = 0.03; // Must be from 0 to 1.
  10.     var probability = 1; // Must be from 0 to 1. Applicable to percussion sounds only. Doesn't do anything yet.
  11.  
  12.     // Make sure these values are correct.
  13.     var sampleRate = 96000;
  14.     var controlPeriod = 64;
  15.     var screenWidth = 1920;
  16.     var screenHeight = 1080;
  17.     var screenWidthOffset = 0;
  18.     var screenHeightOffset = -1;
  19.     // Check the offsets by uncommenting the two ‘Poll.kr’ lines one-at-a-time and running the resulting block.
  20.     // The values should be from 1 to the number of pixels, with all the numbers being close to a whole number.
  21.     // Otherwise the synth may be out of tune by a pixel.
  22.     // The bottom left corner of the screen should be the one with values of roughly 0.
  23.     // If this is a different corner, enter a negative width/height.
  24.     //Poll.kr(Impulse.kr(100),MouseX.kr(screenWidthOffset + 1, screenWidthOffset + screenWidth + 1)) }.play
  25.     //Poll.kr(Impulse.kr(100),MouseY.kr(screenHeightOffset + 1, screenHeightOffset + screenHeight + 1)) }.play
  26.  
  27.     // Don't mess with these ones.
  28.     var controlRate = sampleRate / controlPeriod;
  29.     var mouseXProportion = MouseX.kr(screenWidthOffset, screenWidthOffset + screenWidth) / (screenWidth - 1);
  30.     var mouseYProportion = MouseY.kr(screenHeightOffset, screenHeightOffset + screenHeight) / (screenHeight - 1);
  31.     var controlSamples = duration * controlRate;
  32.     var chorusProportion = Phasor.kr(0, 1 / controlSamples, 0 - (0.1 / controlSamples), 1 - (0.1 / controlSamples));
  33.     var time = duration * chorusProportion;
  34.     var bar = bars * ((subdivision ** chorusProportion) - 1) / (subdivision - 1);
  35.  
  36.     var subdivision0Count = bar * (subdivision ** (0 + 1));
  37.     var subdivision1Count = bar * (subdivision ** (1 + 1));
  38.     var subdivision2Count = bar * (subdivision ** (2 + 1));
  39.     var subdivision3Count = bar * (subdivision ** (3 + 1));
  40.     var subdivision4Count = bar * (subdivision ** (4 + 1));
  41.     var subdivision5Count = bar * (subdivision ** (5 + 1));
  42.  
  43.     var barRounded = round(bar, 1);
  44.     var subdivision0Rounded = round(subdivision0Count, 1);
  45.     var subdivision1Rounded = round(subdivision1Count, 1);
  46.     var subdivision2Rounded = round(subdivision2Count, 1);
  47.     var subdivision3Rounded = round(subdivision3Count, 1);
  48.     var subdivision4Rounded = round(subdivision4Count, 1);
  49.     var subdivision5Rounded = round(subdivision5Count, 1);
  50.  
  51.     var subdivision0Tick = subdivision0Count - subdivision0Rounded;
  52.     var subdivision1Tick = subdivision1Count - subdivision1Rounded;
  53.     var subdivision2Tick = subdivision2Count - subdivision2Rounded;
  54.     var subdivision3Tick = subdivision3Count - subdivision3Rounded;
  55.     var subdivision4Tick = subdivision4Count - subdivision4Rounded;
  56.     var subdivision5Tick = subdivision5Count - subdivision5Rounded;
  57.  
  58.     var barTrigger = bar - barRounded;
  59.     var subdivision0Trigger = Select.kr(((-0.25 / subdivision) <= barTrigger) * (barTrigger < (0.75 / subdivision)), [subdivision0Tick, -1]);
  60.     var subdivision1Trigger = Select.kr(((-0.25 / subdivision) <= subdivision0Tick) * (subdivision0Tick < (0.75 / subdivision)), [subdivision1Tick, -1]);
  61.     var subdivision2Trigger = Select.kr(((-0.25 / subdivision) <= subdivision1Tick) * (subdivision1Tick < (0.75 / subdivision)), [subdivision2Tick, -1]);
  62.     var subdivision3Trigger = Select.kr(((-0.25 / subdivision) <= subdivision2Tick) * (subdivision2Tick < (0.75 / subdivision)), [subdivision3Tick, -1]);
  63.     var subdivision4Trigger = Select.kr(((-0.25 / subdivision) <= subdivision3Tick) * (subdivision3Tick < (0.75 / subdivision)), [subdivision4Tick, -1]);
  64.     var subdivision5Trigger = Select.kr(((-0.25 / subdivision) <= subdivision4Tick) * (subdivision4Tick < (0.75 / subdivision)), [subdivision5Tick, -1]);
  65.  
  66.     var subdivision0Density = if(0 < choruses,
  67.                                   1,
  68.                                   if(0 < (choruses + fade),
  69.                                      (((subdivision ** ((time / duration) + 0 - choruses - fade)) - 1) * (subdivision ** fade))
  70.                                          / (1 - (subdivision ** fade)),
  71.                                      0));
  72.     var subdivision1Density = if(1 < choruses,
  73.                                   1,
  74.                                   if(1 < (choruses + fade),
  75.                                      (((subdivision ** ((time / duration) + 1 - choruses - fade)) - 1) * (subdivision ** fade))
  76.                                          / (1 - (subdivision ** fade)),
  77.                                      0));
  78.     var subdivision2Density = if(2 < choruses,
  79.                                   1,
  80.                                   if(2 < (choruses + fade),
  81.                                      (((subdivision ** ((time / duration) + 2 - choruses - fade)) - 1) * (subdivision ** fade))
  82.                                          / (1 - (subdivision ** fade)),
  83.                                      0));
  84.     var subdivision3Density = if(3 < choruses,
  85.                                   1,
  86.                                   if(3 < (choruses + fade),
  87.                                      (((subdivision ** ((time / duration) + 3 - choruses - fade)) - 1) * (subdivision ** fade))
  88.                                          / (1 - (subdivision ** fade)),
  89.                                      0));
  90.     var subdivision4Density = if(4 < choruses,
  91.                                   1,
  92.                                   if(4 < (choruses + fade),
  93.                                      (((subdivision ** ((time / duration) + 4 - choruses - fade)) - 1) * (subdivision ** fade))
  94.                                          / (1 - (subdivision ** fade)),
  95.                                      0));
  96.     var subdivision5Density = if(5 < choruses,
  97.                                   1,
  98.                                   if(5 < (choruses + fade),
  99.                                      (((subdivision ** ((time / duration) + 5 - choruses - fade)) - 1) * (subdivision ** fade))
  100.                                          / (1 - (subdivision ** fade)),
  101.                                      0));
  102.  
  103.     var subdivision0PerNote = subdivision0Density / ((subdivision) ** (chorusProportion + 0));
  104.     var subdivision1PerNote = subdivision1Density / ((subdivision) ** (chorusProportion + 1));
  105.     var subdivision2PerNote = subdivision2Density / ((subdivision) ** (chorusProportion + 2));
  106.     var subdivision3PerNote = subdivision3Density / ((subdivision) ** (chorusProportion + 3));
  107.     var subdivision4PerNote = subdivision4Density / ((subdivision) ** (chorusProportion + 4));
  108.     var subdivision5PerNote = subdivision5Density / ((subdivision) ** (chorusProportion + 5));
  109.  
  110.     var barEvent = EnvGen.kr(Env([-0.0001, 1, 0], [0, 0]), barTrigger);
  111.     var subdivision0Event = EnvGen.kr(Env([-0.0001, 1, 0], [0, 0]), subdivision0Trigger) * subdivision0PerNote;
  112.     var subdivision1Event = EnvGen.kr(Env([-0.0001, 1, 0], [0, 0]), subdivision1Trigger) * subdivision1PerNote;
  113.     var subdivision2Event = EnvGen.kr(Env([-0.0001, 1, 0], [0, 0]), subdivision2Trigger) * subdivision2PerNote;
  114.     var subdivision3Event = EnvGen.kr(Env([-0.0001, 1, 0], [0, 0]), subdivision3Trigger) * subdivision3PerNote;
  115.     var subdivision4Event = EnvGen.kr(Env([-0.0001, 1, 0], [0, 0]), subdivision4Trigger) * subdivision4PerNote;
  116.     var subdivision5Event = EnvGen.kr(Env([-0.0001, 1, 0], [0, 0]), subdivision5Trigger) * subdivision5PerNote;
  117.  
  118.     var allEvents = barEvent + subdivision0Event + subdivision1Event + subdivision2Event + subdivision3Event + subdivision4Event + subdivision5Event;
  119.     var allTriggers = Select.kr(allEvents > 0, [-0.5, allEvents]);
  120.  
  121.     var metronome = WhiteNoise.ar(EnvGen.kr(Env([0, allTriggers, 0], [0.01, 0.04], \sin), allTriggers) * volume);
  122.     var output = metronome;
  123.     //Poll.kr(Impulse.kr(100), output)
  124.     [output, output]
  125. }.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