From 1ed58291c4fcadccd1d43ecee213c85d5120fe6b Mon Sep 17 00:00:00 2001 From: Henri Cossais Date: Wed, 21 Jun 2023 11:12:25 +0200 Subject: [PATCH] New feature added : Time line slider and scale bar improvements --- src/com/cubaix/kai/KaiEditor.java | 14 ++++++-- src/com/cubaix/kai/KaiTimeLine.java | 56 +++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/com/cubaix/kai/KaiEditor.java b/src/com/cubaix/kai/KaiEditor.java index 959f5a1..72274e0 100644 --- a/src/com/cubaix/kai/KaiEditor.java +++ b/src/com/cubaix/kai/KaiEditor.java @@ -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; @@ -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 @@ -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()); diff --git a/src/com/cubaix/kai/KaiTimeLine.java b/src/com/cubaix/kai/KaiTimeLine.java index 5ea4190..e129b7b 100644 --- a/src/com/cubaix/kai/KaiTimeLine.java +++ b/src/com/cubaix/kai/KaiTimeLine.java @@ -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; @@ -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); @@ -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 && @@ -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(); } } /** @@ -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); } @@ -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); } @@ -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); @@ -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 @@ -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(); @@ -474,6 +506,7 @@ protected void paintTimed() { dblBufGC.setClipping(timeLineBounds); + if(song.kaiSrt != null && currentKaiIdx >= 0) { dblBufGC.setBackground(parentKDJ.logoLightC); @@ -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); @@ -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);