2005-09-25 14:42:24 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2000 Paul Davis
|
|
|
|
|
|
|
|
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 <cstdlib>
|
|
|
|
#include <cmath>
|
|
|
|
#include <vector>
|
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
#include <gtkmm.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/named_selection.h"
|
|
|
|
#include "ardour/session_selection.h"
|
|
|
|
#include "ardour/playlist.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
#include <gtkmm2ext/stop_signal.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "editor.h"
|
2007-02-08 22:36:00 -05:00
|
|
|
#include "keyboard.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "selection.h"
|
|
|
|
#include "time_axis_view.h"
|
|
|
|
#include "ardour_ui.h"
|
|
|
|
#include "prompter.h"
|
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
2009-05-12 13:03:42 -04:00
|
|
|
using namespace std;
|
2005-09-25 16:33:00 -04:00
|
|
|
using namespace sigc;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace ARDOUR;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace Gtk;
|
2005-09-25 16:33:00 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
Editor::handle_new_named_selection ()
|
|
|
|
{
|
2005-09-25 17:19:23 -04:00
|
|
|
ARDOUR_UI::instance()->call_slot (mem_fun(*this, &Editor::redisplay_named_selections));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Editor::add_named_selection_to_named_selection_display (NamedSelection& selection)
|
|
|
|
{
|
2005-10-26 14:12:00 -04:00
|
|
|
TreeModel::Row row = *(named_selection_model->append());
|
|
|
|
row[named_selection_columns.text] = selection.name;
|
|
|
|
row[named_selection_columns.selection] = &selection;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Editor::redisplay_named_selections ()
|
|
|
|
{
|
2005-11-28 17:36:26 -05:00
|
|
|
named_selection_model->clear ();
|
2005-09-25 14:42:24 -04:00
|
|
|
session->foreach_named_selection (*this, &Editor::add_named_selection_to_named_selection_display);
|
|
|
|
}
|
|
|
|
|
2007-01-11 16:45:21 -05:00
|
|
|
bool
|
|
|
|
Editor::named_selection_display_key_release (GdkEventKey* ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2007-01-11 16:45:21 -05:00
|
|
|
if (session == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev->keyval) {
|
|
|
|
case GDK_Delete:
|
|
|
|
remove_selected_named_selections ();
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Editor::remove_selected_named_selections ()
|
|
|
|
{
|
|
|
|
Glib::RefPtr<TreeSelection> selection = named_selection_display.get_selection();
|
|
|
|
TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
|
|
|
|
|
|
|
|
if (selection->count_selected_rows() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
|
|
|
|
|
|
|
|
TreeIter iter;
|
2005-10-26 14:12:00 -04:00
|
|
|
|
2007-01-11 16:45:21 -05:00
|
|
|
if ((iter = named_selection_model->get_iter (*i))) {
|
|
|
|
session->remove_named_selection ((*iter)[named_selection_columns.selection]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Editor::named_selection_display_button_release (GdkEventButton *ev)
|
|
|
|
{
|
2005-10-26 14:12:00 -04:00
|
|
|
TreeModel::Children rows = named_selection_model->children();
|
|
|
|
TreeModel::Children::iterator i;
|
|
|
|
Glib::RefPtr<TreeSelection> selection = named_selection_display.get_selection();
|
|
|
|
|
|
|
|
for (i = rows.begin(); i != rows.end(); ++i) {
|
|
|
|
if (selection->is_selected (i)) {
|
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
|
|
|
if (Keyboard::is_delete_event (ev)) {
|
|
|
|
session->remove_named_selection ((*i)[named_selection_columns.selection]);
|
2006-12-08 12:16:50 -05:00
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2005-10-26 14:12:00 -04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2005-10-26 14:12:00 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2007-01-11 16:45:21 -05:00
|
|
|
|
|
|
|
return false;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-10-26 14:12:00 -04:00
|
|
|
Editor::named_selection_display_selection_changed ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-01-11 16:45:21 -05:00
|
|
|
Editor::create_named_selection ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2007-01-11 16:45:21 -05:00
|
|
|
string name;
|
2005-10-26 14:12:00 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
if (session == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for a range-based selection */
|
|
|
|
|
|
|
|
if (selection->time.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
|
|
|
|
|
|
|
|
if (views->empty()) {
|
|
|
|
delete views;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<Playlist> what_we_found;
|
|
|
|
list<boost::shared_ptr<Playlist> > thelist;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
|
|
|
|
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<Playlist> pl = (*i)->playlist();
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-01-11 16:45:21 -05:00
|
|
|
if (pl && (what_we_found = pl->copy (selection->time, false)) != 0) {
|
|
|
|
thelist.push_back (what_we_found);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-11 16:45:21 -05:00
|
|
|
if (!thelist.empty()) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-01-11 16:45:21 -05:00
|
|
|
ArdourPrompter p;
|
|
|
|
|
|
|
|
p.set_prompt (_("Name for Chunk:"));
|
|
|
|
p.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
|
|
|
|
p.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
|
|
|
p.change_labels (_("Create Chunk"), _("Forget it"));
|
|
|
|
p.show_all ();
|
|
|
|
|
|
|
|
switch (p.run ()) {
|
|
|
|
|
|
|
|
case Gtk::RESPONSE_ACCEPT:
|
|
|
|
p.get_result (name);
|
|
|
|
if (name.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-01-11 16:45:21 -05:00
|
|
|
new NamedSelection (name, thelist); // creation will add it to the model
|
2005-10-26 14:12:00 -04:00
|
|
|
|
2007-01-11 16:45:21 -05:00
|
|
|
/* make the one we just added be selected */
|
|
|
|
|
|
|
|
TreeModel::Children::iterator added = named_selection_model->children().end();
|
|
|
|
--added;
|
|
|
|
named_selection_display.get_selection()->select (*added);
|
|
|
|
} else {
|
|
|
|
error << _("No selectable material found in the currently selected time range") << endmsg;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|