Vkeybd: add a mod-wheel
[ardour.git] / gtk2_ardour / editor_pt_import.cc
1 /*
2  * Copyright (C) 2015-2019 Damien Zammit <damien@zamaudio.com>
3  * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
5  *
6  * This program 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  * This program 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 along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <sys/time.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include <algorithm>
27
28 #include "pbd/pthread_utils.h"
29 #include "pbd/basename.h"
30 #include "pbd/shortpath.h"
31 #include "pbd/stateful_diff_command.h"
32
33 #include "ardour/audio_track.h"
34 #include "ardour/audiofilesource.h"
35 #include "ardour/audioregion.h"
36 #include "ardour/midi_region.h"
37 #include "ardour/midi_track.h"
38 #include "ardour/midi_model.h"
39 #include "ardour/operations.h"
40 #include "ardour/region_factory.h"
41 #include "ardour/smf_source.h"
42 #include "ardour/source_factory.h"
43 #include "ardour/utils.h"
44 #include "ardour/playlist.h"
45 #include "ardour/session.h"
46 #include "pbd/memento_command.h"
47
48 #include "ptformat/ptformat.h"
49
50 #include "ardour_ui.h"
51 #include "cursor_context.h"
52 #include "editor.h"
53 #include "sfdb_ui.h"
54 #include "editing.h"
55 #include "audio_time_axis.h"
56 #include "midi_time_axis.h"
57 #include "session_import_dialog.h"
58 #include "gui_thread.h"
59 #include "interthread_progress_window.h"
60 #include "mouse_cursors.h"
61 #include "editor_cursors.h"
62 #include "pt_import_selector.h"
63
64 #include "pbd/i18n.h"
65
66 using namespace std;
67 using namespace ARDOUR;
68 using namespace PBD;
69 using namespace Gtk;
70 using namespace Gtkmm2ext;
71 using namespace Editing;
72 using std::string;
73
74 /* Editor dialogs supporting the incorporation of PT sessions into ardour */
75
76 void
77 Editor::external_pt_dialog ()
78 {
79         std::string ptpath;
80
81         if (_session == 0) {
82                 MessageDialog msg (_("You can't import a PT session until you have a session loaded."));
83                 msg.run ();
84                 return;
85         }
86
87         PTImportSelector dialog (import_ptf);
88         dialog.set_session (_session);
89
90         while (true) {
91                 int result = dialog.run ();
92
93                 if (result == Gtk::RESPONSE_ACCEPT) {
94
95                         import_pt_status.all_done = false;
96
97                         ImportProgressWindow ipw (&import_pt_status, _("PT Import"), _("Cancel Import"));
98                         pthread_create_and_store ("import_pt", &import_pt_status.thread, _import_pt_thread, this);
99                         pthread_detach (import_pt_status.thread);
100
101                         ipw.show();
102
103                         while (!import_pt_status.all_done) {
104                                 gtk_main_iteration ();
105                         }
106
107                         // wait for thread to terminate
108                         while (!import_pt_status.done) {
109                                 gtk_main_iteration ();
110                         }
111
112                         if (import_pt_status.cancel) {
113                                 MessageDialog msg (_("PT import may have missing files, check session log for details"));
114                                 msg.run ();
115                         } else {
116                                 MessageDialog msg (_("PT import complete!"));
117                                 msg.run ();
118                         }
119                         break;
120                 } else if (result == Gtk::RESPONSE_CANCEL) {
121                         break;
122                 }
123         }
124 }
125
126 void *
127 Editor::_import_pt_thread (void *arg)
128 {
129         SessionEvent::create_per_thread_pool ("import pt events", 64);
130
131         Editor *ed = (Editor *) arg;
132         return ed->import_pt_thread ();
133 }
134
135 void *
136 Editor::import_pt_thread ()
137 {
138         _session->import_pt (import_ptf, import_pt_status);
139         return 0;
140 }