use new action map API instead of ActionManager::get_action
[ardour.git] / gtk2_ardour / export_timespan_selector.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __export_timespan_selector_h__
22 #define __export_timespan_selector_h__
23
24 #include "audio_clock.h"
25
26 #include <list>
27
28 #ifdef interface
29 #undef interface
30 #endif
31
32 #include <boost/shared_ptr.hpp>
33
34 #include <gtkmm/box.h>
35 #include <gtkmm/checkbutton.h>
36 #include <gtkmm/combobox.h>
37 #include <gtkmm/label.h>
38 #include <gtkmm/liststore.h>
39 #include <gtkmm/scrolledwindow.h>
40 #include <gtkmm/treemodel.h>
41 #include <gtkmm/treestore.h>
42 #include <gtkmm/treeview.h>
43
44 #include "ardour/types.h"
45 #include "ardour/session_handle.h"
46 #include "ardour/export_profile_manager.h"
47
48 namespace ARDOUR {
49         class Location;
50         class ExportTimespan;
51         class ExportHandler;
52 }
53
54 using ARDOUR::CDMarkerFormat;
55 using ARDOUR::samplecnt_t;
56
57 /// Timespan Selector base
58 class ExportTimespanSelector : public Gtk::VBox, public ARDOUR::SessionHandlePtr
59 {
60 protected:
61         typedef std::list<ARDOUR::Location *> LocationList;
62         typedef boost::shared_ptr<ARDOUR::ExportHandler> HandlerPtr;
63         typedef boost::shared_ptr<ARDOUR::ExportProfileManager> ProfileManagerPtr;
64
65         typedef std::list<ARDOUR::ExportTimespanPtr> TimespanList;
66         typedef boost::shared_ptr<TimespanList> TimespanListPtr;
67         typedef ARDOUR::ExportProfileManager::TimespanStatePtr TimespanStatePtr;
68
69 public:
70
71         ExportTimespanSelector (ARDOUR::Session * session, ProfileManagerPtr manager, bool multi);
72
73         virtual ~ExportTimespanSelector ();
74
75         void sync_with_manager ();
76         virtual void allow_realtime_export (bool);
77
78         sigc::signal<void> CriticalSelectionChanged;
79
80 protected:
81
82         ProfileManagerPtr manager;
83         TimespanStatePtr  state;
84         bool _realtime_available;
85
86         virtual void fill_range_list () = 0;
87         virtual void update_timespans () = 0;
88
89         void add_range_to_selection (ARDOUR::Location const * loc, bool rt);
90         void set_time_format_from_state ();
91         void toggle_realtime ();
92
93         void change_time_format ();
94
95         std::string construct_label (ARDOUR::Location const * location) const;
96         std::string construct_length (ARDOUR::Location const * location) const;
97         std::string bbt_str (samplepos_t samples) const;
98         std::string timecode_str (samplecnt_t samples) const;
99         std::string ms_str (samplecnt_t samples) const;
100
101         void update_range_name (std::string const & path, std::string const & new_text);
102
103         void set_selection_state_of_all_timespans (bool);
104         int location_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b);
105
106         /*** GUI components ***/
107
108         Gtk::HBox        option_hbox;
109         Gtk::Label       time_format_label;
110         Gtk::CheckButton realtime_checkbutton;
111
112         /* Time format */
113
114         typedef ARDOUR::ExportProfileManager::TimeFormat TimeFormat;
115
116         struct TimeFormatCols : public Gtk::TreeModelColumnRecord
117         {
118         public:
119                 Gtk::TreeModelColumn<TimeFormat>      format;
120                 Gtk::TreeModelColumn<std::string>   label;
121
122                 TimeFormatCols () { add(format); add(label); }
123         };
124         TimeFormatCols               time_format_cols;
125         Glib::RefPtr<Gtk::ListStore> time_format_list;
126         Gtk::ComboBox                time_format_combo;
127
128         /* View */
129
130         struct RangeCols : public Gtk::TreeModelColumnRecord
131         {
132         public:
133                 Gtk::TreeModelColumn<ARDOUR::Location *>  location;
134                 Gtk::TreeModelColumn<std::string>       label;
135                 Gtk::TreeModelColumn<bool>              selected;
136                 Gtk::TreeModelColumn<bool>              realtime;
137                 Gtk::TreeModelColumn<std::string>       name;
138                 Gtk::TreeModelColumn<std::string>       length;
139
140                 RangeCols () { add (location); add(label); add(selected); add(realtime); add(name); add(length); }
141         };
142         RangeCols                    range_cols;
143
144         Glib::RefPtr<Gtk::ListStore> range_list;
145         Gtk::TreeView                range_view;
146
147         Gtk::ScrolledWindow          range_scroller;
148 };
149
150 /// Allows selecting multiple timespans
151 class ExportTimespanSelectorMultiple : public ExportTimespanSelector
152 {
153 public:
154         ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager);
155
156         void allow_realtime_export (bool);
157
158 private:
159
160         virtual void fill_range_list ();
161
162         void set_selection_from_state ();
163         void update_selection ();
164         void update_timespans ();
165 };
166
167 /// Displays one timespan
168 class ExportTimespanSelectorSingle : public ExportTimespanSelector
169 {
170 public:
171         ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id);
172
173         void allow_realtime_export (bool);
174
175 private:
176
177         virtual void fill_range_list ();
178         void update_timespans ();
179
180         std::string range_id;
181
182 };
183
184 #endif /* __export_timespan_selector_h__ */