Changeset 35601


Ignore:
Timestamp:
2021-10-15T09:50:47+13:00 (3 years ago)
Author:
cstephen
Message:

Begin updating time adjustment logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/WordTimingSelector.vue

    r35549 r35601  
    1010
    1111        <div class="word-attachment-container" :style="{ left: leftHandleLeft }">
    12             <span>{{ wordStartTime }}</span>
    13             <span v-if="isMounted" class="material-icons mdi-m word-handle" @mousedown="canShiftMinValue = true">
     12            <span>{{ wordStartTimeString }}</span>
     13            <span v-if="isMounted" class="material-icons mdi-m word-handle" @mousedown="canAdjustWordStartTime = true">
    1414                first_page
    1515            </span>
     
    1717
    1818        <div class="word-attachment-container" :style="{ left: rightHandleLeft }">
    19             <span v-if="isMounted" class="material-icons mdi-m word-handle" @mousedown="canShiftMaxValue = true">
     19            <span v-if="isMounted" class="material-icons mdi-m word-handle" @mousedown="canAdjustWordEndTime = true">
    2020                last_page
    2121            </span>
    22             <span>{{ wordEndTime }}</span>
     22            <span>{{ wordEndTimeString }}</span>
    2323        </div>
    2424    </div>
     
    112112        /** @type {Array<TWord>} */
    113113        surroundingWords: Array,
    114         word: TWord,
    115         upperBound: Number
     114        word: TWord
    116115    },
    117116    data() {
     
    120119            /** @type {Array<Word>} */
    121120            // mySurroundingWords: [],
    122             canShiftMinValue: false,
    123             canShiftMaxValue: false,
     121            canAdjustWordStartTime: false,
     122            canAdjustWordEndTime: false,
    124123            wordsContainerWidth: 0,
    125124            isProduction: false
     
    145144            return Util.formatSecondsTimeString(this.surroundingWords[this.surroundingWords.length - 1].endTime, false, 2);
    146145        },
    147         wordStartTime() {
     146        wordStartTimeString() {
    148147            return Util.formatSecondsTimeString(this.word.startTime, false, 2);
    149148        },
    150         wordEndTime() {
     149        wordEndTimeString() {
    151150            return Util.formatSecondsTimeString(this.word.endTime, false, 2);
    152151        },
     
    166165            }
    167166            else {
    168                 return this.surroundingWords[this.surroundingWords.length - 1].endTime - this.surroundingWords[0].startTime;
     167                let length = this.surroundingWords[this.surroundingWords.length - 1].endTime;
     168
     169                // Removes the buffer from 0s
     170                if (this.wordIndex !== 0) {
     171                    length -= this.surroundingWords[0].startTime;
     172                }
     173
     174                return length;
    169175            }
    170176        },
     
    181187         */
    182188        wordLeftOffsetPx() {
    183             return this.surroundingWords[0].startTime * this.scalingFactor;
     189            if (this.wordIndex === 0) {
     190                return 0;
     191            }
     192            else {
     193                return this.surroundingWords[0].startTime * this.scalingFactor;
     194            }
    184195        },
    185196        mySurroundingWords() {
     
    214225            return myWords;
    215226        },
     227        scaleTime(time) {
     228            return time * this.scalingFactor;
     229        },
     230        timeToPosition(time) {
     231            return time * this.scalingFactor - this.wordLeftOffsetPx;
     232        },
    216233        convertWord(word) {
    217             const left = (word.startTime * this.scalingFactor - this.wordLeftOffsetPx);
     234            const left = this.timeToPosition(word.startTime);
    218235            const length = (word.endTime - word.startTime) * this.scalingFactor;
    219236
     
    228245            }
    229246
    230             if (this.canShiftMinValue) {
     247            if (this.canAdjustWordStartTime) {
    231248                this.onMinHandleMouseMove(event);
    232249            }
    233             else if (this.canShiftMaxValue) {
     250            else if (this.canAdjustWordEndTime) {
    234251                this.onMaxHandleMouseMove(event);
    235252            }
     
    243260            }
    244261
    245             const word = this.mySurroundingWords[this.wordIndex];
    246 
    247             if (event.movementX < 0 && word.left + event.movementX < 0) {
    248                 return;
    249             }
    250 
    251             if (event.movementX > 0 && word.left + event.movementX >= word.right()) {
    252                 return;
    253             }
    254 
    255             this.mySurroundingWords[this.wordIndex].left += event.movementX;
    256             word.length -= event.movementX;
     262            // const word = this.mySurroundingWords[this.wordIndex];
     263
     264            // if (event.movementX < 0 && word.left + event.movementX < 0) {
     265            //     return;
     266            // }
     267
     268            // if (event.movementX > 0 && word.left + event.movementX >= word.right()) {
     269            //     return;
     270            // }
     271
     272            // word.left += event.movementX;
     273            // word.length -= event.movementX;
     274
     275            this.adjustWordStartTime(event.movementX);
    257276
    258277            this.myWordToWord();
     
    280299        },
    281300        onDocumentMouseUp() {
    282             this.canShiftMinValue = false;
    283             this.canShiftMaxValue = false;
     301            this.canAdjustWordStartTime = false;
     302            this.canAdjustWordEndTime = false;
    284303        },
    285304        myWordToWord() {
     
    292311            const word = new TWord(this.word.word, startTime, endTime, this.word.id, this.word.shouldHighlight, this.word.deletionAttempts);
    293312            this.$emit("update:word", word);
     313        },
     314        adjustWordStartTime(amount) {
     315            const word = this.mySurroundingWords[this.wordIndex];
     316            word.left += amount;
     317            word.length -= amount;
     318
     319            if (amount < 0) {
     320                if (this.wordIndex === 0) {
     321                    if (word.left > 0) {
     322                        return;
     323                    }
     324
     325                    const diff = 0 - word.left;
     326                    word.left = 0;
     327                    word.length -= diff;
     328                }
     329                else {
     330                    // Adjust previous word
     331                    const previousWord = this.mySurroundingWords[this.wordIndex - 1];
     332
     333                    if (word.left > previousWord.right()) {
     334                        return;
     335                    }
     336
     337                    const diff = word.left - previousWord.right(); // Will be negative
     338                    word.left -= diff;
     339                    word.length += diff;
     340
     341                    // TODO: This logic needs all words to be reactively updated to work
     342
     343                    // previousWord.length += amount;
     344                    // const leftBoundary = previousWord.left + this.timeToPosition(0.1);
     345
     346                    // if (previousWord.right() > leftBoundary) {
     347                    //     return;
     348                    // }
     349
     350                    // const diff = leftBoundary - previousWord.right(); // Will be negative
     351                    // word.left -= diff;
     352                    // word.length += diff;
     353                    // previousWord.length -= diff;
     354                }
     355            }
     356            else {
     357                if (word.left > (word.right() - this.scaleTime(0.1))) {
     358                    const diff = word.left - (word.right() - this.scaleTime(0.1)) // Will be positive
     359                    word.left -= diff;
     360                    word.length += diff;
     361                }
     362            }
    294363        }
    295364    },
Note: See TracChangeset for help on using the changeset viewer.