[BUG] TimecodeSnapType::getTimecodeString() returns a bunch of Japanese characters

It displays these characters even when I change snap type number.

te::TimecodeSnapType snapType = timecodeFormat.getSnapType(1);
DBG(" timecode string: " << snapType.getTimecodeString(editViewState.leftLocatorX, edit.tempoSequence, false));

image

Is it supposed to be this way, should I just filter them out?

Same for TimecodeDisplayFormat::toFullTimecode()

It really does have a bunch of weird characters. Here’s what its variable contains

Okay, it doesn’t display those characters from snapType 9, which is minutes, and above

That’s odd. Can I ask what scenario you’re seeing this in?
If you put a breakpoint on line 163, are the bars/beats ints correct? If so, it could be a problem with String::formatted?

My TimecodeType is set to milliseconds, it never goes to bars and beats

@dave96 Here’s where it gets all that mess:

It’s TimecodeDisplayFormat::toFullTimecode() and here’s where it’s called:

I’m trying to replicate this but can’t seem to be able to.
I’ve added the following test but the contained string is as expected:


If you add this in your project (or just run the contained code) what do you see?

class TimecodeTests  : public UnitTest
{
public:
    TimecodeTests()
        : UnitTest ("Timecode", "Tracktion")
    {
    }

    void runTest() override
    {
        using namespace tracktion_engine;
        auto edit = Edit::createSingleTrackEdit (*Engine::getEngines()[0]);
        TimecodeDisplayFormat timecodeFormat;
        TimecodeSnapType snapType = timecodeFormat.getSnapType (1);
        auto string = snapType.getTimecodeString (11.616, edit->tempoSequence, false);
        DBG(" timecode string: " << snapType.getTimecodeString (11.61, edit->tempoSequence, false));
    }
};

static TimecodeTests timecodeTests;

I see this:

That’s using the develop branch. If you’re on master just change that to Engine::getInstance() or just call the function with your Engine instance somewhere in your app.

Here’s what it shows: timecode string: 6|4|211

I can’t see how your original example is producing those extra characters then?
What time and tempoSequence are you actually feeding it?
Do you have some example code that I could use to replicate the problem?

Basically RecordingDemo.
Add this to EditViewState construct;
edit.setTimecodeFormat(te::TimecodeDisplayFormat(te::TimecodeType::millisecs));
Then pretty much anywhere else call this:

te::TimecodeDisplayFormat timecodeFormat = edit.getTimecodeFormat();
te::TimecodeSnapType snapType = timecodeFormat.getSnapType(1);
DBG(" timecode string: " << snapType.getTimecodeString(editViewState.leftLocatorX, edit.tempoSequence, false));

Perhaps it’s a Visual Studio issue?

I also have default:

This isn’t particularly helpful though as that example is huge and there isn’t even a leftLocatorX anywhere. What is the value you’re sending it? By the name, it looks like this is a pixel value but getTimecodeString expects a time in seconds.

If you can create a minimal example like in the snipped I’ve provided then I can see if something is going wrong but at the moment it looks more like you’re just either not configuring Edit’s TimecodeDisplayFormat correctly or are passing it some junk data?

Sorry, my bad. leftLocator is a double value of positionX translated to time. Even if I manually set double value it still add those characters:
DBG(" timecode string: " << snapType.getTimecodeString(13.125, edit.tempoSequence, false));

Ok, but in my example you said it was returning a correctly formatted string?
So are you perhaps is snapType destructed or the edit.tempoSequence invalid for some reason?

What does the following output? (I’m trying to create minimal bits of self-contained code here.

        auto edit = Edit::createSingleTrackEdit (*Engine::getInstance());
        TimecodeDisplayFormat timecodeFormat (TimecodeType::millisecs);
        TimecodeSnapType snapType = timecodeFormat.getSnapType (1);
        auto string = snapType.getTimecodeString (13.125, edit->tempoSequence, false);
        DBG(" timecode string: " << snapType.getTimecodeString (13.125, edit->tempoSequence, false));

Same thing:
image

I haven’t touched edit.tempoSequence at all. It might as well be invalid.

You’ve not got some weird build flag enabled like JUCE_NATIVE_WCHAR_IS_UTF32 or something have you?

It looks like the String::formatted is screwing up in here:

String TimecodeDisplayFormat::toFullTimecode (double seconds, int subSecondDivisions, bool showHours)
{
    auto absSecs = std::abs (seconds);
    const char* sign = (seconds < 0) ? "-" : "";
    String result;

    if (showHours || (absSecs >= 60.0 * 60.0))
        result = String::formatted ("%s%02d:%02d:%02d",
                                    sign,
                                    (int) (absSecs / (60.0 * 60.0)),
                                    ((int) (absSecs / 60.0)) % 60,
                                    ((int) absSecs) % 60);
    else
        result = String::formatted ("%s%d:%02d",
                                    sign,
                                    ((int) (absSecs / 60.0)) % 60,
                                    ((int) absSecs) % 60);

…and the only way I can see that going wrong would be if the underlying APIs weren’t using UTF8