Adjust sound effect code

main
Joshua Sigona 3 years ago
parent c8bb8c01f6
commit 21cf15b595
  1. 8
      LLSIG/src/main/java/LLSIG/Canvas.java
  2. 9
      LLSIG/src/main/java/LLSIG/LLSIG.java
  3. 44
      LLSIG/src/main/java/LLSIG/SoundLine.java

@ -68,10 +68,10 @@ public class Canvas extends JPanel implements AudioSpectrumListener{
final int NOTE_Y=(int)(MIDDLE_Y);
for (int y=-BEAT_RANGE;y<BEAT_RANGE;y++) {
g.setColor(Color.GRAY);
g.fillRect(MARGIN_X,(int)(NOTE_Y+(y-LLSIG.EDITOR_CURSOR_BEAT%1)*BEAT_SPACING)+NOTE_SIZE/2,this.getWidth()-MARGIN_X*2,4);
g.fillRect(MARGIN_X,(int)(NOTE_Y+(y-LLSIG.EDITOR_CURSOR_BEAT%1)*BEAT_SPACING)+NOTE_SIZE/2-2,this.getWidth()-MARGIN_X*2,4);
g.setColor(Color.DARK_GRAY);
for (int yy=1;yy<=LLSIG.EDITOR_BEAT_DIVISIONS;yy++) {
g.fillRect(MARGIN_X*2,(int)(NOTE_Y+(y-LLSIG.EDITOR_CURSOR_BEAT%1)*BEAT_SPACING)+(BEAT_SPACING/LLSIG.EDITOR_BEAT_DIVISIONS)*yy+NOTE_SIZE/2,this.getWidth()-MARGIN_X*4,2);
for (int yy=1;yy<LLSIG.EDITOR_BEAT_DIVISIONS;yy++) {
g.fillRect(MARGIN_X*2,(int)Math.round((NOTE_Y+(y-LLSIG.EDITOR_CURSOR_BEAT%1)*BEAT_SPACING)+(BEAT_SPACING/(LLSIG.EDITOR_BEAT_DIVISIONS))*yy+NOTE_SIZE/2),this.getWidth()-MARGIN_X*4,2);
}
}
for (int i=0;i<9;i++) {
@ -207,7 +207,7 @@ public class Canvas extends JPanel implements AudioSpectrumListener{
if (multiple) {
Color drawCol = g.getColor();
g.setColor(multiple_col?Color.RED:Color.BLUE);
g.fillRoundRect((int)x,(int)(y+(ysize*NOTE_SIZE)/2),(int)(xsize*NOTE_SIZE), 4, 6, 2);
g.fillRoundRect((int)x,(int)(y+(ysize*NOTE_SIZE)/2),(int)(xsize*NOTE_SIZE), 8, 4, 24);
g.setColor(drawCol);
}
}

@ -130,7 +130,8 @@ public class LLSIG implements KeyListener,MouseWheelListener{
if (!EDITOR) {
musicPlayer.play();
}
//musicPlayer.jlpp.setVolume(0);
LoadSongData(song,lanes);
}
Canvas canvas = new Canvas(f.getSize());
@ -159,13 +160,11 @@ public class LLSIG implements KeyListener,MouseWheelListener{
if (lane.noteExists()) {
Note n = lane.getNote();
if (n.getNoteType()==NoteType.HOLD&&n.active2&&n.getBeatSnapEnd()<=EDITOR_CURSOR_BEAT) {
clap.setFramePosition(0);
clap.start();
new SoundLine("se/clap.wav");
n.active2=false;
} else
if (n.active&&n.getBeatSnap()<=EDITOR_CURSOR_BEAT) {
clap.setFramePosition(0);
clap.start();
new SoundLine("se/clap.wav");
n.active=false;
}
}

@ -0,0 +1,44 @@
package main.java.LLSIG;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineEvent.Type;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.AudioSystem;
public class SoundLine implements LineListener{
Clip clip;
AudioInputStream stream;
SoundLine(String sound) {
try {
this.clip = AudioSystem.getClip();
this.stream = AudioSystem.getAudioInputStream(new File(sound).getAbsoluteFile());
clip.addLineListener(this);
clip.open(stream);
clip.start();
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
e.printStackTrace();
}
}
@Override
public void update(LineEvent event) {
if (event.getType()==Type.STOP) {
clip.close();
try {
stream.close();
//System.out.println("Freed resources for sound.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Loading…
Cancel
Save