diff --git a/.gitmodules b/.gitmodules index 0dac6c83f7..4ed1baaa2e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -962,6 +962,9 @@ [submodule "vendor/grammars/powershell"] path = vendor/grammars/powershell url = https://github.com/PowerShell/EditorSyntax +[submodule "vendor/grammars/praatvscode"] + path = vendor/grammars/praatvscode + url = https://github.com/orhunulusahin/praatvscode.git [submodule "vendor/grammars/processing.tmbundle"] path = vendor/grammars/processing.tmbundle url = https://github.com/textmate/processing.tmbundle diff --git a/grammars.yml b/grammars.yml index 38a00c634a..0046097d76 100644 --- a/grammars.yml +++ b/grammars.yml @@ -892,6 +892,9 @@ vendor/grammars/portugol-grammar: - source.portugol vendor/grammars/powershell: - source.powershell +vendor/grammars/praatvscode: +- source.praat +- source.textgrid vendor/grammars/processing.tmbundle: - source.processing vendor/grammars/python-django.tmbundle: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index c2fc588b6d..9b8304d549 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -5338,6 +5338,14 @@ PowerShell: interpreters: - pwsh language_id: 293 +Praat: + type: programming + color: "#c8506d" + tm_scope: source.praat + ace_mode: praat + extensions: + - ".praat" + language_id: 106029007 Prisma: type: data color: "#0c344b" diff --git a/samples/Praat/dynamicity.praat b/samples/Praat/dynamicity.praat new file mode 100644 index 0000000000..0f485c888c --- /dev/null +++ b/samples/Praat/dynamicity.praat @@ -0,0 +1,175 @@ +form Textgrid Convolution + comment calculate a Moving Average across a textgrid. + comment does not perform an fft convolution, instead using a dumb algorithm. + comment presumes the textgrid is selected. + real steps_per_second 5 + real window_length_sec 5 + optionmenu kernel 1 + option moving_average +# option gaussian + optionmenu normalisation 1 + option amount + option window_length + option none + endform + +nrTiers = Get number of tiers +isInterval = Is interval tier: 1 + +if nrTiers != 1 + exitScript: "Can only use dynamicity.praat on a TextGrid with exactly one Tier" + endif + +if isInterval == 1 + @preposess_intervals + @calculate_nr_steps + @interval_convolution + @write_to_textgrid +else + @calculate_nr_steps + @point_convolution + @write_to_textgrid + endif + + +procedure preposess_intervals + nrIntervals = Get number of intervals: 1 + + for i to nrIntervals + label$ = Get label of interval: 1, i + if label$ <> "" and label$ != "MISSING" + variable = number(label$) + Set interval text: 1, i, string$(variable) + endif + endfor +endproc + +procedure calculate_nr_steps + start = Get start time + end = Get end time + duration = end - start + nrSteps = floor((duration-window_length_sec)*steps_per_second) + if nrSteps < 0 + nrSteps = 0 + endif +endproc + +procedure interval_convolution + k=1 + movingStart = start + movingEnd = movingStart + window_length_sec + nrIntervals = Get number of intervals: 1 + + if nrIntervals == 0 + nrSteps = 0 + k = 0 + endif + + result# = zero#(nrSteps) + for i to nrSteps + intervalEnd = Get end time of interval: 1, k + while (intervalEnd < movingStart) and (k < nrIntervals) + k+=1 + intervalEnd = Get end time of interval: 1, k + endwhile + + movingSum = 0 + amountSummed = 0 + + j=0 + intervalStart = Get start time of interval: 1, k+j + while (intervalStart < movingEnd) and (k+j <= nrIntervals) + label$ = Get label of interval: 1, k+j + if label$ <> "" and label$ != "MISSING" + movingSum += number(label$) + amountSummed+= 1 + endif + + j+=1 + if (k+j <= nrIntervals) + intervalStart = Get start time of interval: 1, k+j + endif + endwhile + + movingStart+=(1/steps_per_second) + movingEnd+=(1/steps_per_second) + + if normalisation == 1 + result#[i] = movingSum/amountSummed + elsif normalisation == 2 + result#[i] = movingSum/window_length_sec + elsif normalisation == 3 + result#[i] = movingSum + endif + endfor +endproc + +procedure point_convolution + k=1 + movingStart = start + movingEnd = movingStart + window_length_sec + nrPoints = Get number of points: 1 + + if nrPoints == 0 + nrSteps = 0 + k = 0 + endif + + result# = zero#(nrSteps) + for i to nrSteps + pointStart = Get time of point: 1, k + while (pointStart < movingStart) and (k < nrPoints) + k+=1 + pointStart = Get time of point: 1, k + endwhile + + movingSum = 0 + amountSummed = 0 + + j=0 + pointEnd = Get time of point: 1, k+j + while (pointEnd < movingEnd) and (k+j <= nrPoints) + movingSum += 1 + + j+=1 + if (k+j <= nrPoints) + pointEnd = Get time of point: 1, k+j + endif + endwhile + + movingStart+=(1/steps_per_second) + movingEnd+=(1/steps_per_second) + + result#[i] = movingSum + endfor +endproc + +procedure write_to_textgrid + tierName$ = Get tier name: 1 + Insert interval tier: 2, tierName$ + "Dyn" + + movingBoundary = (window_length_sec/2) - ((1/steps_per_second)/2) + + if movingBoundary <= 0 + start = 0.01 + else + start = movingBoundary + endif + + Insert boundary: 2, start + + for i to nrSteps + movingBoundary+= 1/steps_per_second + + if movingBoundary >= end + movingBoundary = end - (0.01 * nrSteps - (i + 1)) + endif + + Insert boundary: 2, movingBoundary + if result#[i] == undefined + Set interval text: 2, i+1, "" + else + Set interval text: 2, i+1, string$(result#[i]) + endif + endfor +endproc diff --git a/samples/Praat/queryTable.praat b/samples/Praat/queryTable.praat new file mode 100644 index 0000000000..2eb3e1185e --- /dev/null +++ b/samples/Praat/queryTable.praat @@ -0,0 +1,73 @@ +form Querying + integer tier 1 + integer nrFormants 10 +endform + +idSounds = Create Strings as file list: "Sounds", "*.flac" +idGrids = Create Strings as file list: "Grids", "*.TextGrid" +nrGrids = Get number of strings + +for i to nrGrids + selectObject: idSounds + sound$ = Get string: i + idSound = Read from file: sound$ + + idFormant = To Formant (burg): 0, 5, 5500, 0.025, 50 + + selectObject: idGrids + grid$ = Get string: i + + idTable = Create Table with column names: grid$, 0, "Index Vowel Start End Duration F1 F2" + idGrid = Read from file: grid$ + + nrInt = Get number of intervals: tier + k = 1 + + for j to nrInt + lab$ = Get label of interval: tier, j + + if lab$ = "aa" or lab$ = "u" or lab$ = "i" + + index$ = string$(k) + start = Get start time of interval: tier, j + start$ = string$(start) + end = Get end time of interval: tier, j + end$ = string$(end) + dur = end - start + dur$ = string$(dur) + + for l to nrFormants + row = l + (k-1)*nrFormants + time = start + dur*(l/nrFormants) + + selectObject: idFormant + f1$ = Get value at time: 1, time, "hertz", "linear" + f2$ = Get value at time: 2, time, "hertz", "linear" + + selectObject: idTable + Insert row: row + Set string value: row, "Index", index$ + Set string value: row, "Vowel", lab$ + Set string value: row, "Start", start$ + Set string value: row, "End", end$ + Set string value: row, "Duration", dur$ + Set string value: row, "F1", f1$ + Set string value: row, "F2", f2$ + + endfor + + selectObject: idGrid + k = k + 1 + endif + + endfor + + name$ = selected$("TextGrid") + selectObject: idTable + Save as tab-separated file: name$ + ".dat" + + removeObject: idSound, idTable, idFormant, idGrid + +endfor + +removeObject: idGrids, idSounds diff --git a/samples/Praat/randomiseArticles.praat b/samples/Praat/randomiseArticles.praat new file mode 100644 index 0000000000..2eb3e1185e --- /dev/null +++ b/samples/Praat/randomiseArticles.praat @@ -0,0 +1,73 @@ +form Querying + integer tier 1 + integer nrFormants 10 +endform + +idSounds = Create Strings as file list: "Sounds", "*.flac" +idGrids = Create Strings as file list: "Grids", "*.TextGrid" +nrGrids = Get number of strings + +for i to nrGrids + selectObject: idSounds + sound$ = Get string: i + idSound = Read from file: sound$ + + idFormant = To Formant (burg): 0, 5, 5500, 0.025, 50 + + selectObject: idGrids + grid$ = Get string: i + + idTable = Create Table with column names: grid$, 0, "Index Vowel Start End Duration F1 F2" + idGrid = Read from file: grid$ + + nrInt = Get number of intervals: tier + k = 1 + + for j to nrInt + lab$ = Get label of interval: tier, j + + if lab$ = "aa" or lab$ = "u" or lab$ = "i" + + index$ = string$(k) + start = Get start time of interval: tier, j + start$ = string$(start) + end = Get end time of interval: tier, j + end$ = string$(end) + dur = end - start + dur$ = string$(dur) + + for l to nrFormants + row = l + (k-1)*nrFormants + time = start + dur*(l/nrFormants) + + selectObject: idFormant + f1$ = Get value at time: 1, time, "hertz", "linear" + f2$ = Get value at time: 2, time, "hertz", "linear" + + selectObject: idTable + Insert row: row + Set string value: row, "Index", index$ + Set string value: row, "Vowel", lab$ + Set string value: row, "Start", start$ + Set string value: row, "End", end$ + Set string value: row, "Duration", dur$ + Set string value: row, "F1", f1$ + Set string value: row, "F2", f2$ + + endfor + + selectObject: idGrid + k = k + 1 + endif + + endfor + + name$ = selected$("TextGrid") + selectObject: idTable + Save as tab-separated file: name$ + ".dat" + + removeObject: idSound, idTable, idFormant, idGrid + +endfor + +removeObject: idGrids, idSounds diff --git a/vendor/README.md b/vendor/README.md index bdc61638b4..c1d5fd8e41 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -425,6 +425,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **PostCSS:** [hudochenkov/Syntax-highlighting-for-PostCSS](https://github.com/hudochenkov/Syntax-highlighting-for-PostCSS) - **PostScript:** [Alhadis/Atom-PostScript](https://github.com/Alhadis/Atom-PostScript) - **PowerShell:** [PowerShell/EditorSyntax](https://github.com/PowerShell/EditorSyntax) +- **Praat:** [orhunulusahin/praatvscode](https://github.com/orhunulusahin/praatvscode) - **Prisma:** [prisma/vscode-prisma](https://github.com/prisma/vscode-prisma) - **Processing:** [textmate/processing.tmbundle](https://github.com/textmate/processing.tmbundle) - **Procfile:** [benspaulding/vscode-procfile](https://github.com/benspaulding/vscode-procfile) diff --git a/vendor/grammars/praatvscode b/vendor/grammars/praatvscode new file mode 160000 index 0000000000..725a508445 --- /dev/null +++ b/vendor/grammars/praatvscode @@ -0,0 +1 @@ +Subproject commit 725a508445b14c3e68b470c9488ede0dc24b9f89 diff --git a/vendor/licenses/git_submodule/praatvscode.dep.yml b/vendor/licenses/git_submodule/praatvscode.dep.yml new file mode 100644 index 0000000000..4feff6dbfe --- /dev/null +++ b/vendor/licenses/git_submodule/praatvscode.dep.yml @@ -0,0 +1,19 @@ +--- +name: praatvscode +version: 725a508445b14c3e68b470c9488ede0dc24b9f89 +type: git_submodule +homepage: https://github.com/orhunulusahin/praatvscode.git +license: mit +licenses: +- sources: LICENSE + text: |- + The MIT License (MIT) + + Copyright © 2022 Orhun Uluşahin + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +notices: []