Song.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package audio;
  2. import image.Images;
  3. import java.awt.image.BufferedImage;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import javax.sound.sampled.AudioInputStream;
  9. import javax.sound.sampled.AudioSystem;
  10. import javax.sound.sampled.UnsupportedAudioFileException;
  11. public class Song {
  12. private String title;
  13. private String subtitle;
  14. private String author;
  15. private double sample_start;
  16. private double BPM;
  17. private File audio;
  18. private File background;
  19. private File banner;
  20. private File file;
  21. private BufferedImage backgroundImage;
  22. private BufferedImage bannerImage;
  23. private AudioInputStream audioStream;
  24. public List<SongInstance> songs;
  25. public Song() {
  26. title = "";
  27. subtitle = "";
  28. author = "";
  29. sample_start = 0;
  30. BPM = 0.0;
  31. audio = null;
  32. background = null;
  33. banner = null;
  34. file = null;
  35. backgroundImage = null;
  36. bannerImage = null;
  37. audioStream = null;
  38. songs = new ArrayList<SongInstance>();
  39. }
  40. public void addSongInstance(SongInstance s) {
  41. songs.add(s);
  42. }
  43. public String getTitle() {
  44. return title;
  45. }
  46. public void setTitle(String title) {
  47. this.title = title;
  48. }
  49. public String getSubtitle() {
  50. return subtitle;
  51. }
  52. public void setSubtitle(String subtitle) {
  53. this.subtitle = subtitle;
  54. }
  55. public String getAuthor() {
  56. return author;
  57. }
  58. public void setAuthor(String author) {
  59. this.author = author;
  60. }
  61. public double getSampleStart() {
  62. return sample_start;
  63. }
  64. public void setSampleStart(double sample_start) {
  65. this.sample_start = sample_start;
  66. }
  67. public double getBPM() {
  68. return BPM;
  69. }
  70. public void setBPM(double bPM) {
  71. BPM = bPM;
  72. }
  73. public File getAudio() {
  74. return audio;
  75. }
  76. public AudioInputStream getAudioStream()
  77. {
  78. if(audioStream == null)
  79. {
  80. try {
  81. this.audioStream = AudioSystem.getAudioInputStream(audio);
  82. } catch (UnsupportedAudioFileException e) {
  83. e.printStackTrace();
  84. } catch (IOException e) {
  85. e.printStackTrace();
  86. }
  87. }
  88. try {
  89. audioStream.reset();
  90. } catch (IOException e) {
  91. e.printStackTrace();
  92. }
  93. return audioStream;
  94. }
  95. public void setAudio(File audio) {
  96. this.audio = audio;
  97. }
  98. public File getBackground() {
  99. return background;
  100. }
  101. public void setBackground(File background) {
  102. this.background = background;
  103. }
  104. public BufferedImage getBackgroundImage()
  105. {
  106. if(backgroundImage == null)
  107. {
  108. this.backgroundImage = Images.readImage(background);
  109. }
  110. return backgroundImage;
  111. }
  112. public File getBanner() {
  113. return banner;
  114. }
  115. public BufferedImage getBannerImage()
  116. {
  117. if(bannerImage == null)
  118. {
  119. this.bannerImage = Images.readImage(banner);
  120. }
  121. return bannerImage;
  122. }
  123. public void setBanner(File banner) {
  124. this.banner = banner;
  125. }
  126. public File getFile() {
  127. return file;
  128. }
  129. public void setFile(File file) {
  130. this.file = file;
  131. }
  132. public List<SongInstance> getSongs() {
  133. return songs;
  134. }
  135. public void close()
  136. {
  137. if(audioStream != null)
  138. {
  139. try {
  140. audioStream.close();
  141. } catch (IOException e) {
  142. }
  143. }
  144. }
  145. }