Merge remote-tracking branch 'origin/master' into export-dialog
[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 #include <gtkmm.h>
29 #include <boost/shared_ptr.hpp>
30
31 #include "ardour/types.h"
32 #include "ardour/session_handle.h"
33 #include "ardour/export_profile_manager.h"
34
35 namespace ARDOUR {
36         class Location;
37         class ExportTimespan;
38         class ExportHandler;
39 }
40
41 using ARDOUR::CDMarkerFormat;
42 using ARDOUR::framecnt_t;
43
44 /// Timespan Selector base
45 class ExportTimespanSelector : public Gtk::VBox, public ARDOUR::SessionHandlePtr
46 {
47   protected:
48         typedef std::list<ARDOUR::Location *> LocationList;
49         typedef boost::shared_ptr<ARDOUR::ExportHandler> HandlerPtr;
50         typedef boost::shared_ptr<ARDOUR::ExportProfileManager> ProfileManagerPtr;
51
52         typedef std::list<ARDOUR::ExportTimespanPtr> TimespanList;
53         typedef boost::shared_ptr<TimespanList> TimespanListPtr;
54         typedef ARDOUR::ExportProfileManager::TimespanStatePtr TimespanStatePtr;
55
56   public:
57
58         ExportTimespanSelector (ARDOUR::Session * session, ProfileManagerPtr manager);
59
60         virtual ~ExportTimespanSelector ();
61
62         void sync_with_manager ();
63
64         sigc::signal<void> CriticalSelectionChanged;
65
66   protected:
67
68         ProfileManagerPtr manager;
69         TimespanStatePtr  state;
70
71         virtual void fill_range_list () = 0;
72
73         void add_range_to_selection (ARDOUR::Location const * loc);
74         void set_time_format_from_state ();
75
76         void change_time_format ();
77
78         std::string construct_label (ARDOUR::Location const * location) const;
79         std::string construct_length (ARDOUR::Location const * location) const;
80         std::string bbt_str (framepos_t frames) const;
81         std::string timecode_str (framecnt_t frames) const;
82         std::string ms_str (framecnt_t frames) const;
83
84         void update_range_name (std::string const & path, std::string const & new_text);
85
86         void set_selection_state_of_all_timespans (bool);
87         int location_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b);
88
89         /*** GUI components ***/
90
91         Gtk::HBox      option_hbox;
92         Gtk::Label     time_format_label;
93
94         /* Time format */
95
96         typedef ARDOUR::ExportProfileManager::TimeFormat TimeFormat;
97
98         struct TimeFormatCols : public Gtk::TreeModelColumnRecord
99         {
100           public:
101                 Gtk::TreeModelColumn<TimeFormat>      format;
102                 Gtk::TreeModelColumn<std::string>   label;
103
104                 TimeFormatCols () { add(format); add(label); }
105         };
106         TimeFormatCols               time_format_cols;
107         Glib::RefPtr<Gtk::ListStore> time_format_list;
108         Gtk::ComboBox                time_format_combo;
109
110         /* View */
111
112         struct RangeCols : public Gtk::TreeModelColumnRecord
113         {
114           public:
115                 Gtk::TreeModelColumn<ARDOUR::Location *>  location;
116                 Gtk::TreeModelColumn<std::string>       label;
117                 Gtk::TreeModelColumn<bool>              selected;
118                 Gtk::TreeModelColumn<std::string>       name;
119                 Gtk::TreeModelColumn<std::string>       length;
120
121                 RangeCols () { add (location); add(label); add(selected); add(name); add(length); }
122         };
123         RangeCols                    range_cols;
124
125         Glib::RefPtr<Gtk::ListStore> range_list;
126         Gtk::TreeView                range_view;
127
128         Gtk::ScrolledWindow          range_scroller;
129 };
130
131 /// Allows selecting multiple timespans
132 class ExportTimespanSelectorMultiple : public ExportTimespanSelector
133 {
134   public:
135         ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager);
136
137   private:
138
139         virtual void fill_range_list ();
140
141         void set_selection_from_state ();
142         void update_selection ();
143         void update_timespans ();
144 };
145
146 /// Displays one timespan
147 class ExportTimespanSelectorSingle : public ExportTimespanSelector
148 {
149   public:
150         ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id);
151
152   private:
153
154         virtual void fill_range_list ();
155
156         std::string range_id;
157
158 };
159
160 #endif /* __export_timespan_selector_h__ */