2 Copyright (C) 2018 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <pbd/error.h>
23 #include <sys/types.h>
25 #include "pbd/gstdio_compat.h"
27 #include "pbd/file_utils.h"
29 #include "ptformat/ptfformat.h"
31 #include "ardour/session_handle.h"
32 #include "pt_import_selector.h"
35 using namespace ARDOUR;
38 PTImportSelector::PTImportSelector (PTFFormat& ptf) :
39 ArdourDialog (_("Import PT Session")),
40 ptimport_ptf_chooser (FILE_CHOOSER_ACTION_OPEN),
41 ptimport_import_button (_("Import")),
42 ptimport_cancel_button (_("Cancel"))
47 Gtk::Dialog::response(RESPONSE_CANCEL);
50 set_size_request (800, 450);
51 ptimport_import_button.set_size_request (90, 35);
52 ptimport_cancel_button.set_size_request (90, 35);
54 Gtk::FileFilter match_pt_filter;
56 ptimport_info_text.set_editable (false);
57 ptimport_info_text.set_wrap_mode (Gtk::WRAP_NONE);
58 ptimport_info_text.get_buffer ()->set_text ("Select a PT session\n");
59 ptimport_info_text.set_sensitive (false);
61 match_pt_filter.add_pattern ("*.pt5");
62 match_pt_filter.add_pattern ("*.pt6");
63 match_pt_filter.add_pattern ("*.pt7");
64 match_pt_filter.add_pattern ("*.pts");
65 match_pt_filter.add_pattern ("*.ptf");
66 match_pt_filter.add_pattern ("*.ptx");
67 match_pt_filter.set_name (_("All PT sessions"));
69 ptimport_ptf_chooser.add_filter (match_pt_filter);
70 ptimport_ptf_chooser.set_select_multiple (false);
71 //XXX ptimport_ptf_chooser.set_current_folder (dstdir);
74 HBox* buttons = manage (new HBox);
75 buttons->set_spacing (2);
76 buttons->set_border_width (10);
77 buttons->pack_start (ptimport_import_button, false, false);
78 buttons->pack_start (ptimport_cancel_button, false, false);
80 HBox* infobox = manage (new HBox);
81 infobox->set_spacing (1);
82 infobox->set_border_width (50);
83 infobox->pack_start (ptimport_info_text, false, false);
85 HBox* toplevel = manage (new HBox);
86 toplevel->set_spacing (2);
87 toplevel->set_border_width (10);
88 toplevel->pack_start (ptimport_ptf_chooser, true, true);
89 toplevel->pack_start (*infobox, false, false);
91 get_vbox()->pack_start (*toplevel, true, true);
92 get_vbox()->pack_start (*buttons, false, false);
94 ptimport_ptf_chooser.signal_selection_changed ().connect (sigc::mem_fun (*this, &PTImportSelector::update_ptf));
96 ptimport_import_button.set_sensitive(false);
97 ptimport_cancel_button.set_sensitive(true);
99 ptimport_cancel_button.signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &Gtk::Dialog::response), RESPONSE_CANCEL));
100 ptimport_import_button.signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &Gtk::Dialog::response), RESPONSE_ACCEPT));
106 PTImportSelector::update_ptf()
108 if (ptimport_ptf_chooser.get_filename ().size () > 0) {
109 std::string path = ptimport_ptf_chooser.get_filename ();
110 bool ok = Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
111 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
113 if (_ptf->load (path, _session_rate) == -1) {
114 ptimport_info_text.get_buffer ()->set_text ("Cannot detect PT session\n");
115 ptimport_import_button.set_sensitive(false);
117 std::string ptinfo = string_compose (_("PT Session [ VALID ]\n\nSession Info:\n\n\nPT v%1 Session @ %2Hz\n\n%3 audio files\n%4 audio regions\n%5 active audio regions\n%6 midi regions\n%7 active midi regions\n\n"),
120 _ptf->audiofiles.size (),
121 _ptf->regions.size (),
122 _ptf->tracks.size (),
123 _ptf->midiregions.size (),
124 _ptf->miditracks.size ()
126 if (_session_rate != _ptf->sessionrate) {
127 ptinfo = string_compose (_("%1WARNING:\n\nSample rate mismatch,\nwill be resampling\n"), ptinfo);
129 ptimport_info_text.get_buffer ()->set_text (ptinfo);
130 ptimport_import_button.set_sensitive(true);
137 PTImportSelector::set_session (Session* s)
139 ArdourDialog::set_session (s);
140 _session_rate = s->sample_rate ();