SHARE
TWEET

Music App Code

a guest Oct 8th, 2019 104 in 299 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //import cassette.audiofiles.*;
  2.  
  3. import processing.sound.*;
  4.  
  5. PImage backgroundImg, logo, scroll, scroll2, playButton, backButton, pauseButton, musicButton, ambianceButton, speechButton, mute, resume, topBarBack, topBarFront, bottomBar, circleImg;
  6.  
  7. int mode, category/*page1, page2, page3, */;
  8. float insetThin, volume1=0.5, volume2=0.5, volume3=0.5;
  9. boolean muted, pressed;
  10.  
  11. ScrollBox scrollBox1, scrollBox2, scrollBox3;
  12. int[] music = {3, 7, 9, 10, 11};
  13. int[] ambiance = {0, 1, 2};
  14. int[] sounds = {4, 5, 6, 8};
  15.  
  16. SoundFile[] Sounds = new SoundFile[12];
  17. String[] soundNames = {"Taberna", "Dungeons", "Bosque", "Musica de Batalla", "Puerta cerrandose", "Pisadas", "Sonido persona", "Star Wars Cantina", "Caballo", "Kingdom Hearts 1", "Kingdom Hearts 2", "NieR Automata"};
  18. String[] fileNames = {"Ambience_Tavern.wav", "Ambiance_Dungeon.wav", "Ambience_Forest1.wav", "Music_Battle1.wav", "Sound_DoorClose.wav", "Sound_Footsteps.wav", "Sound_Grunt.wav", "Music_StarWarsCantina.wav", "Sounds_Horse.wav", "Music_KingdomHearts1.wav", "Music_KingdomHearts2.wav", "Music_NieRAutomata.wav"};
  19.  
  20. void setup() {
  21.   fullScreen(P2D);
  22.   //size(500, 900);
  23.   orientation(PORTRAIT);
  24.   noStroke();
  25.   fill(0);
  26.   imageMode(CORNERS);
  27.   backgroundImg = loadImage ("OldPaper.jpg");
  28.   backgroundImg.resize(width, height);
  29.   logo = loadImage ("PathfinderLogo.png");
  30.   insetThin=width/8;
  31.   image(backgroundImg, 0, 0, width, height);
  32.   image(logo, width/14, height/20, width-width/14, height/10*1.5);
  33.   scroll = loadImage ("scroll.png");
  34.   scroll2 = loadImage ("scroll2.png");
  35.   playButton = loadImage ("Media-Play.png");
  36.   backButton = loadImage ("Previous.png");
  37.   pauseButton = loadImage ("Pause.png");
  38.   musicButton = loadImage ("Music.png");
  39.   ambianceButton = loadImage ("Noise.png");
  40.   speechButton = loadImage ("Speech.png");
  41.   mute = loadImage ("Mute.png");
  42.   resume = loadImage ("Resume.png");
  43.   scrollBox1 = new ScrollBox(music, false);
  44.   scrollBox2 = new ScrollBox(ambiance, false);
  45.   scrollBox3 = new ScrollBox(sounds, false);
  46.   topBarBack = loadImage ("TopBar1.png");
  47.   topBarFront = loadImage ("TopBar2.png");
  48.   bottomBar = loadImage("BottomBar.png");
  49.   circleImg = loadImage("Circle.png");
  50. }
  51.  
  52. void draw() {
  53.   image(backgroundImg, 0, 0, width, height);
  54.   if (mode==0) {
  55.     image(logo, width/14, height/20, width-width/14, height/10*1.5);
  56.     image(scroll, insetThin, height/10*3, width-insetThin, height/10*5.5);
  57.     image(scroll2, insetThin, height/10*6, width-insetThin, height/10*8.5);
  58.   } else if (mode==1) {
  59.     image(backButton, 0, 0, width/7, height/10);
  60.     fill(0, 0, 0, 80);
  61.     rectMode(RADIUS);
  62.     image(topBarBack, width/7*1.9, 0, width/7*5, height/11.6);
  63.     switch(category) {
  64.     case 0:
  65.       image(topBarFront, -width/7*2, 0, width+width/7*0.2, height/11);
  66.       break;
  67.     case 1:
  68.       image(topBarFront, -width/7, 0, width/7*8.2, height/11);
  69.       break;
  70.     case 2:
  71.       image(topBarFront, 0, 0, width/7*9.2, height/11);
  72.       break;
  73.     }
  74.     image(musicButton, width/7*2, 0, width/7*3, height/10);
  75.     image(ambianceButton, width/7*3, 0, width/7*4, height/10);
  76.     image(speechButton, width/7*4, 0, width/7*5, height/10);
  77.     image(mute, width/7*6, 0, width, height/10);
  78.     switch(category) {
  79.     case 0:
  80.       scrollBox1.draw();
  81.       break;
  82.     case 1:
  83.       scrollBox2.draw();
  84.       break;
  85.     case 2:
  86.       scrollBox3.draw();
  87.       break;
  88.     }
  89.     image(bottomBar, width/7, height-height/15, width/7*6, height);
  90.     fill(74, 48, 34);
  91.     strokeWeight(20);
  92.     imageMode(CENTER);
  93.     if (mousePressed) {
  94.       if (mouseY>height-height/20 && mouseX>width/4 && mouseX<width/4*3) {
  95.         switch(category) {
  96.         case 0:
  97.           volume1 = map(mouseX, width/4, width/4*3, 0, 1);
  98.           for (int a = 0; a<scrollBox1.playing.length; a++) {
  99.             if (scrollBox1.playing[a]==true)Sounds[music[a]].amp(volume1);
  100.           }
  101.           break;
  102.         case 1:
  103.           volume2 = map(mouseX, width/4, width/4*3, 0, 1);
  104.           for (int a = 0; a<scrollBox2.playing.length; a++) {
  105.             if (scrollBox2.playing[a]==true)Sounds[ambiance[a]].amp(volume2);
  106.           }
  107.           break;
  108.         case 2:
  109.           volume3 = map(mouseX, width/4, width/4*3, 0, 1);
  110.           for (int a = 0; a<scrollBox3.playing.length; a++) {
  111.             if (scrollBox3.playing[a]==true)Sounds[sounds[a]].amp(volume3);
  112.           }
  113.           break;
  114.         }
  115.       }
  116.     }
  117.     switch(category) {
  118.     case 0:
  119.       image(circleImg, width/2*map(volume1, 0, 1, 0.5, 1.5), height-height/30, width/15, width/15);
  120.       break;
  121.     case 1:
  122.       image(circleImg, width/2*map(volume2, 0, 1, 0.5, 1.5), height-height/30, width/15, width/15);
  123.       break;
  124.     case 2:
  125.       image(circleImg, width/2*map(volume3, 0, 1, 0.5, 1.5), height-height/30, width/15, width/15);
  126.       break;
  127.     }
  128.     imageMode(CORNERS);
  129.   } else if (mode==2) {
  130.     image(backButton, 0, 0, width/7, height/10);
  131.   }
  132. }
  133.  
  134. void mousePressed() {
  135.   if (mode==0) {
  136.     if (mouseX>insetThin && mouseX<width-insetThin) {
  137.       if (mouseY>height/10*3 && mouseY<height/10*5.5) {
  138.         mode=1;
  139.         switch(category) {
  140.         case 0:
  141.           scrollBox1.visible=true;
  142.           break;
  143.         case 1:
  144.           scrollBox2.visible=true;
  145.           break;
  146.         case 2:
  147.           scrollBox3.visible=true;
  148.           break;
  149.         }
  150.       } else if (mouseY>height/10*6 && mouseY<height/10*8.5)mode=2;
  151.     }
  152.   } else if (mode==1) {
  153.     if (mouseY<height/10) {
  154.       if (mouseX<width/7) {
  155.         scrollBox1.visible=false;
  156.         scrollBox2.visible=false;
  157.         scrollBox3.visible=false;
  158.         mode=0;
  159.       } else if (mouseX>width/7*2 && mouseX<width/7*3) {
  160.         category=0;
  161.         scrollBox1.visible=true;
  162.         scrollBox2.visible=false;
  163.         scrollBox3.visible=false;
  164.       } else if (mouseX>width/7*3 && mouseX<width/7*4) {
  165.         category=1;
  166.         scrollBox2.visible=true;
  167.         scrollBox1.visible=false;
  168.         scrollBox3.visible=false;
  169.       } else if (mouseX>width/7*4 && mouseX<width/7*5) {
  170.         category=2;
  171.         scrollBox3.visible=true;
  172.         scrollBox2.visible=false;
  173.         scrollBox1.visible=false;
  174.       }
  175.     } else if (mouseY>height/10 && mouseY < height-height/15) {
  176.       if (mouseX<insetThin*1.5+width/11 && mouseX>insetThin) {
  177.         switch(category) {
  178.         case 0:
  179.           for (int p=0; p<music.length; p++) {
  180.             if (mouseY>scrollBox1.topPos[p] && mouseY<scrollBox1.topPos[p+1]) {
  181.               playMusic(music[p], p, 1);
  182.               break;
  183.             }
  184.           }
  185.           break;
  186.         case 1:
  187.           for (int p=0; p<ambiance.length; p++) {
  188.             if (mouseY>scrollBox2.topPos[p] && mouseY<scrollBox2.topPos[p+1]) {
  189.               playMusic(ambiance[p], p, 2);
  190.               break;
  191.             }
  192.           }
  193.           break;
  194.         case 2:
  195.  
  196.           for (int p=0; p<sounds.length; p++) {
  197.             if (mouseY>scrollBox3.topPos[p] && mouseY<scrollBox3.topPos[p+1]) {
  198.               playMusic(sounds[p], p, 3);
  199.               break;
  200.             }
  201.           }
  202.           break;
  203.         }
  204.       }
  205.     }
  206.   } else if (mode==2) {
  207.     if (mouseY<height/10 && mouseX<width/30*6) {
  208.       mode=0;
  209.     }
  210.   }
  211. }
  212.  
  213. void playMusic(int Soundnum, int Soundpos, int cat) {
  214.   if (Sounds[Soundnum]==null) {
  215.     Sounds[Soundnum]= new SoundFile(this, fileNames[Soundnum]);
  216.   }
  217.  
  218.   switch(cat) {
  219.   case 1:
  220.     if (scrollBox1.playing[Soundpos]) {
  221.       Sounds[Soundnum].stop();
  222.       scrollBox1.playing[Soundpos]=false;
  223.     } else {
  224.       Sounds[Soundnum].loop();
  225.       Sounds[Soundnum].amp(volume1);
  226.       scrollBox1.playing[Soundpos]=true;
  227.     }
  228.     break;
  229.   case 2:
  230.     if (scrollBox2.playing[Soundpos]) {
  231.       Sounds[Soundnum].stop();
  232.       scrollBox2.playing[Soundpos]=false;
  233.     } else {
  234.       Sounds[Soundnum].loop();
  235.       Sounds[Soundnum].amp(volume2);
  236.       scrollBox2.playing[Soundpos]=true;
  237.     }
  238.     break;
  239.   case 3:
  240.     if (scrollBox3.playing[Soundpos]) {
  241.       Sounds[Soundnum].stop();
  242.       scrollBox3.playing[Soundpos]=false;
  243.     } else {
  244.       Sounds[Soundnum].loop();
  245.       Sounds[Soundnum].amp(volume3);
  246.       scrollBox3.playing[Soundpos]=true;
  247.     }
  248.     break;
  249.   }
  250. }
  251.  
  252.  
  253. public class ScrollBox
  254. {
  255.   private int[] soundArray;
  256.   public boolean visible;
  257.   public float[] topPos;
  258.   public boolean[] playing;
  259.  
  260.   ScrollBox(int[] a, boolean vis) {
  261.     soundArray=a;
  262.     visible=vis;
  263.     textAlign(LEFT, CENTER);
  264.     topPos = new float[soundArray.length+1];
  265.     playing = new boolean[soundArray.length];
  266.   }
  267.  
  268.   public void draw()
  269.   {
  270.     if (visible) {
  271.       imageMode(CENTER);
  272.       textSize(35);
  273.       fill(0);
  274.       for (int i=0; i<soundArray.length; i++) {
  275.         topPos[i]=height/12*i+height/12*0.6-width/11/2+height/10;
  276.         topPos[i+1]=height/12*i+height/12*0.6+width/11/2+height/10;
  277.         text(soundNames[soundArray[i]], insetThin*2, height/12*i+height/12*0.6+height/10);
  278.         if (!playing[i]) {
  279.           image(playButton, insetThin*1.5, height/12*i+height/12*0.6+height/10, width/11, width/11);
  280.         } else {
  281.           image(pauseButton, insetThin*1.5, height/12*i+height/12*0.6+height/10, width/11, width/11);
  282.         }
  283.       }
  284.       imageMode(CORNERS);
  285.     }
  286.   }
  287. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top