2013-09-23 14:41:52 -04:00
|
|
|
/*
|
2014-04-10 04:54:47 -05:00
|
|
|
Copyright (C) 2014 Valeriy Kamyshniy
|
2013-09-23 14:41:52 -04:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef WAF_BUILD
|
|
|
|
|
#include "gtk2ardour-config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2014-04-04 18:20:33 -05:00
|
|
|
#include "waves_button.h"
|
|
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
#include <gtkmm/filechooser.h>
|
|
|
|
|
|
|
|
|
|
#include "pbd/failed_constructor.h"
|
|
|
|
|
#include "pbd/file_utils.h"
|
|
|
|
|
#include "pbd/replace_all.h"
|
|
|
|
|
#include "pbd/whitespace.h"
|
|
|
|
|
#include "pbd/stacktrace.h"
|
|
|
|
|
#include "pbd/openuri.h"
|
|
|
|
|
|
|
|
|
|
#include "ardour/audioengine.h"
|
|
|
|
|
#include "ardour/filesystem_paths.h"
|
|
|
|
|
#include "ardour/recent_sessions.h"
|
|
|
|
|
#include "ardour/session.h"
|
|
|
|
|
#include "ardour/session_state_utils.h"
|
|
|
|
|
#include "ardour/template_utils.h"
|
|
|
|
|
#include "ardour/filename_extensions.h"
|
|
|
|
|
|
|
|
|
|
#include "ardour_ui.h"
|
|
|
|
|
#include "session_dialog.h"
|
|
|
|
|
#include "opts.h"
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace Gtk;
|
|
|
|
|
using namespace Gdk;
|
|
|
|
|
using namespace Glib;
|
|
|
|
|
using namespace PBD;
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
2014-04-10 04:54:47 -05:00
|
|
|
#define dbg_msg(a) MessageDialog (a, PROGRAM_NAME).run();
|
2014-04-04 18:20:33 -05:00
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
static string poor_mans_glob (string path)
|
|
|
|
|
{
|
|
|
|
|
string copy = path;
|
|
|
|
|
replace_all (copy, "~", Glib::get_home_dir());
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-23 23:13:07 -04:00
|
|
|
SessionDialog::SessionDialog (bool require_new, const std::string& session_name, const std::string& session_path, const std::string& template_name, bool cancel_not_quit)
|
2014-04-04 18:20:33 -05:00
|
|
|
: WavesDialog (_("session_dialog.xml"), true, false)
|
|
|
|
|
, quit_button (get_waves_button ("quit_button"))
|
|
|
|
|
, new_session_button (get_waves_button ("new_session_button"))
|
|
|
|
|
, open_selected_button (get_waves_button ("open_selected_button"))
|
|
|
|
|
, open_saved_session_button (get_waves_button ("open_saved_session_button"))
|
2014-04-10 04:54:47 -05:00
|
|
|
, session_details_label(get_label("session_details_label"))
|
2013-09-23 14:41:52 -04:00
|
|
|
, new_only (require_new)
|
|
|
|
|
, _provided_session_name (session_name)
|
2014-04-11 04:10:58 -05:00
|
|
|
, _provided_session_path (session_path)
|
2013-09-23 14:41:52 -04:00
|
|
|
, _existing_session_chooser_used (false)
|
2014-04-04 18:20:33 -05:00
|
|
|
{
|
|
|
|
|
recent_session_button[0] = &get_waves_button ("recent_session_button_0");
|
|
|
|
|
recent_session_button[1] = &get_waves_button ("recent_session_button_1");
|
|
|
|
|
recent_session_button[2] = &get_waves_button ("recent_session_button_2");
|
|
|
|
|
recent_session_button[3] = &get_waves_button ("recent_session_button_3");
|
|
|
|
|
recent_session_button[4] = &get_waves_button ("recent_session_button_4");
|
|
|
|
|
recent_session_button[5] = &get_waves_button ("recent_session_button_5");
|
|
|
|
|
recent_session_button[6] = &get_waves_button ("recent_session_button_6");
|
|
|
|
|
recent_session_button[7] = &get_waves_button ("recent_session_button_7");
|
|
|
|
|
recent_session_button[8] = &get_waves_button ("recent_session_button_8");
|
|
|
|
|
recent_session_button[9] = &get_waves_button ("recent_session_button_9");
|
|
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
set_keep_above (true);
|
|
|
|
|
set_position (WIN_POS_CENTER);
|
|
|
|
|
|
2014-04-04 18:20:33 -05:00
|
|
|
open_selected_button.set_sensitive (false);
|
2013-10-08 12:18:27 -04:00
|
|
|
|
|
|
|
|
if (!session_name.empty() && !require_new) {
|
|
|
|
|
response (RESPONSE_OK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-04-04 18:20:33 -05:00
|
|
|
|
|
|
|
|
open_selected_button.signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_open_selected));
|
|
|
|
|
open_saved_session_button.signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_open_saved_session));
|
|
|
|
|
quit_button.signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_quit));
|
|
|
|
|
new_session_button.signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_new_session));
|
|
|
|
|
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
|
|
|
|
|
recent_session_button[i]->signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_recent_session ));
|
|
|
|
|
}
|
2014-04-12 20:01:34 -05:00
|
|
|
redisplay_recent_sessions();
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SessionDialog::~SessionDialog()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-08 12:18:27 -04:00
|
|
|
void
|
|
|
|
|
SessionDialog::clear_given ()
|
|
|
|
|
{
|
|
|
|
|
_provided_session_path = "";
|
|
|
|
|
_provided_session_name = "";
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
std::string
|
|
|
|
|
SessionDialog::session_name (bool& should_be_new)
|
|
|
|
|
{
|
2014-04-10 14:26:38 -05:00
|
|
|
should_be_new = false;
|
|
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
if (!_provided_session_name.empty() && !new_only) {
|
|
|
|
|
return _provided_session_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try recent session selection */
|
|
|
|
|
|
2014-04-04 18:20:33 -05:00
|
|
|
if (!selected_session_full_name.empty()) {
|
2014-04-11 04:10:58 -05:00
|
|
|
should_be_new = (_selection_type == NewSession);
|
|
|
|
|
return should_be_new ? Glib::path_get_basename(selected_session_full_name) :
|
|
|
|
|
selected_session_full_name;
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
2014-04-10 14:26:38 -05:00
|
|
|
|
2014-04-04 18:20:33 -05:00
|
|
|
return "";
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
SessionDialog::session_folder ()
|
|
|
|
|
{
|
2014-04-10 14:26:38 -05:00
|
|
|
if (!selected_session_full_name.empty() ) {
|
2014-04-04 18:20:33 -05:00
|
|
|
if (Glib::file_test (selected_session_full_name, Glib::FILE_TEST_IS_REGULAR)) {
|
|
|
|
|
return Glib::path_get_dirname (selected_session_full_name);
|
2013-10-07 20:46:10 -04:00
|
|
|
}
|
2014-04-04 18:20:33 -05:00
|
|
|
return selected_session_full_name;
|
2014-04-11 04:10:58 -05:00
|
|
|
}
|
2014-04-10 14:26:38 -05:00
|
|
|
return "";
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-04-04 18:20:33 -05:00
|
|
|
SessionDialog::session_selected ()
|
2013-09-23 14:41:52 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-04-04 18:20:33 -05:00
|
|
|
SessionDialog::on_new_session (WavesButton*)
|
2013-09-23 14:41:52 -04:00
|
|
|
{
|
2014-04-10 14:26:38 -05:00
|
|
|
Gtk::FileChooserDialog dialog(*this, _("Create New Session"), Gtk::FILE_CHOOSER_ACTION_SAVE);
|
|
|
|
|
|
|
|
|
|
dialog.add_button("CANCEL", Gtk::RESPONSE_CANCEL);
|
|
|
|
|
dialog.add_button("OK", Gtk::RESPONSE_OK);
|
|
|
|
|
|
|
|
|
|
if (dialog.run() == Gtk::RESPONSE_OK) {
|
2014-04-11 04:10:58 -05:00
|
|
|
selected_session_full_name = dialog.get_filename();
|
|
|
|
|
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
|
|
|
|
|
recent_session_button[i]->set_active(false);
|
|
|
|
|
}
|
2014-04-10 14:26:38 -05:00
|
|
|
hide();
|
2014-04-11 04:10:58 -05:00
|
|
|
_selection_type = NewSession;
|
2014-04-10 14:26:38 -05:00
|
|
|
response (Gtk::RESPONSE_ACCEPT);
|
|
|
|
|
}
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
SessionDialog::redisplay_recent_sessions ()
|
|
|
|
|
{
|
2014-04-04 18:20:33 -05:00
|
|
|
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
|
|
|
|
|
recent_session_button[i]->set_sensitive(false);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
std::vector<std::string> session_directories;
|
|
|
|
|
RecentSessionsSorter cmp;
|
|
|
|
|
|
|
|
|
|
ARDOUR::RecentSessions rs;
|
|
|
|
|
ARDOUR::read_recent_sessions (rs);
|
|
|
|
|
|
|
|
|
|
if (rs.empty()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-04-04 18:20:33 -05:00
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
// sort them alphabetically
|
2014-04-04 18:20:33 -05:00
|
|
|
// sort (rs.begin(), rs.end(), cmp);
|
2013-09-23 14:41:52 -04:00
|
|
|
|
|
|
|
|
for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
|
|
|
|
|
session_directories.push_back ((*i).second);
|
|
|
|
|
}
|
2014-04-04 18:20:33 -05:00
|
|
|
|
2013-09-23 14:41:52 -04:00
|
|
|
int session_snapshot_count = 0;
|
|
|
|
|
|
2014-04-04 18:20:33 -05:00
|
|
|
for (vector<std::string>::const_iterator i = session_directories.begin();
|
|
|
|
|
(session_snapshot_count < MAX_RECENT_SESSION_COUNTS) && (i != session_directories.end());
|
|
|
|
|
++i)
|
2013-09-23 14:41:52 -04:00
|
|
|
{
|
|
|
|
|
std::vector<std::string> state_file_paths;
|
|
|
|
|
|
|
|
|
|
// now get available states for this session
|
|
|
|
|
|
|
|
|
|
get_state_files_in_directory (*i, state_file_paths);
|
|
|
|
|
|
|
|
|
|
vector<string*>* states;
|
|
|
|
|
vector<const gchar*> item;
|
2013-09-23 21:36:13 -04:00
|
|
|
string dirname = *i;
|
2013-09-23 14:41:52 -04:00
|
|
|
|
|
|
|
|
/* remove any trailing / */
|
2013-09-23 21:36:13 -04:00
|
|
|
if (dirname[dirname.length()-1] == '/') {
|
|
|
|
|
dirname = dirname.substr (0, dirname.length()-1);
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check whether session still exists */
|
2013-09-23 21:36:13 -04:00
|
|
|
if (!Glib::file_test(dirname.c_str(), Glib::FILE_TEST_EXISTS)) {
|
2013-09-23 14:41:52 -04:00
|
|
|
/* session doesn't exist */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now get available states for this session */
|
|
|
|
|
|
2013-09-23 21:36:13 -04:00
|
|
|
if ((states = Session::possible_states (dirname)) == 0) {
|
2013-09-23 14:41:52 -04:00
|
|
|
/* no state file? */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
|
|
|
|
|
|
2013-09-23 21:36:13 -04:00
|
|
|
if (state_file_names.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-10 11:16:26 -05:00
|
|
|
recent_session_full_name[session_snapshot_count] = Glib::build_filename (dirname, state_file_names.front() + statefile_suffix);
|
2014-04-04 18:20:33 -05:00
|
|
|
recent_session_button[session_snapshot_count]->set_text(Glib::path_get_basename (dirname));
|
|
|
|
|
recent_session_button[session_snapshot_count]->set_sensitive(true);
|
2014-04-12 20:01:34 -05:00
|
|
|
ARDOUR_UI::instance()->set_tip(*recent_session_button[session_snapshot_count], recent_session_full_name[session_snapshot_count]);
|
2013-09-23 14:41:52 -04:00
|
|
|
++session_snapshot_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return session_snapshot_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2014-04-04 18:20:33 -05:00
|
|
|
SessionDialog::on_delete_event (GdkEventAny* ev)
|
2013-09-23 14:41:52 -04:00
|
|
|
{
|
2014-04-04 18:20:33 -05:00
|
|
|
response (RESPONSE_CANCEL);
|
|
|
|
|
return WavesDialog::on_delete_event (ev);
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
2014-04-04 18:20:33 -05:00
|
|
|
//app logic
|
2013-09-23 14:41:52 -04:00
|
|
|
void
|
2014-04-04 18:20:33 -05:00
|
|
|
SessionDialog::on_quit (WavesButton*)
|
2013-09-23 14:41:52 -04:00
|
|
|
{
|
2014-04-04 18:20:33 -05:00
|
|
|
hide();
|
|
|
|
|
response (Gtk::RESPONSE_CANCEL);
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-04-04 18:20:33 -05:00
|
|
|
SessionDialog::on_open_selected (WavesButton*)
|
2013-09-23 14:41:52 -04:00
|
|
|
{
|
2014-04-04 18:20:33 -05:00
|
|
|
hide();
|
|
|
|
|
response (Gtk::RESPONSE_ACCEPT);
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-04-04 18:20:33 -05:00
|
|
|
SessionDialog::on_open_saved_session (WavesButton*)
|
|
|
|
|
{
|
|
|
|
|
Gtk::FileChooserDialog dialog(*this, _("Select Saved Session"));
|
|
|
|
|
dialog.add_button("CANCEL", Gtk::RESPONSE_CANCEL);
|
|
|
|
|
dialog.add_button("OK", Gtk::RESPONSE_OK);
|
|
|
|
|
if (dialog.run() == Gtk::RESPONSE_OK) {
|
|
|
|
|
selected_session_full_name = dialog.get_filename();
|
2014-04-11 04:10:58 -05:00
|
|
|
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
|
|
|
|
|
recent_session_button[i]->set_active(false);
|
|
|
|
|
}
|
|
|
|
|
_selection_type = SavedSession;
|
2014-04-04 18:20:33 -05:00
|
|
|
hide();
|
|
|
|
|
response (Gtk::RESPONSE_ACCEPT);
|
|
|
|
|
}
|
2013-09-23 14:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-04-04 18:20:33 -05:00
|
|
|
SessionDialog::on_recent_session (WavesButton* clicked_button)
|
2013-09-23 14:41:52 -04:00
|
|
|
{
|
2014-04-04 18:20:33 -05:00
|
|
|
if (clicked_button->get_active()) {
|
2014-04-11 04:10:58 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2014-04-04 18:20:33 -05:00
|
|
|
else {
|
2014-04-11 04:10:58 -05:00
|
|
|
selected_session_full_name = "";
|
|
|
|
|
_selection_type = Nothing;
|
2014-04-04 18:20:33 -05:00
|
|
|
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
|
|
|
|
|
if (recent_session_button[i] == clicked_button) {
|
2014-04-11 04:10:58 -05:00
|
|
|
selected_session_full_name = recent_session_full_name[i];
|
|
|
|
|
recent_session_button[i]->set_active(true);
|
|
|
|
|
} else {
|
|
|
|
|
recent_session_button[i]->set_active(false);
|
|
|
|
|
_selection_type = RecentSession;
|
|
|
|
|
}
|
2014-04-04 18:20:33 -05:00
|
|
|
}
|
2014-04-10 11:16:26 -05:00
|
|
|
}
|
2013-09-23 14:41:52 -04:00
|
|
|
|
2014-04-11 04:10:58 -05:00
|
|
|
if (_selection_type == RecentSession) {
|
2014-04-04 18:20:33 -05:00
|
|
|
open_selected_button.set_sensitive (true);
|
2014-04-10 04:54:47 -05:00
|
|
|
float sr;
|
|
|
|
|
SampleFormat sf;
|
2014-04-10 13:54:52 -05:00
|
|
|
if (Session::get_info_from_path (selected_session_full_name, sr, sf) == 0) {
|
2014-04-10 04:54:47 -05:00
|
|
|
std::string sample_format(sf == FormatFloat ? _("32 bit float") :
|
|
|
|
|
(sf == FormatInt24 ? _("24 bit") :
|
|
|
|
|
(sf == FormatInt16 ? _("16 bit") :
|
|
|
|
|
"??")));
|
|
|
|
|
session_details_label.set_text(string_compose (_("<TBI>\n<TBI>\n<TBI>\n%1\n%2"), sr, sample_format));
|
|
|
|
|
}
|
2014-04-04 18:20:33 -05:00
|
|
|
} else {
|
|
|
|
|
open_selected_button.set_sensitive (false);
|
|
|
|
|
}
|
|
|
|
|
}
|