- Timestamp:
- 2021-10-15T10:45:15+13:00 (3 years ago)
- 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
r35548 r35602 12 12 <ul class="list-view" v-else> 13 13 <li v-for="(word, index) in words" :key="word.id" class="word-container"> 14 <input :size="word.word.length === 0 ? 1 : word.word.length" :ref="word.id" 14 <!-- :size="word.word.length === 0 ? 1 : word.word.length" --> 15 <input :ref="word.id" 15 16 class="editor-word" v-model="word.word" type="text" :class="{ 'word-highlight-applied': word.shouldHighlight }" 16 17 @beforeinput="onEditorBeforeInput($event, index)" @focusout="onEditorFocusOut(index)" @focus="onEditorFocus(index)" /> … … 20 21 </div> 21 22 22 <word-timing-selector class="word-timing-selector" :surroundingWords="surroundingWords" v-model:word="selectedWord" v-if="enableEditing" />23 <word-timing-selector class="word-timing-selector" v-model:surroundingWords="surroundingWords" :wordIndex="surroundingWordPrincipleIndex" v-if="enableEditing" /> 23 24 </div> 24 25 </template> … … 114 115 words: [], 115 116 lastHighlightedWordIndex: 0, 116 selectedIndex: 0 117 selectedIndex: 0, 118 surroundingWordPrincipleIndex: 0 117 119 } 118 120 }, … … 126 128 } 127 129 }, 128 surroundingWords() { 129 return this.getSurroundingWords(this.selectedIndex); 130 }, 131 selectedWord: { 130 surroundingWords: { 132 131 get() { 133 return this. words[this.selectedIndex];132 return this.getSurroundingWords(this.selectedIndex); 134 133 }, 135 134 set(value) { 136 this. words[this.selectedIndex] = value;135 this.setSurroundingWords(this.selectedIndex, value); 137 136 } 138 137 }, … … 194 193 }, 195 194 195 /** 196 * Gets the minimum viable index that surrounding words can start at. 197 * @param {Number} principleIndex The index of the primary surrounding word. 198 * @param {Number} buffer The maximum number of words to take on each side of the principle word. 199 */ 200 getSurroundingWordMinIndex(principleIndex, buffer) { 201 let min = principleIndex; 202 for (let i = principleIndex; i > principleIndex - buffer && i > 0; i--) { 203 min--; 204 } 205 206 return min; 207 }, 208 196 209 getSurroundingWords(index) { 197 210 const BUFFER = 2; // The number of words to take on each side 198 211 199 let min = index; 200 for (let i = index; i > index - BUFFER && i > 0; i--) { 201 min--; 202 } 212 const min = this.getSurroundingWordMinIndex(index, BUFFER); 203 213 204 214 let max = index + 1; … … 207 217 } 208 218 219 this.surroundingWordPrincipleIndex = index - min; 209 220 return this.words.slice(min, max); 221 }, 222 223 /** 224 * Sets the backing value of the surrounding words variable. 225 * @param {Number} index The index in the back array at which to update the words. 226 * @param {Array<Word>} value The updated words. 227 */ 228 setSurroundingWords(index, value) { 229 const BUFFER = 2; // The number of words to take on each side TODO: Global constant 230 231 const startIndex = this.getSurroundingWordMinIndex(index, BUFFER); 232 console.log(this.words); 233 this.words.splice(startIndex, value.length - 1, value); 234 console.log(this.words); 210 235 }, 211 236 -
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/WordTimingSelector.vue
r35601 r35602 112 112 /** @type {Array<TWord>} */ 113 113 surroundingWords: Array, 114 word : TWord114 wordIndex: Number 115 115 }, 116 116 data() { 117 117 return { 118 118 isMounted: false, 119 /** @type {Array<Word>} */120 // mySurroundingWords: [],121 119 canAdjustWordStartTime: false, 122 120 canAdjustWordEndTime: false, … … 125 123 } 126 124 }, 127 emits: [ "update: word" ],125 emits: [ "update:surroundingWords" ], 128 126 computed: { 127 word() { 128 return this.surroundingWords[this.wordIndex]; 129 }, 129 130 myWord() { 130 131 return this.mySurroundingWords[this.wordIndex]; … … 156 157 rightHandleLeft() { 157 158 return `calc(${this.myWord.left}px + ${this.myWord.length}px)`; 158 },159 wordIndex() {160 return this.surroundingWords.indexOf(this.word);161 159 }, 162 160 audioSnippetLength() { … … 212 210 this.wordsContainerWidth = newValue; 213 211 }, 214 convertSurroundingWords() {215 const myWords = [];216 217 if (this.surroundingWords.length === 0) {218 return myWords;219 }220 221 for (const word of this.surroundingWords) {222 myWords.push(this.convertWord(word));223 }224 225 return myWords;226 },227 212 scaleTime(time) { 228 213 return time * this.scalingFactor; … … 275 260 this.adjustWordStartTime(event.movementX); 276 261 277 this. myWordToWord();262 this.updateSurroundingWords(); 278 263 }, 279 264 onMaxHandleMouseMove(event) { … … 296 281 word.length += event.movementX; 297 282 298 this. myWordToWord();283 this.updateSurroundingWords(); 299 284 }, 300 285 onDocumentMouseUp() { … … 302 287 this.canAdjustWordEndTime = false; 303 288 }, 304 myWordToWord() {305 const pxLeft = this.myWord.left;306 const pxRight = this.myWord.left + this.myWord.length;307 308 const startTime = (pxLeft + this.wordLeftOffsetPx) / this.scalingFactor;309 const endTime = (pxRight + this.wordLeftOffsetPx) / this.scalingFactor;310 311 const word = new TWord(this.word.word, startTime, endTime, this.word.id, this.word.shouldHighlight, this.word.deletionAttempts);312 this.$emit("update:word", word);313 },314 289 adjustWordStartTime(amount) { 315 const word = this.my SurroundingWords[this.wordIndex];290 const word = this.myWord; 316 291 word.left += amount; 317 292 word.length -= amount; … … 361 336 } 362 337 } 338 }, 339 updateSurroundingWords() { 340 const updatedWords = []; 341 342 for (let i = 0; i < this.mySurroundingWords.length; i++) { 343 updatedWords.push( 344 this.convertMyWord(this.mySurroundingWords[i], this.surroundingWords[i]) 345 ); 346 } 347 348 console.log(updatedWords); 349 this.$emit("update:surroundingWords", updatedWords); 350 }, 351 convertMyWord(myWord, actualWord) { 352 const startTime = (myWord.left + this.wordLeftOffsetPx) / this.scalingFactor; 353 const endTime = (myWord.right() + this.wordLeftOffsetPx) / this.scalingFactor; 354 355 return new TWord(actualWord.word, startTime, endTime, actualWord.id, actualWord.shouldHighlight, actualWord.deletionAttempts); 363 356 } 364 357 },
Note:
See TracChangeset
for help on using the changeset viewer.