Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- autowatch = 1;
- function bang(){
- var liveObject = new LiveAPI("live_set tracks 0 clip_slots 0 clip");
- // post("path:", liveObject.path);
- // post("\nid:", liveObject.id);
- // post("\nchildren:", liveObject.children);
- // post(liveObject.info);
- var noteOne = new Note(48, 0, 0.5, 100, 0);
- var noteTwo = new Note(51, 2, 0.5, 100, 0);
- liveObject.call("select_all_notes");
- liveObject.call("replace_selected_notes");
- liveObject.call("notes", 2);
- liveObject.call("note", noteOne.pitch, noteOne.start.toFixed(4), noteOne.duration.toFixed(4), noteOne.velocity, noteOne.muted);
- liveObject.call("note", noteTwo.pitch, noteTwo.start.toFixed(4), noteTwo.duration.toFixed(4), noteTwo.velocity, noteTwo.muted);
- liveObject.call("done");
- post("done");
- }
- function list()
- {
- var a = arrayfromargs(arguments);
- var scene = a[2];
- var pattern = bjorklund(a[0], a[1]);
- post(pattern + "\n");
- var altNotes = [];
- altNotes.push("chh");
- altNotes.push("syn");
- altNotes.push("glitch");
- altNotes.push("sn");
- var notes = [];
- var kiks = [];
- var chh = [];
- var syn = [];
- var glitch = [];
- var snr = [];
- var tracks = [];
- tracks.push(kiks);
- tracks.push(chh);
- tracks.push(syn);
- tracks.push(glitch);
- tracks.push(snr);
- var kikNote = 60 + getRandomInt(0,20);
- for (var i = 0; i < pattern.length; i++)
- {
- if (pattern[i] == 1)
- {
- if (Math.random() > 0.4 || i == 0)
- {
- var track = 1;
- var time = (i / a[1]) * 4;
- var midiNote = kikNote;
- var duration = (4 / a[1]);
- var n = new Note(midiNote, time, duration, 100, 0);
- kiks.push(n);
- }
- }
- else if (Math.random() > 0.5)
- {
- var track = getRandomInt(1,5);
- var time = (i / a[1]) * 4;
- var midiNote = 60 + getRandomInt(0,16);
- var duration = (4 / a[1]);
- var n = new Note(midiNote, time, duration, 100, 0);
- tracks[track].push(n);
- }
- else
- {
- // silence
- }
- }
- // post(tracks);
- for (var t = 0; t < tracks.length; t++)
- {
- var liveObject = new LiveAPI("live_set tracks " + (t + 1) + " clip_slots " + scene + " clip");
- liveObject.call("select_all_notes");
- liveObject.call("replace_selected_notes");
- liveObject.call("notes", tracks[t].length);
- for (var i = 0; i < tracks[t].length; i++)
- {
- 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);
- }
- liveObject.call("done");
- post("finished track arr: " + t + "\n");
- }
- }
- function GimmeTen()
- {
- for (var i = 0; i < 10; i++)
- {
- var pulses = getRandomInt(3,15);
- list(pulses, 16, i);
- }
- }
- function bjorklund(pulses, steps)
- {
- steps = Math.round(steps);
- pulses = Math.round(pulses);
- if (pulses > steps || pulses == 0 || steps == 0)
- {
- return new Array();
- }
- pattern = [];
- counts = [];
- remainders = [];
- divisor = steps - pulses;
- remainders.push(pulses);
- level = 0;
- while (true)
- {
- counts.push(Math.floor(divisor / remainders[level]));
- remainders.push(divisor % remainders[level]);
- divisor = remainders[level];
- level += 1;
- if (remainders[level] <= 1)
- {
- break;
- }
- }
- counts.push(divisor);
- var r = 0;
- var build = function(level)
- {
- r++;
- if (level > -1)
- {
- for (var i = 0; i < counts[level]; i++)
- {
- build(level - 1);
- }
- if (remainders[level] != 0)
- {
- build(level - 2);
- }
- }
- else if (level == -1)
- {
- pattern.push(0);
- }
- else if (level == -2)
- {
- pattern.push(1);
- }
- };
- build(level);
- pattern.reverse();
- if (pattern[0] != 1){
- pattern.shift();
- pattern.push(0);
- }
- return pattern;
- }
- // UTILITY FUNCTIONS
- function getRandomInt(min, max)
- {
- var float = GetRandomFloat(min,max);
- return Math.floor(float);
- }
- function GetRandomFloat(min, max)
- {
- var float = Math.random() * (max - min) + min;
- return float;
- }
- function Note(pitch, start, duration, velocity, muted) {
- this.pitch = pitch;
- this.start = start;
- this.duration = duration;
- this.velocity = velocity;
- this.muted = muted;
- }
Advertisement
Add Comment
Please, Sign In to add comment