leeloptimist

Step sequencer 0.2

Apr 12th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. autowatch = 1;
  2. outlets = 6;
  3. var m = mgraphics;
  4. m.init();
  5. m.relative_coords = 0;
  6. m.autofill = 0;
  7. m.redraw();
  8.  
  9. //Get size of jsui object
  10. var js_width = box.rect[2] - box.rect[0];
  11. var js_height = box.rect[3] - box.rect[1];
  12.  
  13. ///////////////// Pad Inspector /////////////////////////////////////////////////////////
  14.  
  15. //pad info
  16. var how_many_pad = 16;
  17. var how_many_pad_at_row = 4;
  18. var how_many_pad_at_column = 4;
  19. var selected_pad = 0;
  20. var selected_velocity = 0.755906;
  21. var width = 1 / how_many_pad_at_row * js_width;
  22. var height = 1 / how_many_pad_at_column * js_height;
  23. var space = 2
  24. var RGB = [0.7, 0.25, 0.45];
  25. var RGB_BACKGROUND = [0.15, 0.15, 0.15];
  26. var pad = [];
  27. var last_note = [];
  28. var last_click = [];
  29. var last_velocity = [];
  30.  
  31. function Pad(){ // pad Making Way
  32.  
  33. this.X = (selected_pad % how_many_pad_at_row) * width;
  34. this.Y = Math.floor(selected_pad / how_many_pad_at_column) * height;
  35. this.NOTE = 36 // Default Note output;
  36. this.CLICK = 1; // Default Pad on
  37. this.VELOCITY = 0.755906; // Default Pad Velocity
  38. this.draw = function(){
  39. m.set_source_rgba(RGB_BACKGROUND, this.CLICK); //Pad Background
  40. m.rectangle(this.X + space, this.Y + space, width - (space * 2), height - (space * 2));
  41. m.fill();
  42. m.set_source_rgba(RGB, this.CLICK * this.VELOCITY); //Pad Background
  43. m.rectangle(this.X + space, this.Y + space, width - (space * 2), height - (space * 2));
  44. m.fill();
  45. m.set_source_rgba(1, 1, 1, 0.8); // Pad Boarder
  46. m.rectangle(this.X + space, this.Y + space, width - (space * 2), height - (space * 2));
  47. m.stroke();
  48. }
  49. }
  50.  
  51. function Pad_maker(){ // pad initial making
  52. for (i = 0; i < how_many_pad; i++){
  53. selected_pad = i;
  54. pad[i] = new Pad();
  55. }
  56. m.redraw();
  57. }
  58.  
  59. Pad_maker(); // pad initial
  60.  
  61. function paint(){ // Draw
  62. for (key in pad){
  63. pad[key].draw();
  64. }
  65. }
  66.  
  67. ///////////////// Randomizer & Clear/////////////////////////////////////////////////////////
  68.  
  69. function clear(){ // Clear all steps
  70. for (i = 0; i < how_many_pad; i++){
  71. pad[i].CLICK = 0;
  72. pad[i].VELOCITY = 0;
  73. }
  74. last_list();
  75. m.redraw();
  76. }
  77.  
  78.  
  79. function random(){ // Randomize steps + velocity
  80. for (i = 0; i < how_many_pad; i++){
  81. var y = Math.random();
  82. if(y < 0.5){
  83. y = Math.floor(y)
  84. }
  85. else{
  86. y = Math.ceil(y)
  87. }
  88. pad[i].CLICK = y;
  89. pad[i].VELOCITY = Math.random();
  90. }
  91. last_list();
  92. m.redraw();
  93. }
  94.  
  95. function random_full(){ // Randomize full steps + velocity
  96. for (i = 0; i < how_many_pad; i++){
  97. pad[i].CLICK = 1;
  98. pad[i].VELOCITY = Math.random();
  99. }
  100. last_list();
  101. m.redraw();
  102. }
  103.  
  104. function random_velocity(){ // Randomize velocity only
  105. for (i = 0; i < how_many_pad; i++){
  106. pad[i].VELOCITY = Math.random();
  107. }
  108. last_list();
  109. m.redraw();
  110. }
  111.  
  112. ////////////////// Step Input ////////////////////////////////////////////////////////////
  113.  
  114. function hardware(a, b){
  115. if (b > 0){
  116. pad[a].CLICK = 1;
  117. pad[a].VELOCITY = b / 127
  118. }
  119. else if (b == 0){
  120. pad[a].CLICK = 0;
  121. pad[a].VELOCITY = 0;
  122. }
  123. last_list();
  124. m.redraw();
  125. }
  126.  
  127. function onclick(x, y){ //mouse click
  128. for (i = 0; i < how_many_pad; i++){
  129. if (pad[i].X < x && x < pad[i].X + width && pad[i].Y < y && y < pad[i].Y + height && selected_velocity < 1 ){
  130. pad[i].CLICK = !pad[i].CLICK;
  131. pad[i].VELOCITY = selected_velocity;
  132. }
  133. else if (pad[i].X < x && x < pad[i].X + width && pad[i].Y < y && y < pad[i].Y + height && selected_velocity == 1){
  134. pad[i].CLICK = !pad[i].CLICK;
  135. pad[i].VELOCITY = Math.random();
  136. }
  137. }
  138. last_list();
  139. m.redraw();
  140. }
  141.  
  142. ///////////////// Max Inlet & Outlet /////////////////////////////////////////////////////////
  143.  
  144. function note(){ //note setting Thankx to Thorsten. :)
  145. for (i = 0; i < arguments.length; i++){
  146. pad[i].NOTE = arguments[i];
  147. }
  148. }
  149.  
  150. function velocity(n){ //set velocity
  151. selected_velocity = n;
  152. }
  153.  
  154. function step(n){ // outlet
  155. if (pad[n].CLICK == 1){
  156. outlet(2, Math.ceil(pad[n].VELOCITY * 127));
  157. }
  158. else{
  159. outlet(2, 0);
  160. }
  161. outlet(1, pad[n].CLICK);
  162. outlet(0, pad[n].NOTE);
  163. }
  164.  
  165. function last_list(){ // Thankx to Aaron last list for note / click / velocity of each pad.
  166. last_note = [];
  167. last_click = [];
  168. last_velocity = [];
  169. for (i = 0; i < how_many_pad; i++){
  170. last_note[i] = pad[i].NOTE;
  171. last_click[i] = pad[i].CLICK;
  172. if (pad[i].CLICK == 0){
  173. last_velocity[i] = 0;
  174. }
  175. else{
  176. last_velocity[i] = Math.ceil(pad[i].VELOCITY * 127);
  177. }
  178. }
  179. outlet(3, last_note);
  180. outlet(4, last_click);
  181. outlet(5, last_velocity);
  182. }
Advertisement
Add Comment
Please, Sign In to add comment