-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_each.proc
196 lines (168 loc) · 5.04 KB
/
view_each.proc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# View each selected Sound (and TextGrid) object in turn
#
# This script is part of the vieweach CPrAN plugin for Praat.
# The latest version is available through CPrAN or at
# <http://cpran.net/plugins/vieweach>
#
# The vieweach plugin 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.
#
# The vieweach plugin 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 vieweach. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2012-2015 Jose Joaquin Atria
procedure view_each.before_iteration ()
@trace: "View each: before iteration"
endproc
procedure view_each.at_begin_iteration ()
@trace: "View each: begin iteration"
endproc
procedure view_each.before_editor ()
@trace: "View each: before editor"
endproc
procedure view_each.at_begin_editor ()
@trace: "View each: begin editor"
.editor$ = Editor info
view_each.name$ = extractLine$(.editor$, "Editor name: ")
view_each.name$ = mid$(view_each.name$,
... rindex(view_each.name$, " "), length(view_each.name$))
endproc
procedure view_each.at_end_editor ()
@trace: "View each: end editor"
Close
endproc
procedure view_each.after_editor ()
@trace: "View each: after editor"
endproc
procedure view_each.no_editor ()
endproc
procedure view_each.at_end_iteration ()
endproc
procedure view_each.finally ()
endproc
procedure view_each.clean_exit: .message$
@for_each.clean_exit: .message$
endproc
procedure view_each.pause ()
if !variableExists("view_each.name$")
view_each.name$ = string$(undefined)
endif
beginPause: "Viewing " + view_each.name$ + " " + "(" +
... string$(for_each.item) + " of " +
... string$(for_each.total_items) + ")"
if for_each.item > 1
.button = endPause: "Stop", "Previous",
... if for_each.item = for_each.total_items then
... "Finish" else "Next" fi, 3, 1
else
.button = endPause: "Stop",
... if for_each.item = for_each.total_items then
... "Finish" else "Next" fi, 2, 1
endif
if .button = 1
# Pressed stop
for_each.next = 0
elsif .button = 2 and for_each.item > 1
# Pressed back
for_each.next = -1
else
# Pressed forward
for_each.next = if for_each.item = for_each.total_items then 0 else 1 fi
endif
endproc
procedure for_each.before_iteration ()
@view_each.before_iteration()
endproc
procedure for_each.at_begin_iteration ()
@view_each.at_begin_iteration()
endproc
procedure for_each.at_end_iteration ()
@view_each.at_end_iteration()
endproc
procedure for_each.finally ()
@view_each.finally()
endproc
procedure for_each.action ()
if numberOfSelected()
@has_editor()
if has_editor.editor
view_each.editor$ = has_editor.editor$
# Hook called before editor is opened
@trace: "View each: before editor"
@view_each.before_editor()
do(has_editor.command$)
editor: view_each.editor$
@trace: "View each: begin editor"
@view_each.at_begin_editor()
endeditor
@trace: "View each: pause"
@view_each.pause()
nocheck editor: view_each.editor$
# Hook within editor, after the pause
@trace: "View each: in editor"
@in_editor()
if in_editor.return != undefined and in_editor.return
@trace: "View each: end editor"
@view_each.at_end_editor()
endif
nocheck endeditor
# Hook called after at_end_editor,
# which might not be in an editor
@trace: "View each: after editor"
@view_each.after_editor()
else
# Hook called when no editor is available
@trace: "View each: no editor"
@view_each.no_editor()
endif
endif
endproc
include ../../plugin_vieweach/procedures/for_each.proc
procedure view_each ()
@for_each()
endproc
procedure in_editor ()
.info$ = nocheck Editor info
.return = if .info$ = "" then
... 0 else extractNumber(.info$, "Editor name: ") fi
.return = if .return == undefined then -1 else .return fi
.return$ = extractLine$(extractLine$(.info$, "Editor name: "), " ")
endproc
procedure has_editor ()
.command$ = "View & Edit"
.editor = 0
@_try_editor: .command$
if !'_try_editor.return'
.command$ = "Edit"
@_try_editor: .command$
endif
if !'_try_editor.return'
.command$ = "View"
@_try_editor: .command$
endif
.editor = '_try_editor.return'
.editor$ = "'_try_editor.return$'"
endproc
procedure _try_editor: .command$
nocheck do(.command$)
for .i to numberOfSelected()
nocheck editor: selected$(.i)
@in_editor()
if in_editor.return
Close
endif
nocheck endeditor
if in_editor.return
.i += numberOfSelected()
endif
endfor
.return = in_editor.return
.return$ = in_editor.return$
endproc