Synchronize an QOpengl line with audio file
-
wrote on 28 Nov 2018, 14:27 last edited by HW-Developer
I want to create an app that can play an audio and synchronize it with a QOpenglWidget that include a divided ruler instead of a qslider like this:
but i can't figure out how to create positionchanged method in my QOpenglWidget class, so any one has a simple example or an idea, i really appreciate it. Thank you. -
Hi
you mean some method or signal to move the red line ? -
wrote on 28 Nov 2018, 15:14 last edited by
@mrjj Yes that's right
-
@mrjj Yes that's right
@HW-Developer
well did u subclass QOpenglWidget ?
If yes, you can just add a slot to it like
public slots:
void PositionChanged( int pos) ;and in cpp
void yourclassname:: PositionChanged( int pos) {
change the variable that controls the red line.
} -
@HW-Developer
well did u subclass QOpenglWidget ?
If yes, you can just add a slot to it like
public slots:
void PositionChanged( int pos) ;and in cpp
void yourclassname:: PositionChanged( int pos) {
change the variable that controls the red line.
}wrote on 28 Nov 2018, 15:28 last edited by HW-Developer@mrjj for example if we have this code to draw the red line
glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); glVertex3f(-1 + (redLine*scaleFactor), 1 + -(0 * 0.016), -1.0); glVertex3f(-1 + (redLine*scaleFactor), 1 + -(130 * 0.016), -1.0); glEnd();
//scaleFactor is a float variable which determines the space before the red line
//redline is a float variable = 320 + 160;and i create the positionChanged(int position) methode, what should i change using the position variable?
-
@mrjj for example if we have this code to draw the red line
glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); glVertex3f(-1 + (redLine*scaleFactor), 1 + -(0 * 0.016), -1.0); glVertex3f(-1 + (redLine*scaleFactor), 1 + -(130 * 0.016), -1.0); glEnd();
//scaleFactor is a float variable which determines the space before the red line
//redline is a float variable = 320 + 160;and i create the positionChanged(int position) methode, what should i change using the position variable?
@HW-Developer
I would assume redLine variable ? -
@HW-Developer
I would assume redLine variable ?wrote on 28 Nov 2018, 15:42 last edited by HW-Developer@mrjj When i use redLine =0, it gives me this result:
so 160 is the space between the small grey lines
and 320 is just a number that i added so the red line will be in the same line with my slider
-
@mrjj When i use redLine =0, it gives me this result:
so 160 is the space between the small grey lines
and 320 is just a number that i added so the red line will be in the same line with my slider
@HW-Developer
so the redline default offset is 320+160.
so if you add to that, it will move the redline.
Do you mean to hook up the slider so it moves the redline or what is task? -
@HW-Developer
so the redline default offset is 320+160.
so if you add to that, it will move the redline.
Do you mean to hook up the slider so it moves the redline or what is task?wrote on 28 Nov 2018, 15:46 last edited by@mrjj The slider was my first test so to have the same result i did have with my slider i initialize the red line on the same line with that slider so when the audio is playing, they will be moving in the same time
-
@mrjj The slider was my first test so to have the same result i did have with my slider i initialize the red line on the same line with that slider so when the audio is playing, they will be moving in the same time
@HW-Developer
ok.
so now you want a method in QOpenglWidget that also moves the redLine ? -
@HW-Developer
ok.
so now you want a method in QOpenglWidget that also moves the redLine ?wrote on 28 Nov 2018, 15:54 last edited by@mrjj Yes that's right
-
@mrjj Yes that's right
@HW-Developer
Ok, i assumed you subclassed it ?
like
class MyGLWidget : public QOpenGLWidget ...so you can just add a new method to it to alter the redLine variable.
-
@HW-Developer
Ok, i assumed you subclassed it ?
like
class MyGLWidget : public QOpenGLWidget ...so you can just add a new method to it to alter the redLine variable.
wrote on 28 Nov 2018, 15:57 last edited by@mrjj Yes of course i already did what is necessary to have the drawing ruler that i upload it above
-
@mrjj Yes of course i already did what is necessary to have the drawing ruler that i upload it above
@HW-Developer
ok but you question was
" how to create positionchanged method in my QOpenglWidget class,"
so i must be missing something you ask about ?
(if you already did make such method) -
@HW-Developer
ok but you question was
" how to create positionchanged method in my QOpenglWidget class,"
so i must be missing something you ask about ?
(if you already did make such method)wrote on 28 Nov 2018, 16:52 last edited by HW-Developer@mrjj I already draw the qopenglwidget but I did not synchronize it with the audio file using positionchanged method that I did ask you about
-
@mrjj I already draw the qopenglwidget but I did not synchronize it with the audio file using positionchanged method that I did ask you about
hi
well you can hook up the AUDIO positionchanged
signal to your own method (slot)
using connect.
http://doc.qt.io//qt-5/signalsandslots.htmlso it will directly call your method when it changes.
1/16