fix mistaken "do not roll" conclusion in TransportFSM::compute_should_roll()
[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 <ctime>
30 #include <list>
31
32 #ifdef interface
33 #undef interface
34 #endif
35
36 #include <boost/shared_ptr.hpp>
37
38 #include <gtkmm/box.h>
39 #include <gtkmm/checkbutton.h>
40 #include <gtkmm/combobox.h>
41 #include <gtkmm/label.h>
42 #include <gtkmm/liststore.h>
43 #include <gtkmm/scrolledwindow.h>
44 #include <gtkmm/treemodel.h>
45 #include <gtkmm/treestore.h>
46 #include <gtkmm/treeview.h>
47
48 #include "ardour/export_profile_manager.h"
49 #include "ardour/session_handle.h"
50 #include "ardour/types.h"
51
52 namespace ARDOUR {
53         class Location;
54         class ExportTimespan;
55         class ExportHandler;
56 }
57
58 using ARDOUR::CDMarkerFormat;
59 using ARDOUR::samplecnt_t;
60
61 /// Timespan Selector base
62 class ExportTimespanSelector : public Gtk::VBox, public ARDOUR::SessionHandlePtr
63 {
64 protected:
65         typedef std::list<ARDOUR::Location*>                    LocationList;
66         typedef boost::shared_ptr<ARDOUR::ExportHandler>        HandlerPtr;
67         typedef boost::shared_ptr<ARDOUR::ExportProfileManager> ProfileManagerPtr;
68
69         typedef std::list<ARDOUR::ExportTimespanPtr>           TimespanList;
70         typedef boost::shared_ptr<TimespanList>                TimespanListPtr;
71         typedef ARDOUR::ExportProfileManager::TimespanStatePtr TimespanStatePtr;
72
73 public:
74         ExportTimespanSelector (ARDOUR::Session* session, ProfileManagerPtr manager, bool multi);
75
76         virtual ~ExportTimespanSelector ();
77
78         void sync_with_manager ();
79         virtual void allow_realtime_export (bool);
80
81         sigc::signal<void> CriticalSelectionChanged;
82
83 protected:
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         public:
120                 Gtk::TreeModelColumn<TimeFormat>  format;
121                 Gtk::TreeModelColumn<std::string> label;
122
123                 TimeFormatCols ()
124                 {
125                         add (format);
126                         add (label);
127                 }
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         public:
137                 Gtk::TreeModelColumn<ARDOUR::Location*>   location;
138                 Gtk::TreeModelColumn<std::string>         label;
139                 Gtk::TreeModelColumn<bool>                selected;
140                 Gtk::TreeModelColumn<bool>                realtime;
141                 Gtk::TreeModelColumn<std::string>         name;
142                 Gtk::TreeModelColumn<std::string>         length;
143                 Gtk::TreeModelColumn<std::string>         date;
144                 Gtk::TreeModelColumn<time_t>              timestamp;
145                 Gtk::TreeModelColumn<ARDOUR::samplecnt_t> length_actual;
146                 Gtk::TreeModelColumn<ARDOUR::samplecnt_t> start;
147
148                 RangeCols ()
149                 {
150                         add (location);
151                         add (label);
152                         add (selected);
153                         add (realtime);
154                         add (name);
155                         add (length);
156                         add (date);
157                         add (timestamp);
158                         add (length_actual);
159                         add (start);
160                 }
161         };
162         RangeCols range_cols;
163
164         Glib::RefPtr<Gtk::ListStore> range_list;
165         Gtk::TreeView                range_view;
166
167         Gtk::ScrolledWindow range_scroller;
168 };
169
170 /// Allows selecting multiple timespans
171 class ExportTimespanSelectorMultiple : public ExportTimespanSelector
172 {
173 public:
174         ExportTimespanSelectorMultiple (ARDOUR::Session* session, ProfileManagerPtr manager);
175
176         void allow_realtime_export (bool);
177
178 private:
179         virtual void fill_range_list ();
180
181         void set_selection_from_state ();
182         void update_selection ();
183         void update_timespans ();
184 };
185
186 /// Displays one timespan
187 class ExportTimespanSelectorSingle : public ExportTimespanSelector
188 {
189 public:
190         ExportTimespanSelectorSingle (ARDOUR::Session* session, ProfileManagerPtr manager, std::string range_id);
191
192         void allow_realtime_export (bool);
193
194 private:
195         virtual void fill_range_list ();
196         void         update_timespans ();
197
198         std::string range_id;
199 };
200
201 #endif /* __export_timespan_selector_h__ */