The length() function gives it in miliseconds as an integer so dividing doesn’t work. Did some research but couldn’t find anything and it seems like there is no other function similar to length().
Can somebody help?
Can you explain your problem better please. What do you actually want to divide/trim
I want to get the length of the audio file in ‘minute : seconds’ format with minim. The length() function gives the length of the audio file already but in miliseconds as an integer so didn’t have much luck using that.
Here is a simple example with millis():
int ms;
int sec;
int min;
int hours;
int days;
int offset;
void setup()
{
}
void draw()
{
background(0);
ms = millis();
print(ms);
println(" ms");
sec = ms/1000;
print(sec);
println(" sec");
print(sec); print(":"); println(ms);
//min = sec/?;
/*
Complete the rest for:
hours
days
*/
}
I kept it as simple as possible.
References:
One of the best tools in a programmers tool chest is knowing the resources available to you and learning to navigate and use them.
This is a very short list:
Resources < Click here to expand !
I encourage you to review the resources available here:
- The Processing website has references, examples, tutorials, etc.
https://processing.org/ - The Processing PDE (IDE) has lots to offer!
An exploration of the tabs will reveal what is available; libraries, tools and local examples there. - The Coding Train
https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw
https://thecodingtrain.com/ - Happy Coding
Processing Tutorials - Happy Coding - The source code can give insight if you are adventurous:
GitHub - processing/processing: Source code for the Processing Core and Development Environment (PDE)
Many of the Processing functions are here:
processing/core/src/processing/core/PApplet.java at master · processing/processing · GitHub - The Processing Foundation
https://processingfoundation.org/
Check out the tabs.
In the education tab, there is a reference to the Coding Train. - And the Internet.
:)
:)
Thanks a lot! With a few additions it works great:
fill(0);
int sec = file2.length() / 1000;
int min = sec / 60;
sec = sec - min * 60;
if (sec < 10) text(min + ":0" + sec,250,250);
else text(min + ":" + sec,250,250);
it was much simpler than I thought, I was overcomplicating it in my head
I know those resources, they help everyday!. Especially older forum posts.
Edit:
And the duration and time left is working beatifully now thanks so much!
fill(255);
int sec = file2.position() / 1000;
int min = sec / 60;
sec = sec - min * 60;
if (sec < 10) text(min + ":0" + sec,12,380);
else text(min + ":" + sec,12,380);
fill(255);
int sec2 = (file2.length() - file2.position()) / 1000;
int min2 = sec2 / 60;
sec2 = sec2 - min2 * 60;
if (sec2 < 10) text(min2 + ":0" + sec2,560,380);
else text(min2 + ":" + sec2,560,380);