Error on getBarCount()

I want to get the last bar number with getBarCount(), but I get an error. (Error message = "There is no suitable conversion function from “Juce::Optional<int64_t>” to “int”.)
How can I get rid of this error?

I was able to get getIsPlaying().

1 Like

something like this will do it. Not all hosts have this value available, so the usage of Optional allows you to check if the current host supports it, or not.

auto possibleNumBarCount { playHead->getPostion ()->getBarCount () };
if (possibleNumBarCount.hasValue ())
{
   // you have a valid bar count
   num = *possibleNumBarCount;
}
else
{
    // you do not have a valid bar count
}
2 Likes

Thank you!
Auto type, huh? I had not thought of that.

The error was successfully resolved and the program is now what I expected.
However, getBarCount could not be retrieved by the host application I have. The road to completion of my own plugin is a long one.

I appreciate it, thank you.

1 Like

You could specify the return type, juce::Optional<int64>, but I prefer auto when possible. Oh, you can probably make that const, and improve the scoping by moving the retrieval in the init portion of the if statement.

3 Likes