# move_bound_zerocross.psc # Moves the boundary (on the selected tier) nearest to the cursor # to the zero crossing nearest to the cursor # # All the tiers in the TextGrid should be _IntervalTiers_ # # Boundaries aligned with the boundary on the selected tier # will also be moved # # Select TextGrid + Sound | Edit | run this script # # 09.11.2005 John Tøndering # Textgrid and numbers of tiers textgrid = selected("TextGrid") select 'textgrid' endeditor numberOfTiers = Get number of tiers editor 'textgrid' # Where is the cursor now? cursor_time = Get cursor # Starting and end point of the interval containing the cursor position int_start = Get starting point of interval int_end = Get end point of interval # The cursors position relative to the start/end of the interval time_before = cursor_time - int_start time_after = int_end - cursor_time # Which boundary is the nearest? if time_before < time_after boundary_time = int_start else boundary_time = int_end endif # Move cursor to the nearest zero crossing Move cursor to nearest zero crossing # And that is? (The new boundary position) new_boundary_time = Get cursor from_tier = 0 tier_cached = 0 # Checking and moving... if boundary_time <> new_boundary_time for i to numberOfTiers endeditor if new_boundary_time < boundary_time old_inval = Get interval at time... i cursor_time test_time = Get end point... i old_inval if new_boundary_time <> test_time and test_time = boundary_time if tier_cached = 0 from_tier = i tier_cached = 1 endif editor 'textgrid' Add on tier 'i' endeditor Remove boundary at time... i boundary_time endif elsif new_boundary_time > boundary_time old_inval = Get interval at time... i new_boundary_time test_time = Get starting point... i old_inval if test_time <> new_boundary_time and test_time = boundary_time if tier_cached = 0 from_tier = i tier_cached = 1 endif label$ = Get label of interval... i old_inval Set interval text... i old_inval editor 'textgrid' Add on tier 'i' endeditor Set interval text... i old_inval+1 'label$' Remove boundary at time... i boundary_time endif endif endfor editor 'textgrid' Add interval tier... numberOfTiers+1 DEL Remove entire tier for z to from_tier-1 Select next tier endfor endif