Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- autowatch = 1;
- outlets = 6;
- var m = mgraphics;
- m.init();
- m.relative_coords = 0;
- m.autofill = 0;
- m.redraw();
- //Get size of jsui object
- var js_width = box.rect[2] - box.rect[0];
- var js_height = box.rect[3] - box.rect[1];
- ///////////////// Pad Inspector /////////////////////////////////////////////////////////
- //pad info
- var how_many_pad = 16;
- var how_many_pad_at_row = 4;
- var how_many_pad_at_column = 4;
- var selected_pad = 0;
- var selected_velocity = 0.755906;
- var width = 1 / how_many_pad_at_row * js_width;
- var height = 1 / how_many_pad_at_column * js_height;
- var space = 2
- var RGB = [0.7, 0.25, 0.45];
- var RGB_BACKGROUND = [0.15, 0.15, 0.15];
- var pad = [];
- var last_note = [];
- var last_click = [];
- var last_velocity = [];
- function Pad(){ // pad Making Way
- this.X = (selected_pad % how_many_pad_at_row) * width;
- this.Y = Math.floor(selected_pad / how_many_pad_at_column) * height;
- this.NOTE = 36 // Default Note output;
- this.CLICK = 1; // Default Pad on
- this.VELOCITY = 0.755906; // Default Pad Velocity
- this.draw = function(){
- m.set_source_rgba(RGB_BACKGROUND, this.CLICK); //Pad Background
- m.rectangle(this.X + space, this.Y + space, width - (space * 2), height - (space * 2));
- m.fill();
- m.set_source_rgba(RGB, this.CLICK * this.VELOCITY); //Pad Background
- m.rectangle(this.X + space, this.Y + space, width - (space * 2), height - (space * 2));
- m.fill();
- m.set_source_rgba(1, 1, 1, 0.8); // Pad Boarder
- m.rectangle(this.X + space, this.Y + space, width - (space * 2), height - (space * 2));
- m.stroke();
- }
- }
- function Pad_maker(){ // pad initial making
- for (i = 0; i < how_many_pad; i++){
- selected_pad = i;
- pad[i] = new Pad();
- }
- m.redraw();
- }
- Pad_maker(); // pad initial
- function paint(){ // Draw
- for (key in pad){
- pad[key].draw();
- }
- }
- ///////////////// Randomizer & Clear/////////////////////////////////////////////////////////
- function clear(){ // Clear all steps
- for (i = 0; i < how_many_pad; i++){
- pad[i].CLICK = 0;
- pad[i].VELOCITY = 0;
- }
- last_list();
- m.redraw();
- }
- function random(){ // Randomize steps + velocity
- for (i = 0; i < how_many_pad; i++){
- var y = Math.random();
- if(y < 0.5){
- y = Math.floor(y)
- }
- else{
- y = Math.ceil(y)
- }
- pad[i].CLICK = y;
- pad[i].VELOCITY = Math.random();
- }
- last_list();
- m.redraw();
- }
- function random_full(){ // Randomize full steps + velocity
- for (i = 0; i < how_many_pad; i++){
- pad[i].CLICK = 1;
- pad[i].VELOCITY = Math.random();
- }
- last_list();
- m.redraw();
- }
- function random_velocity(){ // Randomize velocity only
- for (i = 0; i < how_many_pad; i++){
- pad[i].VELOCITY = Math.random();
- }
- last_list();
- m.redraw();
- }
- ////////////////// Step Input ////////////////////////////////////////////////////////////
- function hardware(a, b){
- if (b > 0){
- pad[a].CLICK = 1;
- pad[a].VELOCITY = b / 127
- }
- else if (b == 0){
- pad[a].CLICK = 0;
- pad[a].VELOCITY = 0;
- }
- last_list();
- m.redraw();
- }
- function onclick(x, y){ //mouse click
- for (i = 0; i < how_many_pad; i++){
- if (pad[i].X < x && x < pad[i].X + width && pad[i].Y < y && y < pad[i].Y + height && selected_velocity < 1 ){
- pad[i].CLICK = !pad[i].CLICK;
- pad[i].VELOCITY = selected_velocity;
- }
- else if (pad[i].X < x && x < pad[i].X + width && pad[i].Y < y && y < pad[i].Y + height && selected_velocity == 1){
- pad[i].CLICK = !pad[i].CLICK;
- pad[i].VELOCITY = Math.random();
- }
- }
- last_list();
- m.redraw();
- }
- ///////////////// Max Inlet & Outlet /////////////////////////////////////////////////////////
- function note(){ //note setting Thankx to Thorsten. :)
- for (i = 0; i < arguments.length; i++){
- pad[i].NOTE = arguments[i];
- }
- }
- function velocity(n){ //set velocity
- selected_velocity = n;
- }
- function step(n){ // outlet
- if (pad[n].CLICK == 1){
- outlet(2, Math.ceil(pad[n].VELOCITY * 127));
- }
- else{
- outlet(2, 0);
- }
- outlet(1, pad[n].CLICK);
- outlet(0, pad[n].NOTE);
- }
- function last_list(){ // Thankx to Aaron last list for note / click / velocity of each pad.
- last_note = [];
- last_click = [];
- last_velocity = [];
- for (i = 0; i < how_many_pad; i++){
- last_note[i] = pad[i].NOTE;
- last_click[i] = pad[i].CLICK;
- if (pad[i].CLICK == 0){
- last_velocity[i] = 0;
- }
- else{
- last_velocity[i] = Math.ceil(pad[i].VELOCITY * 127);
- }
- }
- outlet(3, last_note);
- outlet(4, last_click);
- outlet(5, last_velocity);
- }
Advertisement
Add Comment
Please, Sign In to add comment