Advertisement
misingnoglic

random.js

Feb 21st, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. inlets = 1;
  2. outlets = 2;
  3.  
  4. G = [7, 10, 2] //notes of Gm chord
  5. F = [5, 9 , 0]//notes of F chord
  6. D = [2, 6, 9]// notes of D chord
  7.  
  8. bass = [55,53,50] //bass notes (not implemented)
  9.  
  10. //below is dictionary of MIDI number to note name
  11. notes = {0:"C", 1:"C#", 2:"D", 3:"D#", 4:"E", 5:"F", 6:"F#", 7:"G", 9:"A", 10:"Bb", 11:"B"}
  12.  
  13.  
  14. function get_note(mode) {
  15.     //takes a mode and gets a random note as a result
  16.     mode = [G,F,D][mode]//gets the notes of that mode
  17.     note = mode[random(0,3)]; //chooses a random note from the mode
  18.    
  19.     outlet(1,note+(12*random(4,8))); // puts in outlet 1 that note from 4-8 octaves above
  20.     outlet(0,notes[note%12]); //puts the name of that note in outlet 0
  21.  
  22. }
  23.  
  24. function random(min,maximum){
  25.     //simple function that returns a number within the min/max bounds
  26.     return Math.floor(Math.random()*(maximum-min)+min);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement