Fix ExportFormatSpecification copy-c'tor
[ardour.git] / gtk2_ardour / editor_pt_import.cc
1 /*
2     Copyright (C) 2000-2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/time.h>
23 #include <errno.h>
24 #include <unistd.h>
25 #include <algorithm>
26
27 #include "pbd/pthread_utils.h"
28 #include "pbd/basename.h"
29 #include "pbd/shortpath.h"
30 #include "pbd/stateful_diff_command.h"
31
32 #include "ardour/audio_track.h"
33 #include "ardour/audiofilesource.h"
34 #include "ardour/audioregion.h"
35 #include "ardour/midi_region.h"
36 #include "ardour/midi_track.h"
37 #include "ardour/midi_model.h"
38 #include "ardour/operations.h"
39 #include "ardour/region_factory.h"
40 #include "ardour/smf_source.h"
41 #include "ardour/source_factory.h"
42 #include "ardour/utils.h"
43 #include "ardour/playlist.h"
44 #include "ardour/session.h"
45 #include "pbd/memento_command.h"
46
47 #include "ptformat/ptfformat.h"
48
49 #include "ardour_ui.h"
50 #include "cursor_context.h"
51 #include "editor.h"
52 #include "sfdb_ui.h"
53 #include "editing.h"
54 #include "audio_time_axis.h"
55 #include "midi_time_axis.h"
56 #include "session_import_dialog.h"
57 #include "gui_thread.h"
58 #include "interthread_progress_window.h"
59 #include "mouse_cursors.h"
60 #include "editor_cursors.h"
61 #include "pt_import_selector.h"
62
63 #include "pbd/i18n.h"
64
65 using namespace std;
66 using namespace ARDOUR;
67 using namespace PBD;
68 using namespace Gtk;
69 using namespace Gtkmm2ext;
70 using namespace Editing;
71 using std::string;
72
73 /* Editor dialogs supporting the incorporation of PT sessions into ardour */
74
75 void
76 Editor::external_pt_dialog ()
77 {
78         std::string ptpath;
79
80         if (_session == 0) {
81                 MessageDialog msg (_("You can't import a PT session until you have a session loaded."));
82                 msg.run ();
83                 return;
84         }
85
86         PTImportSelector dialog (import_ptf);
87         dialog.set_session (_session);
88
89         while (true) {
90                 int result = dialog.run ();
91
92                 if (result == Gtk::RESPONSE_ACCEPT) {
93
94                         import_pt_status.all_done = false;
95
96                         ImportProgressWindow ipw (&import_pt_status, _("PT Import"), _("Cancel Import"));
97                         pthread_create_and_store ("import_pt", &import_pt_status.thread, _import_pt_thread, this);
98                         pthread_detach (import_pt_status.thread);
99
100                         ipw.show();
101
102                         while (!import_pt_status.all_done) {
103                                 gtk_main_iteration ();
104                         }
105
106                         // wait for thread to terminate
107                         while (!import_pt_status.done) {
108                                 gtk_main_iteration ();
109                         }
110
111                         if (import_pt_status.cancel) {
112                                 MessageDialog msg (_("PT import may have missing files, check session log for details"));
113                                 msg.run ();
114                         } else {
115                                 MessageDialog msg (_("PT import complete!"));
116                                 msg.run ();
117                         }
118                         break;
119                 } else if (result == Gtk::RESPONSE_CANCEL) {
120                         break;
121                 }
122         }
123 }
124
125 void *
126 Editor::_import_pt_thread (void *arg)
127 {
128         SessionEvent::create_per_thread_pool ("import pt events", 64);
129
130         Editor *ed = (Editor *) arg;
131         return ed->import_pt_thread ();
132 }
133
134 void *
135 Editor::import_pt_thread ()
136 {
137         _session->import_pt (import_ptf, import_pt_status);
138         return 0;
139 }