ID of a new utterance in the Waveform view must be unique
Description
In the Waveform view - Edit mode, newly added utterances may get lost after the "Sort utterances" button is clicked.
Steps to reproduce
- logged in, go to: https://quest.ms.mff.cuni.cz/teitok-dev/teitok/evaldio/index.php?action=wavesurfer&act=edit&cid=MN-test.xml
- select a random region in the waveform
- press ALT+C, enter "A" as a transcription and "SPEAKER_00" as a speaker, and save; the "A" utterance is added to the end of the document
- click on the "Sort utterances" button; the "A" utterance is ordered according to its start time
- select another random region in the waveform
- press ALT+C, enter "B" as a transcription and "SPEAKER_00" as a speaker, and save; the "B" utterance is added to the end of the document
- click on the "Sort utterances" button; the "B" utterance is ordered according to its start time, but the "A" utterance disappears
Analysis
The problem is that both "A" and "B" have been assigned the same id="u-59-1". However, the uttarray
array indexed by utterances' IDs is able to index just one of them (https://gitlab.com/maartenes/TEITOK/-/blob/master/Scripts/wavesurfer.js?ref_type=heads#L302). As the uttarray
array is then used in sorting utterances, all but one utterance sharing the same ID are deleted (https://gitlab.com/maartenes/TEITOK/-/blob/master/Scripts/wavesurfer.js?ref_type=heads#L648-664).
ID for a new utterance is formed using the ID of the last utterance (https://gitlab.com/maartenes/TEITOK/-/blob/master/Scripts/wavesurfer.js?ref_type=heads#L294). After sorting the utterances, the "A" is no longer the last one and the "B" utterance is thus assigned the same ID.
To prevent this issue, one should check all the utterances' IDs to guarantee that the new ID is really unique.