Skip to content

Commit

Permalink
Seek to the song position when clicking on a time-stamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneAb3d committed Mar 29, 2023
1 parent ad83812 commit 7a61e0f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 7 deletions.
Binary file modified dist/karaok-AI.jar
Binary file not shown.
55 changes: 55 additions & 0 deletions src/com/cubaix/kai/KaiEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public void paintControl(PaintEvent arg0) {
if(aR.y+aR.height > parentKDJ.display.getBounds().height - 40) {
aR.y = parentKDJ.display.getBounds().height-aR.height - 40;
}
if(KaiDJ._SIZE_FOR_SCREENSHOTS) {
aR.width = KaiDJ._SIZE_FOR_SCREENSHOTS_W;
aR.height = KaiDJ._SIZE_FOR_SCREENSHOTS_H;
}
shell.setBounds(aR);
}

Expand Down Expand Up @@ -461,6 +465,21 @@ public void run() {
}
}

void seek(long aTimeMS) {
boolean aIsPlaying = playerVocals.playState == 1;
if(aIsPlaying) {
togglePlay();
}
long aBitBef = 500;
playerVocals.seek(aTimeMS-aBitBef);
playerDrums.seek(aTimeMS-aBitBef);
playerBass.seek(aTimeMS-aBitBef);
playerOther.seek(aTimeMS-aBitBef);
if(aIsPlaying) {
togglePlay();
}
}

void togglePlay() {
final boolean[] aDone = new boolean[] {false,false,false,false};
Thread aThVocals = new Thread(new Runnable() {
Expand Down Expand Up @@ -610,6 +629,42 @@ public void keyReleased(KeyEvent arg0) {
public void keyPressed(KeyEvent arg0) {
}
});
editor.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent aE) {
int aPos = editor.getCaretPosition();
String aTxt = editor.getText();
String aLine = null;
String[] aLines = aTxt.split("\n");
for(String aL : aLines) {
if(aPos <= aL.length()) {
aLine = aL;
break;
}
aPos -= aL.length()+1;
}
if(aLine == null || !aLine.matches("[0-9]+:[0-9]+:[0-9]+[.,][0-9]+ --> .*")) {
return;
}
String[] aHMS = aLine.split("[:,. ]");
long aTimeMS = Integer.parseInt(aHMS[0])*3600*1000
+Integer.parseInt(aHMS[1])*60*1000
+Integer.parseInt(aHMS[2])*1000
+Integer.parseInt(aHMS[3]);
seek(aTimeMS);
// int aClickedPos = playerVocals.progessBarR.x
// +(int)(playerVocals.progessBarR.width * aTimeMS / (double)playerVocals.getDurationTimeMs());
// clickSeek(aClickedPos, playerVocals.progessBarR.y);
}

@Override
public void mouseDown(MouseEvent aE) {
}

@Override
public void mouseDoubleClick(MouseEvent aE) {
}
});
}

void start() {
Expand Down
4 changes: 4 additions & 0 deletions src/com/cubaix/kai/KaiViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public void mouseDoubleClick(MouseEvent arg0) {
if(aR.y+aR.height > parentKE.parentKDJ.display.getBounds().height - 40) {
aR.y = parentKE.parentKDJ.display.getBounds().height-aR.height - 40;
}
if(KaiDJ._SIZE_FOR_SCREENSHOTS) {
aR.width = KaiDJ._SIZE_FOR_SCREENSHOTS_W;
aR.height = KaiDJ._SIZE_FOR_SCREENSHOTS_H;
}
shell.setBounds(aR);
}

Expand Down
21 changes: 16 additions & 5 deletions src/com/cubaix/kaiDJ/DJPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
* This class implements a simple player based on BasicPlayer. BasicPlayer is a threaded class providing most features of a music player. BasicPlayer works with underlying JavaSound SPIs to support multiple audio formats. Basically JavaSound supports WAV, AU, AIFF audio formats. Add MP3 SPI (from JavaZOOM) and Vorbis SPI( from JavaZOOM) in your CLASSPATH to play MP3 and Ogg Vorbis file.
*/
public class DJPlayer extends TimedCanvas implements BasicPlayerListener, KJDigitalSignalProcessor{

//EM 06/07/2008
static public int _BUFFER_SIZE = 16384;
static final public int _WIDTHINT = 150;
static final public int _HEIGHTINT = 100;

Expand All @@ -55,7 +54,7 @@ public class DJPlayer extends TimedCanvas implements BasicPlayerListener, KJDigi

Rectangle playerBounds = null;

protected BasicPlayer player;
public BasicPlayer player;
public BasicController control;

int destCard = 0;
Expand Down Expand Up @@ -146,6 +145,18 @@ public int click(int x, int y) {
return aClickWhat;
}

public void seek(long aTimeMS) {
try {
double aPos = aTimeMS / (double) currentDuration;
long aSeek = (long) (aPos * currentLengthBytes);
player.seek(aSeek);
currentPositionMs = aTimeMS;
needRedraw();
} catch (Exception e) {
e.printStackTrace(System.err);
}
}

/**
* @param aDestCard
*/
Expand All @@ -171,7 +182,7 @@ public void load(String aPath) {
//EM 29/04/2009 : provide with parentJDJ
player = new BasicPlayer(parentKDJ,useDSP);
//EM 01/11/2008 : try to get the same buffer size on each
player.setLineBufferSize(-1);//65535);
player.setLineBufferSize(_BUFFER_SIZE);

setDestCard(destCard);
// BasicPlayer is a BasicController.
Expand Down Expand Up @@ -716,7 +727,7 @@ String getDoneTimeFormated() {
/**
* @return
*/
long getDurationTimeMs() {
public long getDurationTimeMs() {
return currentDuration;
}

Expand Down
17 changes: 15 additions & 2 deletions src/com/cubaix/kaiDJ/KaiDJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@

// Main class, for all in JDJ
public class KaiDJ {
static final public String _VERSION = "0.6.0";
static final public String _VERSION = "0.6.1";

static public boolean _SIZE_FOR_SCREENSHOTS = false;
static final public int _SIZE_FOR_SCREENSHOTS_W = 1024;
static final public int _SIZE_FOR_SCREENSHOTS_H = 576;
public static final boolean _DEBUG_PAINT = false;

public static String kaiDir = System.getProperty("user.home")+File.separatorChar+"karaok-AI";
Expand Down Expand Up @@ -354,6 +358,10 @@ public void paintControl(PaintEvent arg0) {
}
aR.width -= 20;
aR.height /=2;
if(KaiDJ._SIZE_FOR_SCREENSHOTS) {
aR.width = KaiDJ._SIZE_FOR_SCREENSHOTS_W;
aR.height = KaiDJ._SIZE_FOR_SCREENSHOTS_H;
}
shell.setBounds(aR);
}

Expand Down Expand Up @@ -674,7 +682,7 @@ public void widgetSelected(SelectionEvent arg0) {
// karaok-AI
KaiButton aKai = new KaiButton(this, aButtonsC, SWT.NULL);
aKai.setBackground(this.mainBckC);
aKai.setToolTipText("Open karaok-AI");
aKai.setToolTipText("Open karaok-AI (select a song first)");
aKai.setImagePath("img2/kaiBut.png");
aGD = new GridData(GridData.FILL_HORIZONTAL);
aGD.heightHint = KaiButton._HEIGHT;
Expand Down Expand Up @@ -1186,6 +1194,11 @@ public static void main(String[] args) {
System.out.println("Java version : " + System.getProperty("java.version"));
System.out.println("JRE location : " + System.getProperty("java.home"));
System.out.println("SWT version : " + SWT.getVersion());
for(String aA : args) {
if("SCR".equalsIgnoreCase(aA)) {
KaiDJ._SIZE_FOR_SCREENSHOTS = true;
}
}
new KaiDJ().start();
}
}

0 comments on commit 7a61e0f

Please sign in to comment.