2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <ardour/named_selection.h>
28 #include <ardour/session_selection.h>
29 #include <ardour/playlist.h>
31 #include <gtkmmext/stop_signal.h>
34 #include "selection.h"
35 #include "time_axis_view.h"
36 #include "ardour_ui.h"
42 using namespace ARDOUR;
44 using namespace Gtkmmext;
47 Editor::handle_new_named_selection ()
49 ARDOUR_UI::instance()->call_slot (slot (*this, &Editor::redisplay_named_selections));
53 Editor::add_named_selection_to_named_selection_display (NamedSelection& selection)
57 row[0] = selection.name.c_str();
58 named_selection_display.rows().push_back (row);
59 named_selection_display.rows().back().set_data (&selection);
63 Editor::redisplay_named_selections ()
65 named_selection_display.freeze ();
66 named_selection_display.clear ();
67 session->foreach_named_selection (*this, &Editor::add_named_selection_to_named_selection_display);
68 named_selection_display.thaw ();
72 Editor::named_selection_display_button_press (GdkEventButton *ev)
74 NamedSelection* named_selection;
80 if (Keyboard::is_delete_event (ev)) {
81 if (named_selection_display.get_selection_info ((int)ev->x, (int)ev->y, &row, &col) != 0) {
82 if ((named_selection = reinterpret_cast<NamedSelection *> (named_selection_display.get_row_data (row))) != 0) {
83 session->remove_named_selection (named_selection);
84 return stop_signal (named_selection_display, "button_press_event");
103 Editor::named_selection_display_selected (gint row, gint col, GdkEvent *ev)
108 Editor::named_selection_display_unselected (gint row, gint col, GdkEvent *ev)
113 Editor::name_selection ()
117 p.set_prompt (_("name for chunk:"));
118 p.done.connect (slot (*this, &Editor::named_selection_name_chosen));
119 p.change_labels (_("Create chunk"), _("Forget it"));
124 if (p.status == Prompter::entered) {
129 create_named_selection (name);
135 Editor::named_selection_name_chosen ()
141 Editor::create_named_selection (string name)
147 /* check for a range-based selection */
149 if (selection->time.empty()) {
154 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
156 if (views->empty()) {
161 Playlist* what_we_found;
162 list<Playlist*> thelist;
164 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
166 Playlist *pl = (*i)->playlist();
170 if ((what_we_found = pl->copy (selection->time, false)) != 0) {
172 thelist.push_back (what_we_found);
179 ns = new NamedSelection (name, thelist);
181 /* make the one we just added be selected */
183 named_selection_display.rows().back().select ();