Consistent preset layout
[ardour.git] / gtk2_ardour / export_timespan_selector.h
1 /*
2  * Copyright (C) 2008-2011 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
5  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2013-2014 Colin Fletcher <colin.m.fletcher@googlemail.com>
7  * Copyright (C) 2016-2017 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef __export_timespan_selector_h__
25 #define __export_timespan_selector_h__
26
27 #include "audio_clock.h"
28
29 #include <list>
30 #include <ctime>
31
32
33 #ifdef interface
34 #undef interface
35 #endif
36
37 #include <boost/shared_ptr.hpp>
38
39 #include <gtkmm/box.h>
40 #include <gtkmm/checkbutton.h>
41 #include <gtkmm/combobox.h>
42 #include <gtkmm/label.h>
43 #include <gtkmm/liststore.h>
44 #include <gtkmm/scrolledwindow.h>
45 #include <gtkmm/treemodel.h>
46 #include <gtkmm/treestore.h>
47 #include <gtkmm/treeview.h>
48
49 #include "ardour/types.h"
50 #include "ardour/session_handle.h"
51 #include "ardour/export_profile_manager.h"
52
53 namespace ARDOUR {
54         class Location;
55         class ExportTimespan;
56         class ExportHandler;
57 }
58
59 using ARDOUR::CDMarkerFormat;
60 using ARDOUR::samplecnt_t;
61
62 /// Timespan Selector base
63 class ExportTimespanSelector : public Gtk::VBox, public ARDOUR::SessionHandlePtr
64 {
65 protected:
66         typedef std::list<ARDOUR::Location *> LocationList;
67         typedef boost::shared_ptr<ARDOUR::ExportHandler> HandlerPtr;
68         typedef boost::shared_ptr<ARDOUR::ExportProfileManager> ProfileManagerPtr;
69
70         typedef std::list<ARDOUR::ExportTimespanPtr> TimespanList;
71         typedef boost::shared_ptr<TimespanList> TimespanListPtr;
72         typedef ARDOUR::ExportProfileManager::TimespanStatePtr TimespanStatePtr;
73
74 public:
75
76         ExportTimespanSelector (ARDOUR::Session * session, ProfileManagerPtr manager, bool multi);
77
78         virtual ~ExportTimespanSelector ();
79
80         void sync_with_manager ();
81         virtual void allow_realtime_export (bool);
82
83         sigc::signal<void> CriticalSelectionChanged;
84
85 protected:
86
87         ProfileManagerPtr manager;
88         TimespanStatePtr  state;
89         bool _realtime_available;
90
91         virtual void fill_range_list () = 0;
92         virtual void update_timespans () = 0;
93
94         void add_range_to_selection (ARDOUR::Location const * loc, bool rt);
95         void set_time_format_from_state ();
96         void toggle_realtime ();
97
98         void change_time_format ();
99
100         std::string construct_label (ARDOUR::Location const * location) const;
101         std::string construct_length (ARDOUR::Location const * location) const;
102         std::string bbt_str (samplepos_t samples) const;
103         std::string timecode_str (samplecnt_t samples) const;
104         std::string ms_str (samplecnt_t samples) const;
105
106         void update_range_name (std::string const & path, std::string const & new_text);
107
108         void set_selection_state_of_all_timespans (bool);
109         int location_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b);
110
111         /*** GUI components ***/
112
113         Gtk::HBox        option_hbox;
114         Gtk::Label       time_format_label;
115         Gtk::CheckButton realtime_checkbutton;
116
117         /* Time format */
118
119         typedef ARDOUR::ExportProfileManager::TimeFormat TimeFormat;
120
121         struct TimeFormatCols : public Gtk::TreeModelColumnRecord
122         {
123         public:
124                 Gtk::TreeModelColumn<TimeFormat>      format;
125                 Gtk::TreeModelColumn<std::string>   label;
126
127                 TimeFormatCols () { add(format); add(label); }
128         };
129         TimeFormatCols               time_format_cols;
130         Glib::RefPtr<Gtk::ListStore> time_format_list;
131         Gtk::ComboBox                time_format_combo;
132
133         /* View */
134
135         struct RangeCols : public Gtk::TreeModelColumnRecord
136         {
137         public:
138                 Gtk::TreeModelColumn<ARDOUR::Location *>  location;
139                 Gtk::TreeModelColumn<std::string>       label;
140                 Gtk::TreeModelColumn<bool>              selected;
141                 Gtk::TreeModelColumn<bool>              realtime;
142                 Gtk::TreeModelColumn<std::string>       name;
143                 Gtk::TreeModelColumn<std::string>       length;
144                 Gtk::TreeModelColumn<std::string>       date;
145                 Gtk::TreeModelColumn<time_t>            timestamp;
146
147                 RangeCols () { add (location); add(label); add(selected); add(realtime); add(name); add(length); add(date); add(timestamp);}
148         };
149         RangeCols                    range_cols;
150
151         Glib::RefPtr<Gtk::ListStore> range_list;
152         Gtk::TreeView                range_view;
153
154         Gtk::ScrolledWindow          range_scroller;
155 };
156
157 /// Allows selecting multiple timespans
158 class ExportTimespanSelectorMultiple : public ExportTimespanSelector
159 {
160 public:
161         ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager);
162
163         void allow_realtime_export (bool);
164
165 private:
166
167         virtual void fill_range_list ();
168
169         void set_selection_from_state ();
170         void update_selection ();
171         void update_timespans ();
172 };
173
174 /// Displays one timespan
175 class ExportTimespanSelectorSingle : public ExportTimespanSelector
176 {
177 public:
178         ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id);
179
180         void allow_realtime_export (bool);
181
182 private:
183
184         virtual void fill_range_list ();
185         void update_timespans ();
186
187         std::string range_id;
188
189 };
190
191 #endif /* __export_timespan_selector_h__ */