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