Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- autowatch = 1;
- outlets = 1;
- mgraphics.init();
- mgraphics.relative_coords = 0;
- mgraphics.autofill = 0;
- mgraphics.redraw();
- var m = mgraphics;
- var jsui_width = box.rect[2] - box.rect[0];
- var jsui_height = box.rect[3] - box.rect[1];
- var display_ratio = jsui_width / jsui_height;
- var hidden_voice = 1000;
- var voice = 8;
- var drag_zone = 100;
- var space = 0;
- var note_height = jsui_height / voice;
- var each_y = [];
- var each_start = [];
- var each_end = [];
- var each_width = [];
- var R = [];
- var G = [];
- var B = [];
- for (i = 0; i < hidden_voice; i++){ //init.
- each_y[i] = (jsui_height - note_height) - (note_height * i);
- each_start[i] = 0;
- each_end[i] = jsui_width;
- each_width[i] = each_end[i] - each_start[i];
- R[i] = Math.random();
- G[i] = Math.random();
- B[i] = Math.random();
- }
- function voice_number(n){ //voice change
- each_y = [];
- voice = n;
- note_height = jsui_height / voice;
- for (i = 0; i < voice; i++){
- each_y[i] = (jsui_height - note_height) - (note_height * i);
- }
- outlet_maker();
- m.redraw();
- }
- function outlet_maker(){ // make new array for outlet
- for (i = 0; i < voice; i++){
- var start = each_start[i] / jsui_width;
- var end = each_end[i] / jsui_width;
- var length = each_width[i] / jsui_width;
- outlet(0, i, start, end, length);
- }
- }
- function ondrag(x, y){ //drag
- if ( x >= 0 && x <= jsui_width && y >= 0 && y <= jsui_height){
- for (i = 0; i < voice; i++){
- if (y > each_y[i] && y < each_y[i] + note_height && x > each_start[i] - drag_zone && x < each_start[i] + drag_zone && x < each_end[i] - drag_zone){
- each_start[i] = x;
- each_width[i] = each_end[i] - each_start[i];
- }
- }
- }
- if ( x >= 0 && x <= jsui_width && y >= 0 && y <= jsui_height){
- for (i = 0; i < voice; i++){
- if (y > each_y[i] && y < each_y[i] + note_height && x > each_end[i] - drag_zone && x < each_end[i] + drag_zone && x > each_start[i] + drag_zone){
- each_end[i] = x;
- each_width[i] = each_end[i] - each_start[i];
- }
- }
- }
- outlet_maker();
- m.redraw();
- }
- function random_note(){ // note randomizer
- for (i = 0; i < voice; i++){
- each_start[i] = Math.floor(Math.random() * jsui_width);
- each_end[i] = Math.floor(Math.random() * (jsui_width - each_start[i])) + each_start[i];
- each_width[i] = each_end[i] - each_start[i];
- }
- outlet_maker();
- m.redraw();
- }
- function random_start(){ //note start randomizer
- for (i = 0; i < voice; i++){
- each_start[i] = Math.floor(Math.random() * each_end[i]);
- each_width[i] = each_end[i] - each_start[i];
- each_end[i] = each_start[i] + each_width[i];
- }
- outlet_maker();
- m.redraw();
- }
- function random_end(){ //end randomizer
- for (i = 0; i < voice; i++){
- each_width[i] = Math.floor((Math.random() * (jsui_width - each_start[i])))
- each_end[i] = each_start[i] + each_width[i];
- }
- outlet_maker();
- m.redraw();
- }
- function clear_note(){ //clear note
- for (i = 0; i < hidden_voice; i++){
- each_start[i] = 0;
- each_end[i] = jsui_width;
- each_width[i] = each_end[i] - each_start[i];
- }
- outlet_maker();
- m.redraw();
- }
- function space_value(n){
- if (n >= 0 && n <= 10){
- space = n;
- }
- m.redraw();
- }
- function paint(){ //draw
- for (i = 0; i < voice; i++){
- m.set_source_rgba(R[i], G[i], B[i], 0.8);
- m.rectangle(each_start[i], each_y[i] + space, each_width[i], note_height - space);
- m.fill();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement