9ba2b186c359602754f5bcc5057e39c8bfd5e34c
[dcpomatic.git] / src / wx / timing_panel.cc
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "timing_panel.h"
22 #include "wx_util.h"
23 #include "film_viewer.h"
24 #include "timecode.h"
25 #include "content_panel.h"
26 #include "move_to_dialog.h"
27 #include "static_text.h"
28 #include "dcpomatic_button.h"
29 #include "lib/content.h"
30 #include "lib/image_content.h"
31 #include "lib/text_content.h"
32 #include "lib/dcp_subtitle_content.h"
33 #include "lib/audio_content.h"
34 #include "lib/string_text_file_content.h"
35 #include "lib/video_content.h"
36 #include "lib/dcp_content.h"
37 #include "lib/ffmpeg_content.h"
38 #include <dcp/locale_convert.h>
39 #include <boost/foreach.hpp>
40 #include <set>
41 #include <iostream>
42
43 using std::cout;
44 using std::string;
45 using std::set;
46 using boost::shared_ptr;
47 using boost::weak_ptr;
48 using boost::dynamic_pointer_cast;
49 using boost::optional;
50 using dcp::locale_convert;
51
52 TimingPanel::TimingPanel (ContentPanel* p, weak_ptr<FilmViewer> viewer)
53         /* horrid hack for apparent lack of context support with wxWidgets i18n code */
54         /// TRANSLATORS: translate the word "Timing" here; do not include the "Timing|" prefix
55         : ContentSubPanel (p, S_("Timing|Timing"))
56         , _viewer (viewer)
57         , _film_content_changed_suspender (boost::bind(&TimingPanel::film_content_changed, this, _1))
58 {
59         wxSize size = TimecodeBase::size (this);
60
61         for (int i = 0; i < 3; ++i) {
62                 _colon[i] = create_label (this, wxT(":"), false);
63         }
64
65         //// TRANSLATORS: this is an abbreviation for "hours"
66         _h_label = new StaticText (this, _("h"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
67 #ifdef DCPOMATIC_LINUX
68         /* Hack to work around failure to centre text on GTK */
69         gtk_label_set_line_wrap (GTK_LABEL(_h_label->GetHandle()), FALSE);
70 #endif
71         //// TRANSLATORS: this is an abbreviation for "minutes"
72         _m_label = new StaticText (this, _("m"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
73 #ifdef DCPOMATIC_LINUX
74         gtk_label_set_line_wrap (GTK_LABEL (_m_label->GetHandle()), FALSE);
75 #endif
76         //// TRANSLATORS: this is an abbreviation for "seconds"
77         _s_label = new StaticText (this, _("s"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
78 #ifdef DCPOMATIC_LINUX
79         gtk_label_set_line_wrap (GTK_LABEL(_s_label->GetHandle()), FALSE);
80 #endif
81         //// TRANSLATORS: this is an abbreviation for "frames"
82         _f_label = new StaticText (this, _("f"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
83 #ifdef DCPOMATIC_LINUX
84         gtk_label_set_line_wrap (GTK_LABEL(_f_label->GetHandle()), FALSE);
85 #endif
86
87         _position_label = create_label (this, _("Position"), true);
88         _position = new Timecode<DCPTime> (this);
89         _move_to_start_of_reel = new Button (this, _("Move to start of reel"));
90         _full_length_label = create_label (this, _("Full length"), true);
91         _full_length = new Timecode<DCPTime> (this);
92         _trim_start_label = create_label (this, _("Trim from start"), true);
93         _trim_start = new Timecode<ContentTime> (this);
94         _trim_start_to_playhead = new Button (this, _("Trim up to current position"));
95         _trim_end_label = create_label (this, _("Trim from end"), true);
96         _trim_end = new Timecode<ContentTime> (this);
97         _trim_end_to_playhead = new Button (this, _("Trim after current position"));
98         _play_length_label = create_label (this, _("Play length"), true);
99         _play_length = new Timecode<DCPTime> (this);
100
101         _video_frame_rate_label = create_label (this, _("Video frame rate"), true);
102         _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
103         _set_video_frame_rate = new Button (this, _("Set"));
104         _set_video_frame_rate->Enable (false);
105
106         /* We can't use Wrap() here as it doesn't work with markup:
107          * http://trac.wxwidgets.org/ticket/13389
108          */
109
110         wxString in = _("<i>Only change this if the content's frame rate has been read incorrectly.</i>");
111         wxString out;
112         int const width = 20;
113         int current = 0;
114         for (size_t i = 0; i < in.Length(); ++i) {
115                 if (in[i] == ' ' && current >= width) {
116                         out += '\n';
117                         current = 0;
118                 } else {
119                         out += in[i];
120                         ++current;
121                 }
122         }
123
124         _tip = new StaticText (this, wxT (""));
125         _tip->SetLabelMarkup (out);
126 #ifdef DCPOMATIC_OSX
127         /* Hack to stop hidden text on some versions of OS X */
128         _tip->SetMinSize (wxSize (-1, 256));
129 #endif
130
131         _position->Changed.connect    (boost::bind (&TimingPanel::position_changed, this));
132         _move_to_start_of_reel->Bind  (wxEVT_BUTTON, boost::bind (&TimingPanel::move_to_start_of_reel_clicked, this));
133         _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
134         _trim_start->Changed.connect  (boost::bind (&TimingPanel::trim_start_changed, this));
135         _trim_start_to_playhead->Bind (wxEVT_BUTTON, boost::bind (&TimingPanel::trim_start_to_playhead_clicked, this));
136         _trim_end->Changed.connect    (boost::bind (&TimingPanel::trim_end_changed, this));
137         _trim_end_to_playhead->Bind   (wxEVT_BUTTON, boost::bind (&TimingPanel::trim_end_to_playhead_clicked, this));
138         _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
139         _video_frame_rate->Bind       (wxEVT_TEXT, boost::bind (&TimingPanel::video_frame_rate_changed, this));
140         _set_video_frame_rate->Bind   (wxEVT_BUTTON, boost::bind (&TimingPanel::set_video_frame_rate, this));
141
142         shared_ptr<FilmViewer> fv = _viewer.lock ();
143         DCPOMATIC_ASSERT (fv);
144         fv->ImageChanged.connect (boost::bind (&TimingPanel::setup_sensitivity, this));
145
146         setup_sensitivity ();
147         add_to_grid ();
148 }
149
150 void
151 TimingPanel::add_to_grid ()
152 {
153         bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
154
155         int r = 0;
156
157         wxSizer* labels = new wxBoxSizer (wxHORIZONTAL);
158         labels->Add (_h_label, 1, wxEXPAND);
159         add_label_to_sizer (labels, _colon[0], false);
160         labels->Add (_m_label, 1, wxEXPAND);
161         add_label_to_sizer (labels, _colon[1], false);
162         labels->Add (_s_label, 1, wxEXPAND);
163         add_label_to_sizer (labels, _colon[2], false);
164         labels->Add (_f_label, 1, wxEXPAND);
165         _grid->Add (labels, wxGBPosition(r, 1));
166         ++r;
167
168         add_label_to_sizer (_grid, _position_label, true, wxGBPosition(r, 0));
169         _grid->Add (_position, wxGBPosition(r, 1));
170         ++r;
171
172         _move_to_start_of_reel->Show (full);
173         _full_length_label->Show (full);
174         _full_length->Show (full);
175         _play_length_label->Show (full);
176         _play_length->Show (full);
177         _video_frame_rate_label->Show (full);
178         _video_frame_rate->Show (full);
179         _set_video_frame_rate->Show (full);
180         _tip->Show (full);
181
182         if (full) {
183                 _grid->Add (_move_to_start_of_reel, wxGBPosition(r, 1));
184                 ++r;
185
186                 add_label_to_sizer (_grid, _full_length_label, true, wxGBPosition(r, 0));
187                 _grid->Add (_full_length, wxGBPosition(r, 1));
188                 ++r;
189         }
190
191         add_label_to_sizer (_grid, _trim_start_label, true, wxGBPosition(r, 0));
192         _grid->Add (_trim_start, wxGBPosition(r, 1));
193         ++r;
194
195         _grid->Add (_trim_start_to_playhead, wxGBPosition(r, 1));
196         ++r;
197
198         add_label_to_sizer (_grid, _trim_end_label, true, wxGBPosition(r, 0));
199         _grid->Add (_trim_end, wxGBPosition(r, 1));
200         ++r;
201
202         _grid->Add (_trim_end_to_playhead, wxGBPosition(r, 1));
203         ++r;
204
205         if (full) {
206                 add_label_to_sizer (_grid, _play_length_label, true, wxGBPosition(r, 0));
207                 _grid->Add (_play_length, wxGBPosition(r, 1));
208                 ++r;
209
210                 {
211                         add_label_to_sizer (_grid, _video_frame_rate_label, true, wxGBPosition(r, 0));
212                         wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
213                         s->Add (_video_frame_rate, 1, wxEXPAND);
214                         s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
215                         _grid->Add (s, wxGBPosition(r, 1), wxGBSpan(1, 2));
216                 }
217                 ++r;
218
219                 _grid->Add (_tip, wxGBPosition(r, 1), wxGBSpan(1, 2));
220         }
221
222         /* Completely speculative fix for #891 */
223         _grid->Layout ();
224 }
225
226 void
227 TimingPanel::update_full_length ()
228 {
229         set<DCPTime> check;
230         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
231                 check.insert (i->full_length(_parent->film()));
232         }
233
234         if (check.size() == 1) {
235                 _full_length->set (_parent->selected().front()->full_length(_parent->film()), _parent->film()->video_frame_rate());
236         } else {
237                 _full_length->clear ();
238         }
239 }
240
241 void
242 TimingPanel::update_play_length ()
243 {
244         set<DCPTime> check;
245         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
246                 check.insert (i->length_after_trim(_parent->film()));
247         }
248
249         if (check.size() == 1) {
250                 _play_length->set (_parent->selected().front()->length_after_trim(_parent->film()), _parent->film()->video_frame_rate());
251         } else {
252                 _play_length->clear ();
253         }
254 }
255
256 void
257 TimingPanel::film_content_changed (int property)
258 {
259         if (_film_content_changed_suspender.check(property)) {
260                 return;
261         }
262
263         int const film_video_frame_rate = _parent->film()->video_frame_rate ();
264
265         /* Here we check to see if we have exactly one different value of various
266            properties, and fill the controls with that value if so.
267         */
268
269         if (property == ContentProperty::POSITION) {
270
271                 set<DCPTime> check;
272                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
273                         check.insert (i->position ());
274                 }
275
276                 if (check.size() == 1) {
277                         _position->set (_parent->selected().front()->position(), film_video_frame_rate);
278                 } else {
279                         _position->clear ();
280                 }
281
282         } else if (
283                 property == ContentProperty::LENGTH ||
284                 property == ContentProperty::VIDEO_FRAME_RATE ||
285                 property == VideoContentProperty::FRAME_TYPE
286                 ) {
287
288                 update_full_length ();
289
290         } else if (property == ContentProperty::TRIM_START) {
291
292                 set<ContentTime> check;
293                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
294                         check.insert (i->trim_start ());
295                 }
296
297                 if (check.size() == 1) {
298                         _trim_start->set (_parent->selected().front()->trim_start (), film_video_frame_rate);
299                 } else {
300                         _trim_start->clear ();
301                 }
302
303         } else if (property == ContentProperty::TRIM_END) {
304
305                 set<ContentTime> check;
306                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
307                         check.insert (i->trim_end ());
308                 }
309
310                 if (check.size() == 1) {
311                         _trim_end->set (_parent->selected().front()->trim_end (), film_video_frame_rate);
312                 } else {
313                         _trim_end->clear ();
314                 }
315         }
316
317         if (
318                 property == ContentProperty::LENGTH ||
319                 property == ContentProperty::TRIM_START ||
320                 property == ContentProperty::TRIM_END ||
321                 property == ContentProperty::VIDEO_FRAME_RATE ||
322                 property == VideoContentProperty::FRAME_TYPE
323                 ) {
324
325                 update_play_length ();
326         }
327
328         if (property == ContentProperty::VIDEO_FRAME_RATE) {
329                 set<double> check_vc;
330                 shared_ptr<const Content> content;
331                 int count_ac = 0;
332                 int count_sc = 0;
333                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
334                         if (i->video && i->video_frame_rate()) {
335                                 check_vc.insert (i->video_frame_rate().get());
336                                 content = i;
337                         }
338                         if (i->audio && i->video_frame_rate()) {
339                                 ++count_ac;
340                                 content = i;
341                         }
342                         if (!i->text.empty() && i->video_frame_rate()) {
343                                 ++count_sc;
344                                 content = i;
345                         }
346
347                 }
348
349                 bool const single_frame_image_content = content && dynamic_pointer_cast<const ImageContent> (content) && content->number_of_paths() == 1;
350
351                 if ((check_vc.size() == 1 || count_ac == 1 || count_sc == 1) && !single_frame_image_content) {
352                         checked_set (_video_frame_rate, locale_convert<string> (content->video_frame_rate().get(), 5));
353                         _video_frame_rate->Enable (true);
354                 } else {
355                         checked_set (_video_frame_rate, wxT (""));
356                         _video_frame_rate->Enable (false);
357                 }
358         }
359
360         bool have_still = false;
361         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
362                 shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (i);
363                 if (ic && ic->still ()) {
364                         have_still = true;
365                 }
366         }
367
368         _full_length->set_editable (have_still);
369         _play_length->set_editable (!have_still);
370         _set_video_frame_rate->Enable (false);
371         setup_sensitivity ();
372 }
373
374 void
375 TimingPanel::position_changed ()
376 {
377         DCPTime const pos = _position->get (_parent->film()->video_frame_rate ());
378         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
379                 i->set_position (_parent->film(), pos);
380         }
381 }
382
383 void
384 TimingPanel::full_length_changed ()
385 {
386         int const vfr = _parent->film()->video_frame_rate ();
387         Frame const len = _full_length->get (vfr).frames_round (vfr);
388         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
389                 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i);
390                 if (ic && ic->still ()) {
391                         ic->video->set_length (len);
392                 }
393         }
394 }
395
396 void
397 TimingPanel::trim_start_changed ()
398 {
399         shared_ptr<FilmViewer> fv = _viewer.lock ();
400         if (!fv) {
401                 return;
402         }
403
404         DCPTime const ph = fv->position ();
405
406         fv->set_coalesce_player_changes (true);
407
408         shared_ptr<Content> ref;
409         optional<FrameRateChange> ref_frc;
410         optional<DCPTime> ref_ph;
411
412         Suspender::Block bl = _film_content_changed_suspender.block ();
413         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
414                 if (i->position() <= ph && ph < i->end(_parent->film())) {
415                         /* The playhead is in i.  Use it as a reference to work out
416                            where to put the playhead post-trim; we're trying to keep the playhead
417                            at the same frame of content that we're looking at pre-trim.
418                         */
419                         ref = i;
420                         ref_frc = _parent->film()->active_frame_rate_change (i->position ());
421                         ref_ph = ph - i->position() + DCPTime (i->trim_start(), ref_frc.get());
422                 }
423
424                 ContentTime const trim = _trim_start->get (i->video_frame_rate().get_value_or(_parent->film()->video_frame_rate()));
425                 i->set_trim_start (trim);
426         }
427
428         if (ref) {
429                 fv->seek (max(DCPTime(), ref_ph.get() + ref->position() - DCPTime(ref->trim_start(), ref_frc.get())), true);
430         }
431
432         fv->set_coalesce_player_changes (false);
433 }
434
435 void
436 TimingPanel::trim_end_changed ()
437 {
438         shared_ptr<FilmViewer> fv = _viewer.lock ();
439         if (!fv) {
440                 return;
441         }
442
443         fv->set_coalesce_player_changes (true);
444
445         Suspender::Block bl = _film_content_changed_suspender.block ();
446         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
447                 ContentTime const trim = _trim_end->get (i->video_frame_rate().get_value_or(_parent->film()->video_frame_rate()));
448                 i->set_trim_end (trim);
449         }
450
451         /* XXX: maybe playhead-off-the-end-of-the-film should be handled elsewhere */
452         if (fv->position() >= _parent->film()->length()) {
453                 fv->seek (_parent->film()->length() - DCPTime::from_frames(1, _parent->film()->video_frame_rate()), true);
454         }
455
456         fv->set_coalesce_player_changes (false);
457 }
458
459 void
460 TimingPanel::play_length_changed ()
461 {
462         DCPTime const play_length = _play_length->get (_parent->film()->video_frame_rate());
463         Suspender::Block bl = _film_content_changed_suspender.block ();
464         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
465                 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
466                 i->set_trim_end (
467                         ContentTime (max(DCPTime(), i->full_length(_parent->film()) - play_length), frc) - i->trim_start()
468                         );
469         }
470 }
471
472 void
473 TimingPanel::video_frame_rate_changed ()
474 {
475         bool enable = true;
476         if (_video_frame_rate->GetValue() == wxT("")) {
477                 /* No frame rate has been entered; if the user clicks "set" now it would unset the video
478                    frame rate in the selected content.  This can't be allowed for some content types.
479                 */
480                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected()) {
481                         if (
482                                 dynamic_pointer_cast<DCPContent>(i) ||
483                                 dynamic_pointer_cast<FFmpegContent>(i)
484                                 ) {
485                                 enable = false;
486                         }
487                 }
488         }
489
490         _set_video_frame_rate->Enable (enable);
491 }
492
493 void
494 TimingPanel::set_video_frame_rate ()
495 {
496         optional<double> fr;
497         if (_video_frame_rate->GetValue() != wxT("")) {
498                 fr = locale_convert<double> (wx_to_std (_video_frame_rate->GetValue ()));
499         }
500         Suspender::Block bl = _film_content_changed_suspender.block ();
501         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
502                 if (fr) {
503                         i->set_video_frame_rate (*fr);
504                 } else {
505                         i->unset_video_frame_rate ();
506                 }
507         }
508
509         _set_video_frame_rate->Enable (false);
510 }
511
512 void
513 TimingPanel::content_selection_changed ()
514 {
515         setup_sensitivity ();
516
517         film_content_changed (ContentProperty::POSITION);
518         film_content_changed (ContentProperty::LENGTH);
519         film_content_changed (ContentProperty::TRIM_START);
520         film_content_changed (ContentProperty::TRIM_END);
521         film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
522 }
523
524 void
525 TimingPanel::film_changed (Film::Property p)
526 {
527         if (p == Film::VIDEO_FRAME_RATE) {
528                 update_full_length ();
529                 update_play_length ();
530         }
531 }
532
533 void
534 TimingPanel::trim_start_to_playhead_clicked ()
535 {
536         shared_ptr<FilmViewer> fv = _viewer.lock ();
537         if (!fv) {
538                 return;
539         }
540
541         shared_ptr<const Film> film = _parent->film ();
542         DCPTime const ph = fv->position().floor (film->video_frame_rate ());
543         optional<DCPTime> new_ph;
544
545         fv->set_coalesce_player_changes (true);
546
547         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
548                 if (i->position() < ph && ph < i->end(film)) {
549                         FrameRateChange const frc = film->active_frame_rate_change (i->position());
550                         i->set_trim_start (i->trim_start() + ContentTime (ph - i->position(), frc));
551                         new_ph = i->position ();
552                 }
553         }
554
555         if (new_ph) {
556                 fv->seek (new_ph.get(), true);
557         }
558
559         fv->set_coalesce_player_changes (false);
560 }
561
562 void
563 TimingPanel::trim_end_to_playhead_clicked ()
564 {
565         shared_ptr<FilmViewer> fv = _viewer.lock ();
566         if (!fv) {
567                 return;
568         }
569
570         shared_ptr<const Film> film = _parent->film ();
571         DCPTime const ph = fv->position().floor (film->video_frame_rate ());
572         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
573                 if (i->position() < ph && ph < i->end(film)) {
574                         FrameRateChange const frc = film->active_frame_rate_change (i->position ());
575                         i->set_trim_end (ContentTime(i->position() + i->full_length(film) - ph - DCPTime::from_frames(1, frc.dcp), frc) - i->trim_start());
576                 }
577         }
578 }
579
580 void
581 TimingPanel::setup_sensitivity ()
582 {
583         bool const e = !_parent->selected().empty ();
584
585         _position->Enable (e);
586         _move_to_start_of_reel->Enable (e);
587         _full_length->Enable (e);
588         _trim_start->Enable (e);
589         _trim_end->Enable (e);
590         _play_length->Enable (e);
591         _video_frame_rate->Enable (e);
592
593         shared_ptr<FilmViewer> fv = _viewer.lock ();
594         DCPOMATIC_ASSERT (fv);
595         DCPTime const ph = fv->position ();
596         bool any_over_ph = false;
597         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
598                 if (i->position() <= ph && ph < i->end(_parent->film())) {
599                         any_over_ph = true;
600                 }
601         }
602
603         _trim_start_to_playhead->Enable (any_over_ph);
604         _trim_end_to_playhead->Enable (any_over_ph);
605 }
606
607 void
608 TimingPanel::move_to_start_of_reel_clicked ()
609 {
610         /* Find common position of all selected content, if it exists */
611
612         optional<DCPTime> position;
613         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
614                 if (!position) {
615                         position = i->position();
616                 } else {
617                         if (position.get() != i->position()) {
618                                 position.reset ();
619                                 break;
620                         }
621                 }
622         }
623
624         MoveToDialog* d = new MoveToDialog (this, position, _parent->film());
625
626         if (d->ShowModal() == wxID_OK) {
627                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected()) {
628                         i->set_position (_parent->film(), d->position());
629                 }
630         }
631         d->Destroy ();
632 }