Changeset 35542


Ignore:
Timestamp:
2021-10-01T15:01:09+13:00 (3 years ago)
Author:
cstephen
Message:

WordTimingSelector is now fully reactive

Location:
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components
Files:
2 edited

Legend:

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

    r35541 r35542  
    2020    </div>
    2121
    22     <word-timing-selector class="word-timing-selector" :surroundingWords="surroundingWords" :word="selectedWord" v-if="enableEditing" />
     22    <word-timing-selector class="word-timing-selector" :surroundingWords="surroundingWords" v-model:word="selectedWord" v-if="enableEditing" />
    2323
    2424    <div class="editor-controls">
     
    9797     * @param {Number} endTime The time within the audio that this word finishes being spoken.
    9898     */
    99     constructor(word, startTime, endTime) {
     99    constructor(word, startTime, endTime, id = null, shouldHighlight = false, deletionAttempts = 0) {
    100100        /** @type {String} The ID of this word. */
    101         this.id = Util.generateUuid();
     101        this.id = id ?? Util.generateUuid();
    102102
    103103        /** @type {String} The word. */
     
    111111
    112112        /** @type {Boolean} A value indicating whether this word should be highlighted. */
    113         this.shouldHighlight = false;
     113        this.shouldHighlight = shouldHighlight;
    114114
    115115        /** @type {Number} The number of times the user has tried to delete this word. */
    116         this.deletionAttempts = 0;
     116        this.deletionAttempts = deletionAttempts;
    117117    }
    118118}
     
    150150            return this.getSurroundingWords(this.selectedIndex);
    151151        },
    152         selectedWord() {
    153             return this.words[this.selectedIndex];
     152        selectedWord: {
     153            get() {
     154                return this.words[this.selectedIndex];
     155            },
     156            set(value) {
     157                this.words[this.selectedIndex] = value;
     158            }
    154159        },
    155160        ...mapState({
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/WordTimingSelector.vue

    r35540 r35542  
    7777
    7878<script>
     79import { Word as TWord } from "./TranscriptionItemEditor.vue"
    7980import Util from "../js/Util"
    8081
     
    9798    name: "WordTimingSelector",
    9899    props: {
    99         /** @type {Array<{ word: String, startTime: Number, endTime: Number }>} */
     100        /** @type {Array<TWord>} */
    100101        surroundingWords: Array,
    101         word: { word: String, startTime: Number, endTime: Number },
     102        word: TWord,
    102103        upperBound: Number
    103104    },
     
    106107            isMounted: false,
    107108            /** @type {Array<Word>} */
    108             mySurroundingWords: [],
     109            // mySurroundingWords: [],
    109110            canShiftMinValue: false,
    110111            canShiftMaxValue: false,
     
    142143        },
    143144        audioSnippetLength() {
    144             return this.surroundingWords[this.surroundingWords.length - 1].endTime - this.surroundingWords[0].startTime;
     145            if (this.surroundingWords.length === 0) {
     146                return 0;
     147            }
     148            else {
     149                return this.surroundingWords[this.surroundingWords.length - 1].endTime - this.surroundingWords[0].startTime;
     150            }
    145151        },
    146152        /**
     
    157163        wordLeftOffsetPx() {
    158164            return this.surroundingWords[0].startTime * this.scalingFactor;
    159         }
    160     },
    161     watch: {
    162         surroundingWords() {
    163             this.mySurroundingWords = this.convertSurroundingWords();
     165        },
     166        mySurroundingWords() {
     167            const myWords = [];
     168
     169            if (this.surroundingWords.length === 0) {
     170                return myWords;
     171            }
     172
     173            for (const word of this.surroundingWords) {
     174                myWords.push(this.convertWord(word));
     175            }
     176
     177            return myWords;
    164178        }
    165179    },
     
    188202        },
    189203        shouldHoist(word) {
    190             return word && this.word && word.startTime === this.word.startTime && word.word === this.word.word;
     204            return word === this.myWord;
    191205        },
    192206        /**
     
    198212            }
    199213
    200             const word = this.myWord;
     214            const word = this.mySurroundingWords[this.wordIndex];
    201215
    202216            if (event.movementX < 0 && word.left + event.movementX < 0) {
     
    208222            }
    209223
    210             word.left += event.movementX;
     224            this.mySurroundingWords[this.wordIndex].left += event.movementX;
    211225            word.length -= event.movementX;
    212226        },
     
    229243
    230244            word.length += event.movementX;
     245            this.myWordToWord();
    231246        },
    232247        onHandleMouseUp() {
    233248            this.canShiftMinValue = false;
    234249            this.canShiftMaxValue = false;
     250        },
     251        myWordToWord() {
     252            const pxLeft = this.myWord.left;
     253            const pxRight = this.myWord.left + this.myWord.length;
     254
     255            const startTime = (pxLeft + this.wordLeftOffsetPx) / this.scalingFactor;
     256            const endTime = (pxRight + this.wordLeftOffsetPx) / this.scalingFactor;
     257
     258            const word = new TWord(this.word.word, startTime, endTime, this.word.id, this.word.shouldHighlight, this.word.deletionAttempts);
     259            this.$emit("update:word", word);
    235260        }
    236261    },
     
    240265    mounted() {
    241266        this.isMounted = true;
    242         this.mySurroundingWords = this.convertSurroundingWords();
    243267    }
    244268}
Note: See TracChangeset for help on using the changeset viewer.