Skip to content

Commit

Permalink
New feature added : Time line slider and scale bar improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Cossais committed Jun 21, 2023
1 parent d1c0adf commit 1ed5829
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/com/cubaix/kai/KaiEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public void run() {
aTh.start();
}

void seek(long aTimeMS) {
void seek(long aTimeMS, boolean aBitBefore) {

//flag to avoid multiple thread execution that can desynchronize players (mainly used in the time line menu, advance and forward buttons)
currentlySeeking = true;
Expand All @@ -573,7 +573,15 @@ public void run() {
togglePlay();
}

final long aBitBef = 500;
long aTimeBeofore;
if(aBitBefore) {
aTimeBeofore = 500;
} else {
aTimeBeofore = 0;
}

final long aBitBef = aTimeBeofore;

final boolean[] aDone = new boolean[] {false,false,false,false};
Thread aThVocals = new Thread(new Runnable() {
@Override
Expand Down Expand Up @@ -808,7 +816,7 @@ public void mouseUp(MouseEvent aE) {
+Integer.parseInt(aHMS[8]);


seek(aTimeMS);
seek(aTimeMS,true);
kaiTimeLine.timestampClickHandler(aTimeMS, aTimeEndMS);
// int aClickedPos = playerVocals.progessBarR.x
// +(int)(playerVocals.progessBarR.width * aTimeMS / (double)playerVocals.getDurationTimeMs());
Expand Down
56 changes: 50 additions & 6 deletions src/com/cubaix/kai/KaiTimeLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class KaiTimeLine extends TimedCanvas {
private Long widthMainChunk = (long) -1;

private int xCurrentMousePos = -1;
protected boolean cursorOnScaleBar;
protected int yCurrentMousePos;

private boolean mainChunkIsClicked = false;
private boolean markOneIsClicked = false;
Expand All @@ -78,6 +80,8 @@ public class KaiTimeLine extends TimedCanvas {
Long aPlayerCurrentPosMS;

private int indexToGo = -1;
protected boolean scaleBarIsClicked;


public KaiTimeLine(KaiEditor parentKE, Composite parent, int style) {
super(parentKE.parentKDJ, parent, style);
Expand Down Expand Up @@ -188,6 +192,14 @@ private boolean isSomethingIsClicked(MouseEvent aME) {
aThis.setCursor(new Cursor(parentKDJ.display,SWT.CURSOR_SIZEE));
markOneIsClicked = true;
return true;
} else if (
//Scalebar
cursorOnScaleBar) {
aThis.setCursor(new Cursor(parentKDJ.display,SWT.CURSOR_SIZEE));
if(parentKE.playerVocals.playState == 1) parentKE.togglePlay();
currentPlayTimeTriangle = new int[] {aME.x,SCALE_BAR_HEIGHT-2 , aME.x-5,SCALE_BAR_HEIGHT-12, aME.x+5,SCALE_BAR_HEIGHT-12};
scaleBarIsClicked = true;
return true;
} else if (
//Menu previous button
aME.x >= previousButton.x && aME.x <= previousButton.x + previousButton.width &&
Expand Down Expand Up @@ -244,6 +256,13 @@ public void mouseUp(MouseEvent aME) {

needRedraw();
xCurrentMousePos = -1;
} else if (scaleBarIsClicked) {
aThis.setCursor(new Cursor(parentKDJ.display,SWT.CURSOR_ARROW));
aPlayerCurrentPosMS = (tStart/scaleFactor+aME.x)*scaleFactor;
parentKE.seek(aPlayerCurrentPosMS, false);
currentPlayTimeTriangle = new int[] {aME.x,SCALE_BAR_HEIGHT-2 , aME.x-5,SCALE_BAR_HEIGHT-12, aME.x+5,SCALE_BAR_HEIGHT-12};
scaleBarIsClicked = false;
needRedraw();
}
}
/**
Expand Down Expand Up @@ -289,7 +308,7 @@ private void menuEventhandler() {
if(parentKE.currentlySeeking) {
enterInQueue();
} else {
parentKE.seek(song.kaiSrt.chunks.get(currentKaiIdx).getStartTime());
parentKE.seek(song.kaiSrt.chunks.get(currentKaiIdx).getStartTime(),true);
}
needRedraw(2);
}
Expand All @@ -301,7 +320,7 @@ private void menuEventhandler() {
if(parentKE.currentlySeeking) {
enterInQueue();
} else {
parentKE.seek(song.kaiSrt.chunks.get(currentKaiIdx).getStartTime());
parentKE.seek(song.kaiSrt.chunks.get(currentKaiIdx).getStartTime(),true);
}
needRedraw(2);
}
Expand Down Expand Up @@ -336,7 +355,7 @@ public void run() {
try {
if(indexToGo != -1 && !parentKE.currentlySeeking) {
System.out.println("seeking chunk : " + indexToGo);
parentKE.seek(song.kaiSrt.chunks.get(indexToGo).getStartTime());
parentKE.seek(song.kaiSrt.chunks.get(indexToGo).getStartTime(),true);
indexToGo = -1;
}
Thread.sleep(5);
Expand All @@ -362,6 +381,20 @@ public void run() {

@Override
public void mouseMove(MouseEvent aME) {
if(aME.y >= 0 && aME.y <= SCALE_BAR_HEIGHT) {
cursorOnScaleBar = true;
xCurrentMousePos = aME.x;
yCurrentMousePos = aME.y;
needRedraw();
}
if(aME.y < 25 || aME.y > SCALE_BAR_HEIGHT) {
cursorOnScaleBar = false;
needRedraw();
}
if(scaleBarIsClicked) {
currentPlayTimeTriangle = new int[] {aME.x,SCALE_BAR_HEIGHT-2 , aME.x-5,SCALE_BAR_HEIGHT-12, aME.x+5,SCALE_BAR_HEIGHT-12};
needRedraw();
}
if(mainChunkIsClicked) {
newPos = mainTimestamp.x + aME.x-xCurrentMousePos;
//restricting position to fit into windows limits
Expand Down Expand Up @@ -396,13 +429,12 @@ public void mouseMove(MouseEvent aME) {
}
});

//Dynamic time line
//Dynamic time line slider
Thread aTrackTh = new Thread(new Runnable() {
@Override
public void run() {
//voir si le temps a changer, avec le stockage du temps précedant
while(!aThis.isDisposed()) {
if(aPlayerCurrentPosMS != parentKE.playerVocals.getPositionMs()) {
if(aPlayerCurrentPosMS != parentKE.playerVocals.getPositionMs() && parentKE.playerVocals.playState == 1) {
int aPlayerCurrentPosPxl = (int) ((aPlayerCurrentPosMS / scaleFactor)-(tStart / scaleFactor));
currentPlayTimeTriangle = new int[] {aPlayerCurrentPosPxl,SCALE_BAR_HEIGHT-2 , aPlayerCurrentPosPxl-5,SCALE_BAR_HEIGHT-12, aPlayerCurrentPosPxl+5,SCALE_BAR_HEIGHT-12};
aPlayerCurrentPosMS = parentKE.playerVocals.getPositionMs();
Expand Down Expand Up @@ -474,6 +506,7 @@ protected void paintTimed() {

dblBufGC.setClipping(timeLineBounds);


if(song.kaiSrt != null && currentKaiIdx >= 0) {

dblBufGC.setBackground(parentKDJ.logoLightC);
Expand Down Expand Up @@ -537,6 +570,7 @@ protected void paintTimed() {
//Current play time
dblBufGC.setBackground(parentKDJ.redC);
dblBufGC.setForeground(parentKDJ.redC);

dblBufGC.fillPolygon(currentPlayTimeTriangle);
dblBufGC.drawLine(currentPlayTimeTriangle[0], SCALE_BAR_HEIGHT, currentPlayTimeTriangle[0], timeLineBounds.height);

Expand Down Expand Up @@ -574,6 +608,16 @@ protected void paintTimed() {

}

//Drawing focused time stamp if mouse is on scale bar
dblBufGC.setClipping(timeLineBounds);
dblBufGC.setFont(parentKDJ.kaiFont);
dblBufGC.setBackground(parentKDJ.secondBckC);
dblBufGC.setForeground(parentKDJ.redC);
if(cursorOnScaleBar && xCurrentMousePos >=75) {
dblBufGC.drawText(ChunkStr.getTimeFormatFromMs((tStart/scaleFactor+xCurrentMousePos)*scaleFactor), xCurrentMousePos-71, SCALE_BAR_HEIGHT);
} else if (cursorOnScaleBar)dblBufGC.drawText(ChunkStr.getTimeFormatFromMs((tStart/scaleFactor+xCurrentMousePos)*scaleFactor), xCurrentMousePos+15, SCALE_BAR_HEIGHT);


// Draw final image
GC aPlGC = new GC(this);
paintDbl(aPlGC);
Expand Down

0 comments on commit 1ed5829

Please sign in to comment.