Editor crash when SV.getPhonemesForGroup with a newly created reference with SV.create("NoteGroupReference")

I’m writing a function that passes in a single note to get a phoneme. Checking the manual on the official website, if I want to call the built-in text to phoneme converter I should only be able to pass in a NoteGroupReference using SV.getPhonemesForGroup(), so I tried to build a reference that contains only one note and pass it to the converter. , but at this point the editor crashes without giving an error report (see the code at the bottom).
I’m not sure if there’s a better implementation of this function, but in this case I’m guessing that the newly created reference doesn’t have the appropriate context (voice, language, time and pitch offset in the manual) causing the crash. So I tried assigning the voice, time and pitch offset from the existing reference to the newly created reference but it still crashes. It could be the missing language context, but I don’t know how to get and set this parameter when reading the manual.

Additonal infomation:

  • os: windows 11 pro 22h2
  • editor: sv pro 1.11.0b1
function getClientInfo() {
    return {
        "name": "Crash",
        "category": "Example",
        "author": "Bob Alice",
        "versionNumber": 1,
        "minEditorVersion": 65540
    };
}


/**
 * return a list of phonemes in a given note.
 * @param {Note} note
 * @returns {Array<String>}
 */
function getNotePhonemes(note) {
    if (note.getPhonemes() === "") {
        var groupRef = SV.create("NoteGroupReference");
        var group = SV.create("NoteGroup");
        group.addNote(note.clone());
        groupRef.setTarget(group);
        //where the editor would crash
        return SV.getPhonemesForGroup(groupRef)[0].split(" ");
    } else {
        return note.getPhonemes().split(" ");
    }
}

function main() {
    var notes = SV.getMainEditor().getSelection().getSelectedNotes();
    for (var i = 0; i < notes.length; i++) {
        var note = notes[i];
        try {
            var ph = getNotePhonemes(note);
            SV.showMessageBox("Note: " + note.getLyrics(), ph.toString());
        } catch (error) {
            SV.showMessageBox("Error", error.name + ": " + error.message);
        }
    }
    SV.finish();
}

Beside the crashing, I notice that the javascript stander is es5. As far as I’m consoned it is outdated and needed to be upgraded to es6 for one big reason. that is for people who are new to js, most of the new reference you can find online is base on es6 which is not compactable with current version that is used in sv. especialy when you google with keywords that directly ask for solution to a specific problem, the resultes you get have a greate possibility of using es6 features (like reference from mozilla, which would not tell you it is es6 specific or not, it only tell you how well do different browers support), which, again, is hard to tell for js beginner. what worse is that when it comes to this situation, sv would only give you an syntax error on certain line, but not what excatlly cause the error, and that would be really confusing. So it would be really nice to have es6 in sv scripting.

A NoteGroupReference created in this way is not part of the project.

Get the phonemes for all notes in a group (passed in as a group reference). The group must be part of the currently open project.

The bigger obstacle is that it has no language associated with it, so there is no default dictionary to perform lookups against (and no phonemes to return). Since you can’t change the language for a track or group using scripts, you’d have to add the group reference to a track so it would inherit the track’s language setting.

Take note of this paragraph in the documentation. If the group has no language set, text-to-phoneme conversion is never run, and therefore has not finished for the group. Even if you add the group to a track programatically, without adding a small delay the phoneme conversion might not have completed if you call getPhonemesForGroup immediately after.

Also note that the text-to-phoneme converter runs on a different thread. getPhonemesForGroup does not block the current thread. There’s a slight chance of returning an empty array if text-to-phoneme conversion has not yet finished on the group.


But, that aside, since you already have the note selected in the project it would be much simpler to skip the whole group creation step. The index in the array returned by getPhonemesForGroup will match the index returned by Note.getIndexInParent. For example:

function getNotePhonemes(note) {
    var editorView = SV.getMainEditor();
    var groupPhones = SV.getPhonemesForGroup(editorView.getCurrentGroup())
    return groupPhones[note.getIndexInParent()].split(" ");
}


If you’re struggling with the ES5 syntax, you might benefit from making your scripts in Lua instead, since it’s much easier to find version-relevant resources and documentation. As-is there is no ES6+ version of DukTape, so Dreamtonics would have to implement a completely different JavaScript engine, and I doubt that’s very high on the priority list.

「いいね!」 1

Thanks for the quick response! Your explanation and solution really help a lot. So if I’m not mistaken, currently you can not get or set language in the track using only script, is that correct? Lua is new to me but I’ve heard of its simplicity, so I would consider that. Maybe that’s a good chance to learn a new language!