Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. import java.nio.file.Path;
  2.  
  3. import processing.sound.*;
  4.  
  5. SoundFile file;
  6.  
  7. boolean loading = true;
  8. boolean loadingphase2 = false;
  9. boolean select;
  10. boolean processing;
  11. boolean playing;
  12.  
  13. String from;
  14. String newPath;
  15.  
  16. boolean folderSelected = false;
  17. boolean fileSelected = false;
  18.  
  19. void setup() {
  20. size(600,300);
  21. }
  22.  
  23. void draw() {
  24. if(loading) {
  25. loading();
  26. }
  27. if(select) {
  28. select();
  29. }
  30. if(processing) {
  31. processing();
  32. }
  33. if(playing) {
  34. playing();
  35. }
  36. }
  37.  
  38. void loading() {
  39. background(0);
  40. textSize(20);
  41. textAlign(CENTER);
  42. fill(255);
  43. text("Hello, please choose an mp3 file to play.", width/2, height/2-100);
  44. fill(25,255,255);
  45. rect(width/2-100, height/2-50, 200, 50);
  46. textAlign(CENTER);
  47. textSize(30);
  48. fill(0);
  49. text("LOADING...", width/2, height/2-15);
  50. while(loadingphase2) {
  51. delay(3000);
  52. select = true;
  53. loading = false;
  54. loadingphase2 = false;
  55. }
  56. loadingphase2 = true;
  57. }
  58.  
  59. void select() {
  60. background(0);
  61. textSize(20);
  62. textAlign(CENTER);
  63. fill(255);
  64. text("Hello, please choose an mp3 file to play.", width/2, height/2-100);
  65. fill(25,255,255);
  66. rect(width/2-100, height/2-50, 200, 50);
  67. textAlign(CENTER);
  68. textSize(30);
  69. fill(0);
  70. text("UPLOAD", width/2, height/2-15);
  71. }
  72.  
  73. void processing() {
  74. background(0);
  75. textSize(20);
  76. textAlign(CENTER);
  77. fill(255);
  78. text("Nicely done! Now, please select the 'data' folder. /n It's in the folder with this code-app.", width/2, height/2-100);
  79. fill(25,255,255);
  80. rect(width/2-100, height/2-50, 200, 50);
  81. textAlign(CENTER);
  82. textSize(30);
  83. fill(0);
  84. text("SELECT", width/2, height/2-15);
  85. }
  86.  
  87. void playing() {
  88. if(fileSelected) {
  89. background(0);
  90. textSize(30);
  91. textAlign(CENTER);
  92. text("Alright, enjoy the music.", width/2, height/2);
  93. file = new SoundFile(this, "music.mp3");
  94. file.play();
  95. fileSelected = false;
  96. playing = false;
  97. }
  98. }
  99.  
  100. void fileSelected(File selection) {
  101. if (selection == null) {
  102. println("Window was closed or the user hit cancel.");
  103. } else {
  104.  
  105. from = selection.getPath();
  106.  
  107. Path to = selection.get(sketchPath()+"/data/"+"music.mp3");
  108. selection.copy(from, to);
  109.  
  110. fileSelected = true;
  111. playing = true;
  112. select = false;
  113. }
  114. }
  115.  
  116. /*void folderSelected(File selection) {
  117. if (selection == null) {
  118. println("Window was closed or the user hit cancel.");
  119. } else {
  120. Path to = selection.getAbsolutePath();
  121. Files.copy(from, to.resolve(source.getFileName()));
  122.  
  123. folderSelected = true;
  124.  
  125.  
  126.  
  127. playing = true;
  128. processing = false;
  129. }
  130. }*/
  131.  
  132. void mouseReleased() {
  133. if(mouseX <= width/2+100 && mouseX >= width/2-100 && mouseY <= height/2+50 && mouseY >= height/2-50 && select) {
  134. selectInput("Select an mp3 file to play.", "fileSelected");
  135. }
  136. /* if(mouseX <= width/2+100 && mouseX >= width/2-100 && mouseY <= height/2+50 && mouseY >= height/2-50 && processing) {
  137. selectFolder("Select a folder to process:", "folderSelected");
  138. }*/
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement