Guest User

EuclidToClip

a guest
Oct 27th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. autowatch = 1;
  2.  
  3.  
  4.  
  5. function bang(){
  6.  
  7.     var liveObject = new LiveAPI("live_set tracks 0 clip_slots 0 clip");
  8.      
  9.     // post("path:", liveObject.path);
  10.     // post("\nid:", liveObject.id);
  11.     // post("\nchildren:", liveObject.children);
  12.     // post(liveObject.info);
  13.  
  14.     var noteOne = new Note(48, 0, 0.5, 100, 0);
  15.     var noteTwo = new Note(51, 2, 0.5, 100, 0);
  16.  
  17.     liveObject.call("select_all_notes");
  18.     liveObject.call("replace_selected_notes");
  19.     liveObject.call("notes", 2);
  20.  
  21.     liveObject.call("note", noteOne.pitch, noteOne.start.toFixed(4), noteOne.duration.toFixed(4), noteOne.velocity, noteOne.muted);
  22.     liveObject.call("note", noteTwo.pitch, noteTwo.start.toFixed(4), noteTwo.duration.toFixed(4), noteTwo.velocity, noteTwo.muted);
  23.     liveObject.call("done");
  24.  
  25.     post("done");
  26. }
  27.  
  28. function list()
  29. {
  30.     var a = arrayfromargs(arguments);
  31.  
  32.     var scene = a[2];
  33.    
  34.     var pattern = bjorklund(a[0], a[1]);
  35.  
  36.     post(pattern + "\n");
  37.  
  38.     var altNotes = [];
  39.     altNotes.push("chh");
  40.     altNotes.push("syn");
  41.     altNotes.push("glitch");
  42.     altNotes.push("sn");
  43.  
  44.     var notes = [];
  45.  
  46.     var kiks = [];
  47.     var chh = [];
  48.     var syn = [];
  49.     var glitch = [];
  50.     var snr = [];
  51.  
  52.     var tracks = [];
  53.     tracks.push(kiks);
  54.     tracks.push(chh);
  55.     tracks.push(syn);
  56.     tracks.push(glitch);
  57.     tracks.push(snr);
  58.  
  59.     var kikNote = 60 + getRandomInt(0,20);
  60.     for (var i = 0; i < pattern.length; i++)
  61.     {  
  62.         if (pattern[i] == 1)
  63.         {
  64.             if (Math.random() > 0.4 || i == 0)
  65.             {
  66.                 var track = 1;
  67.                 var time = (i / a[1]) * 4;
  68.                 var midiNote = kikNote;
  69.                 var duration = (4 / a[1]);
  70.                 var n = new Note(midiNote, time, duration, 100, 0);
  71.                 kiks.push(n);
  72.             }
  73.         }
  74.         else if (Math.random() > 0.5)
  75.             {
  76.                 var track = getRandomInt(1,5);
  77.                 var time = (i / a[1]) * 4;
  78.                 var midiNote = 60 + getRandomInt(0,16);
  79.                 var duration = (4 / a[1]);
  80.                 var n = new Note(midiNote, time, duration, 100, 0);
  81.                 tracks[track].push(n);
  82.             }
  83.         else
  84.         {  
  85.             // silence
  86.         }
  87.     }
  88.     // post(tracks);
  89.  
  90.     for (var t = 0; t < tracks.length; t++)
  91.     {
  92.         var liveObject = new LiveAPI("live_set tracks " + (t + 1) + " clip_slots " + scene + " clip");
  93.  
  94.         liveObject.call("select_all_notes");
  95.         liveObject.call("replace_selected_notes");
  96.         liveObject.call("notes", tracks[t].length);
  97.        
  98.         for (var i = 0; i < tracks[t].length; i++)
  99.         {
  100.             liveObject.call("note", tracks[t][i].pitch, tracks[t][i].start.toFixed(4), tracks[t][i].duration.toFixed(4), tracks[t][i].velocity, tracks[t][i].muted);
  101.  
  102.         }
  103.         liveObject.call("done");
  104.         post("finished track arr: " + t + "\n");
  105.     }
  106.  
  107.    
  108. }
  109.  
  110. function GimmeTen()
  111. {
  112.    
  113.     for (var i = 0; i < 10; i++)
  114.     {
  115.         var pulses = getRandomInt(3,15);
  116.        
  117.         list(pulses, 16, i);
  118.        
  119.     }
  120.    
  121. }
  122.  
  123. function bjorklund(pulses, steps)
  124. {
  125.     steps = Math.round(steps);
  126.     pulses = Math.round(pulses);
  127.     if (pulses > steps || pulses == 0 || steps == 0)
  128.     {
  129.         return new Array();
  130.     }
  131.     pattern = [];
  132.     counts = [];
  133.     remainders = [];
  134.     divisor = steps - pulses;
  135.     remainders.push(pulses);
  136.     level = 0;
  137.     while (true)
  138.     {
  139.         counts.push(Math.floor(divisor / remainders[level]));
  140.         remainders.push(divisor % remainders[level]);
  141.         divisor = remainders[level];
  142.         level += 1;
  143.         if (remainders[level] <= 1)
  144.         {
  145.             break;
  146.         }
  147.     }
  148.     counts.push(divisor);
  149.     var r = 0;
  150.     var build = function(level)
  151.     {
  152.         r++;
  153.         if (level > -1)
  154.         {
  155.             for (var i = 0; i < counts[level]; i++)
  156.             {
  157.                 build(level - 1);
  158.             }
  159.             if (remainders[level] != 0)
  160.             {
  161.                 build(level - 2);
  162.             }
  163.         }
  164.         else if (level == -1)
  165.         {
  166.             pattern.push(0);
  167.         }
  168.         else if (level == -2)
  169.         {
  170.             pattern.push(1);
  171.         }
  172.     };
  173.     build(level);
  174.     pattern.reverse();
  175.  
  176.     if (pattern[0] != 1){
  177.         pattern.shift();
  178.         pattern.push(0);
  179.     }
  180.  
  181.     return pattern;
  182. }
  183.  
  184. // UTILITY FUNCTIONS
  185.  
  186. function getRandomInt(min, max)
  187. {
  188.     var float = GetRandomFloat(min,max);
  189.  
  190.     return Math.floor(float);
  191.  
  192. }
  193.  
  194. function GetRandomFloat(min, max)
  195. {
  196.     var float = Math.random() * (max - min) + min;
  197.  
  198.     return float;
  199.  
  200. }
  201.  
  202. function Note(pitch, start, duration, velocity, muted) {
  203.   this.pitch = pitch;
  204.   this.start = start;
  205.   this.duration = duration;
  206.   this.velocity = velocity;
  207.   this.muted = muted;
  208. }
  209.  
Advertisement
Add Comment
Please, Sign In to add comment