2008-09-26 04:29:30 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2008 Paul Davis
|
|
|
|
Author: Sakari Bergen
|
|
|
|
|
|
|
|
This program 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 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "session_import_dialog.h"
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/failed_constructor.h"
|
2008-09-26 04:29:30 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/audio_region_importer.h"
|
|
|
|
#include "ardour/audio_playlist_importer.h"
|
|
|
|
#include "ardour/audio_track_importer.h"
|
|
|
|
#include "ardour/location_importer.h"
|
|
|
|
#include "ardour/tempo_map_importer.h"
|
2008-09-26 04:29:30 -04:00
|
|
|
|
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
|
2009-12-21 13:23:07 -05:00
|
|
|
#include "gui_thread.h"
|
2008-09-26 04:29:30 -04:00
|
|
|
#include "prompter.h"
|
|
|
|
#include "i18n.h"
|
|
|
|
|
2009-05-12 13:03:42 -04:00
|
|
|
using namespace std;
|
2008-09-26 04:29:30 -04:00
|
|
|
using namespace ARDOUR;
|
2011-01-03 10:43:06 -05:00
|
|
|
using namespace PBD;
|
2011-01-07 12:36:01 -05:00
|
|
|
using namespace Gtk;
|
2008-09-26 04:29:30 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
SessionImportDialog::SessionImportDialog (ARDOUR::Session* target) :
|
2010-05-02 19:54:25 -04:00
|
|
|
ArdourDialog (_("Import From Session")),
|
2008-09-26 04:29:30 -04:00
|
|
|
file_browse_button (_("Browse"))
|
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
set_session (target);
|
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// File entry
|
|
|
|
file_entry.set_name ("ImportFileNameEntry");
|
|
|
|
file_entry.set_text ("/");
|
|
|
|
Gtkmm2ext::set_size_request_to_display_given_text (file_entry, X_("Kg/quite/a/reasonable/size/for/files/i/think"), 5, 8);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
file_browse_button.set_name ("EditorGTKButton");
|
2009-12-11 18:29:48 -05:00
|
|
|
file_browse_button.signal_clicked().connect (sigc::mem_fun(*this, &SessionImportDialog::browse));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
file_hbox.set_spacing (5);
|
|
|
|
file_hbox.set_border_width (5);
|
|
|
|
file_hbox.pack_start (file_entry, true, true);
|
|
|
|
file_hbox.pack_start (file_browse_button, false, false);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
file_frame.add (file_hbox);
|
|
|
|
file_frame.set_border_width (5);
|
|
|
|
file_frame.set_name ("ImportFrom");
|
|
|
|
file_frame.set_label (_("Import from Session"));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
get_vbox()->pack_start (file_frame, false, false);
|
|
|
|
|
|
|
|
// Session browser
|
2011-01-07 12:36:01 -05:00
|
|
|
session_tree = TreeStore::create (sb_cols);
|
2008-09-26 04:29:30 -04:00
|
|
|
session_browser.set_model (session_tree);
|
|
|
|
|
|
|
|
session_browser.set_name ("SessionBrowser");
|
|
|
|
session_browser.append_column (_("Elements"), sb_cols.name);
|
|
|
|
session_browser.append_column_editable (_("Import"), sb_cols.queued);
|
2009-05-02 16:26:11 -04:00
|
|
|
session_browser.set_tooltip_column (3);
|
2008-09-26 04:29:30 -04:00
|
|
|
session_browser.get_column(0)->set_min_width (180);
|
|
|
|
session_browser.get_column(1)->set_min_width (40);
|
2011-01-07 12:36:01 -05:00
|
|
|
session_browser.get_column(1)->set_sizing (TREE_VIEW_COLUMN_AUTOSIZE);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-01-07 12:36:01 -05:00
|
|
|
session_scroll.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
|
2008-09-26 04:29:30 -04:00
|
|
|
session_scroll.add (session_browser);
|
|
|
|
session_scroll.set_size_request (220, 400);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// Connect signals
|
2011-01-07 12:36:01 -05:00
|
|
|
CellRendererToggle *toggle = dynamic_cast<CellRendererToggle *> (session_browser.get_column_cell_renderer (1));
|
2009-12-11 18:29:48 -05:00
|
|
|
toggle->signal_toggled().connect(sigc::mem_fun (*this, &SessionImportDialog::update));
|
|
|
|
session_browser.signal_row_activated().connect(sigc::mem_fun (*this, &SessionImportDialog::show_info));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
get_vbox()->pack_start (session_scroll, false, false);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// Buttons
|
2011-01-07 12:36:01 -05:00
|
|
|
cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
|
2009-12-11 18:29:48 -05:00
|
|
|
cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &SessionImportDialog::end_dialog));
|
2011-01-07 12:36:01 -05:00
|
|
|
ok_button = add_button (_("Import"), RESPONSE_ACCEPT);
|
2009-12-11 18:29:48 -05:00
|
|
|
ok_button->signal_clicked().connect (sigc::mem_fun (*this, &SessionImportDialog::do_merge));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-12-21 13:23:07 -05:00
|
|
|
// prompt signals XXX: problem - handlers to be in the same thread since they return values
|
|
|
|
ElementImporter::Rename.connect_same_thread (connections, boost::bind (&SessionImportDialog::open_rename_dialog, this, _1, _2));
|
|
|
|
ElementImporter::Prompt.connect_same_thread (connections, boost::bind (&SessionImportDialog::open_prompt_dialog, this, _1));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// Finalize
|
|
|
|
show_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionImportDialog::load_session (const string& filename)
|
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
if (_session) {
|
2011-01-03 10:17:18 -05:00
|
|
|
if (tree.read (filename)) {
|
2011-01-03 10:43:06 -05:00
|
|
|
error << string_compose (_("Cannot load XML for session from %1"), filename) << endmsg;
|
2011-01-03 10:17:18 -05:00
|
|
|
return;
|
|
|
|
}
|
2009-12-17 13:24:23 -05:00
|
|
|
boost::shared_ptr<AudioRegionImportHandler> region_handler (new AudioRegionImportHandler (tree, *_session));
|
|
|
|
boost::shared_ptr<AudioPlaylistImportHandler> pl_handler (new AudioPlaylistImportHandler (tree, *_session, *region_handler));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
handlers.push_back (boost::static_pointer_cast<ElementImportHandler> (region_handler));
|
|
|
|
handlers.push_back (boost::static_pointer_cast<ElementImportHandler> (pl_handler));
|
|
|
|
handlers.push_back (HandlerPtr(new UnusedAudioPlaylistImportHandler (tree, *_session, *region_handler)));
|
|
|
|
handlers.push_back (HandlerPtr(new AudioTrackImportHandler (tree, *_session, *pl_handler)));
|
|
|
|
handlers.push_back (HandlerPtr(new LocationImportHandler (tree, *_session)));
|
|
|
|
handlers.push_back (HandlerPtr(new TempoMapImportHandler (tree, *_session)));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
fill_list();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
if (ElementImportHandler::dirty()) {
|
|
|
|
// Warn user
|
|
|
|
string txt = _("Some elements had errors in them. Please see the log for details");
|
2011-01-07 12:36:01 -05:00
|
|
|
MessageDialog msg (txt, false, MESSAGE_WARNING, BUTTONS_OK, true);
|
2009-12-17 13:24:23 -05:00
|
|
|
msg.run();
|
|
|
|
}
|
2008-09-26 04:29:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionImportDialog::fill_list ()
|
|
|
|
{
|
|
|
|
session_tree->clear();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// Loop through element types
|
|
|
|
for (HandlerList::iterator handler = handlers.begin(); handler != handlers.end(); ++handler) {
|
2011-01-07 12:36:01 -05:00
|
|
|
TreeModel::iterator iter = session_tree->append();
|
|
|
|
TreeModel::Row row = *iter;
|
2008-09-26 04:29:30 -04:00
|
|
|
row[sb_cols.name] = (*handler)->get_info();
|
|
|
|
row[sb_cols.queued] = false;
|
|
|
|
row[sb_cols.element] = ElementPtr(); // "Null" pointer
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// Loop through elements
|
|
|
|
ElementList &elements = (*handler)->elements;
|
|
|
|
for (ElementList::iterator element = elements.begin(); element != elements.end(); ++element) {
|
|
|
|
iter = session_tree->append(row.children());
|
2011-01-07 12:36:01 -05:00
|
|
|
TreeModel::Row child = *iter;
|
2008-09-26 04:29:30 -04:00
|
|
|
child[sb_cols.name] = (*element)->get_name();
|
|
|
|
child[sb_cols.queued] = false;
|
|
|
|
child[sb_cols.element] = *element;
|
2009-05-02 16:26:11 -04:00
|
|
|
child[sb_cols.info] = (*element)->get_info();
|
2008-09-26 04:29:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionImportDialog::browse ()
|
|
|
|
{
|
2011-01-07 12:36:01 -05:00
|
|
|
FileChooserDialog dialog(_("Import from session"), browse_action());
|
2008-09-26 04:29:30 -04:00
|
|
|
dialog.set_transient_for(*this);
|
|
|
|
dialog.set_filename (file_entry.get_text());
|
|
|
|
|
2011-01-07 12:36:01 -05:00
|
|
|
FileFilter session_filter;
|
|
|
|
session_filter.add_pattern ("*.ardour");
|
|
|
|
session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
|
|
|
|
dialog.add_filter (session_filter);
|
|
|
|
dialog.set_filter (session_filter);
|
|
|
|
|
|
|
|
dialog.add_button(Stock::CANCEL, RESPONSE_CANCEL);
|
|
|
|
dialog.add_button(Stock::OK, RESPONSE_OK);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
int result = dialog.run();
|
|
|
|
|
2011-01-07 12:36:01 -05:00
|
|
|
if (result == RESPONSE_OK) {
|
2008-09-26 04:29:30 -04:00
|
|
|
string filename = dialog.get_filename();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
if (filename.length()) {
|
|
|
|
file_entry.set_text (filename);
|
|
|
|
load_session (filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionImportDialog::do_merge ()
|
|
|
|
{
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// element types
|
2011-01-07 12:36:01 -05:00
|
|
|
TreeModel::Children types = session_browser.get_model()->children();
|
|
|
|
TreeModel::Children::iterator ti;
|
2008-09-26 04:29:30 -04:00
|
|
|
for (ti = types.begin(); ti != types.end(); ++ti) {
|
|
|
|
// elements
|
2011-01-07 12:36:01 -05:00
|
|
|
TreeModel::Children elements = ti->children();
|
|
|
|
TreeModel::Children::iterator ei;
|
2008-09-26 04:29:30 -04:00
|
|
|
for (ei = elements.begin(); ei != elements.end(); ++ei) {
|
|
|
|
if ((*ei)[sb_cols.queued]) {
|
|
|
|
ElementPtr element = (*ei)[sb_cols.element];
|
|
|
|
element->move();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
end_dialog();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
if (ElementImportHandler::errors()) {
|
|
|
|
// Warn user
|
|
|
|
string txt = _("Some elements had errors in them. Please see the log for details");
|
2011-01-07 12:36:01 -05:00
|
|
|
MessageDialog msg (txt, false, MESSAGE_WARNING, BUTTONS_OK, true);
|
2008-09-26 04:29:30 -04:00
|
|
|
msg.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionImportDialog::update (string path)
|
|
|
|
{
|
2011-01-07 12:36:01 -05:00
|
|
|
TreeModel::iterator cell = session_browser.get_model()->get_iter (path);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// Select all elements if element type is selected
|
|
|
|
if (path.size() == 1) {
|
|
|
|
{
|
|
|
|
// Prompt user for verification
|
|
|
|
string txt = _("This will select all elements of this type!");
|
2011-01-07 12:36:01 -05:00
|
|
|
MessageDialog msg (txt, false, MESSAGE_QUESTION, BUTTONS_OK_CANCEL, true);
|
|
|
|
if (msg.run() == RESPONSE_CANCEL) {
|
2008-09-26 04:29:30 -04:00
|
|
|
(*cell)[sb_cols.queued] = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-01-07 12:36:01 -05:00
|
|
|
TreeModel::Children elements = cell->children();
|
|
|
|
TreeModel::Children::iterator ei;
|
2008-09-26 04:29:30 -04:00
|
|
|
for (ei = elements.begin(); ei != elements.end(); ++ei) {
|
|
|
|
ElementPtr element = (*ei)[sb_cols.element];
|
|
|
|
if (element->prepare_move()) {
|
|
|
|
(*ei)[sb_cols.queued] = true;
|
|
|
|
} else {
|
|
|
|
(*cell)[sb_cols.queued] = false; // Not all are selected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
ElementPtr element = (*cell)[sb_cols.element];
|
|
|
|
if ((*cell)[sb_cols.queued]) {
|
|
|
|
if (!element->prepare_move()) {
|
|
|
|
(*cell)[sb_cols.queued] = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
element->cancel_move();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-07 12:36:01 -05:00
|
|
|
SessionImportDialog::show_info(const TreeModel::Path& path, TreeViewColumn*)
|
2008-09-26 04:29:30 -04:00
|
|
|
{
|
|
|
|
if (path.size() == 1) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-01-07 12:36:01 -05:00
|
|
|
TreeModel::iterator cell = session_browser.get_model()->get_iter (path);
|
2009-05-02 16:26:11 -04:00
|
|
|
string info = (*cell)[sb_cols.info];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-01-07 12:36:01 -05:00
|
|
|
MessageDialog msg (info, false, MESSAGE_INFO, BUTTONS_OK, true);
|
2008-09-26 04:29:30 -04:00
|
|
|
msg.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionImportDialog::end_dialog ()
|
|
|
|
{
|
|
|
|
hide_all();
|
|
|
|
|
|
|
|
set_modal (false);
|
|
|
|
ok_button->set_sensitive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<bool, string>
|
|
|
|
SessionImportDialog::open_rename_dialog (string text, string name)
|
|
|
|
{
|
|
|
|
ArdourPrompter prompter(true);
|
|
|
|
string new_name;
|
|
|
|
|
|
|
|
prompter.set_name ("Prompter");
|
2011-01-07 12:36:01 -05:00
|
|
|
prompter.add_button (Stock::SAVE, RESPONSE_ACCEPT);
|
2008-09-26 04:29:30 -04:00
|
|
|
prompter.set_prompt (text);
|
|
|
|
prompter.set_initial_text (name);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-01-07 12:36:01 -05:00
|
|
|
if (prompter.run() == RESPONSE_ACCEPT) {
|
2008-09-26 04:29:30 -04:00
|
|
|
prompter.get_result (new_name);
|
|
|
|
if (new_name.length()) {
|
|
|
|
name = new_name;
|
|
|
|
}
|
|
|
|
return std::make_pair (true, new_name);
|
|
|
|
}
|
|
|
|
return std::make_pair (false, new_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SessionImportDialog::open_prompt_dialog (string text)
|
|
|
|
{
|
2011-01-07 12:36:01 -05:00
|
|
|
MessageDialog msg (text, false, MESSAGE_QUESTION, BUTTONS_OK_CANCEL, true);
|
|
|
|
if (msg.run() == RESPONSE_OK) {
|
2008-09-26 04:29:30 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|