# drawSemitonesMidpoint.praat. Praat script to draw a Pitch object
# in semitones, scaled and drawn to a user-defined midpoint.
# Copyright (C) 2016 Gareth Walker.
# g.walker@sheffield.ac.uk
# School of English
# University of Sheffield
# Jessop West
# 1 Upper Hanover Street
# Sheffield
# S3 7RA
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# .
form Speckle semitones re. baseline
real left_Time_range_(s) 0.0
real right_Time_range_(s) 0.0 (=all)
real left_Range_(Hz) 50
real right_Range_(Hz) 400
real Midpoint_(Hz) 100
boolean Show_boundaries 1
choice Style 1
button Draw
button Speckle
boolean Garnish 1
choice Pitch_marks 1
button Top and bottom
button Marks every octave
endform
if show_boundaries = 1
bound$="yes"
else
bound$="no"
endif
if left_Time_range = 0
start = Get start time
left_Time_range = start
endif
if right_Time_range = 0
end = Get end time
right_Time_range = end
endif
base = 12*log2(left_Range/midpoint)
top = 12*log2(right_Range/midpoint)
basePrune = 'base:1'
topPrune='top:1'
pitch = selected ("Pitch")
Axes: left_Time_range, right_Time_range, (12*log2(left_Range/midpoint)),
... (12*log2(right_Range/midpoint))
selectObject: pitch
frames = Get number of frames
if style = 1
step = Get time step
halfStep = step/2
for i from 1 to frames
time = Get time from frame number: i
value = Get value in frame: i, "Hertz"
preValue = Get value in frame: i-1, "Hertz"
postValue = Get value in frame: i+1, "Hertz"
preValueInc = ((preValue-value)/2)+value
postValueInc = ((postValue-value)/2)+value
if time > left_Time_range and time < right_Time_range and value <> undefined
if preValue = undefined and postValue = undefined
Draw line: time-halfStep, 12*log2(value/midpoint), time+halfStep, 12*log2(value/midpoint)
elsif preValue <> undefined and postValue <> undefined
Draw line: time-halfStep, 12*log2(preValueInc/midpoint), time, 12*log2(value/midpoint)
Draw line: time, 12*log2(value/midpoint), time+halfStep, 12*log2(postValueInc/midpoint)
elsif preValue = undefined and postValue <> undefined
Draw line: time-halfStep, 12*log2(value/midpoint), time, 12*log2(value/midpoint)
Draw line: time, 12*log2(value/midpoint), time+halfStep, 12*log2(postValueInc/midpoint)
elsif preValue <> undefined and postValue = undefined
Draw line: time-halfStep, 12*log2(preValueInc/midpoint), time, 12*log2(value/midpoint)
Draw line: time, 12*log2(value/midpoint), time+halfStep, 12*log2(value/midpoint)
endif
endif
endfor
elsif style = 2
for i from 1 to frames
time = Get time from frame number: i
if time > left_Time_range and time < right_Time_range
value = Get value in frame: i, "Hertz"
if value <> undefined
Paint circle (mm): "black", time, 12*log2(value/midpoint), 1.0
endif
endif
endfor
endif
if garnish = 1
Draw inner box
Text left: "yes", "Pitch (semitones %%re% midpoint)"
Text bottom: "yes", "Time (s)"
One mark left: basePrune, "yes", "yes", "no", ""
if pitch_marks = 1
One mark left: topPrune, "yes", "yes", "no", ""
elsif pitch_marks = 2
Marks left every: 1, 12, "yes", "yes", "no"
endif
One mark bottom: 'left_Time_range:3', "yes", "yes", "no", ""
One mark bottom: 'right_Time_range:3', "yes", "yes", "no", ""
endif