switch to using boost::signals2 instead of sigc++, at least for libardour. not finish...
[ardour.git] / gtk2_ardour / audio_clock.h
1 /*
2     Copyright (C) 1999 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __audio_clock_h__
21 #define __audio_clock_h__
22
23 #include <gtkmm/box.h>
24 #include <gtkmm/menu.h>
25 #include <gtkmm/eventbox.h>
26 #include <gtkmm/label.h>
27 #include <gtkmm/frame.h>
28 #include "ardour/ardour.h"
29 #include "ardour/session_handle.h"
30
31 namespace ARDOUR {
32         class Session;
33 }
34
35 class AudioClock : public Gtk::HBox, public ARDOUR::SessionHandlePtr
36 {
37   public:
38         enum Mode {
39                 Timecode,
40                 BBT,
41                 MinSec,
42                 Frames,
43                 Off
44         };
45
46         AudioClock (std::string, bool, std::string, bool, bool, bool duration = false, bool with_info = false);
47
48         Mode mode() const { return _mode; }
49
50         void focus ();
51
52         void set (nframes_t, bool force = false, nframes_t offset = 0, char which = 0);
53         void set_from_playhead ();
54         void locate ();
55         void set_mode (Mode);
56         void set_bbt_reference (nframes64_t);
57
58         void set_widget_name (std::string);
59
60         std::string name() const { return _name; }
61
62         nframes_t current_time (nframes_t position = 0) const;
63         nframes_t current_duration (nframes_t position = 0) const;
64         void set_session (ARDOUR::Session *s);
65
66         sigc::signal<void> ValueChanged;
67         sigc::signal<void> mode_changed;
68         sigc::signal<void> ChangeAborted;
69
70         static sigc::signal<void> ModeChanged;
71         static std::vector<AudioClock*> clocks;
72
73         static bool has_focus() { return _has_focus; }
74
75   private:
76         Mode             _mode;
77         uint32_t          key_entry_state;
78         std::string      _name;
79         bool              is_transient;
80         bool              is_duration;
81         bool              editable;
82         /** true if this clock follows the playhead, meaning that certain operations are redundant */
83         bool             _follows_playhead;
84
85         Gtk::Menu  *ops_menu;
86
87         Gtk::HBox   timecode_packer_hbox;
88         Gtk::HBox   timecode_packer;
89
90         Gtk::HBox   minsec_packer_hbox;
91         Gtk::HBox   minsec_packer;
92
93         Gtk::HBox   bbt_packer_hbox;
94         Gtk::HBox   bbt_packer;
95
96         Gtk::HBox   frames_packer_hbox;
97         Gtk::HBox   frames_packer;
98
99         enum Field {
100                 Timecode_Hours,
101                 Timecode_Minutes,
102                 Timecode_Seconds,
103                 Timecode_Frames,
104                 MS_Hours,
105                 MS_Minutes,
106                 MS_Seconds,
107                 Bars,
108                 Beats,
109                 Ticks,
110                 AudioFrames
111         };
112
113         Gtk::EventBox  audio_frames_ebox;
114         Gtk::Label     audio_frames_label;
115
116         Gtk::HBox      off_hbox;
117
118         Gtk::EventBox  hours_ebox;
119         Gtk::EventBox  minutes_ebox;
120         Gtk::EventBox  seconds_ebox;
121         Gtk::EventBox  frames_ebox;
122
123         Gtk::EventBox  ms_hours_ebox;
124         Gtk::EventBox  ms_minutes_ebox;
125         Gtk::EventBox  ms_seconds_ebox;
126
127         Gtk::EventBox  bars_ebox;
128         Gtk::EventBox  beats_ebox;
129         Gtk::EventBox  ticks_ebox;
130
131         Gtk::Label  hours_label;
132         Gtk::Label  minutes_label;
133         Gtk::Label  seconds_label;
134         Gtk::Label  frames_label;
135         Gtk::Label  colon1, colon2, colon3;
136
137         Gtk::Label  ms_hours_label;
138         Gtk::Label  ms_minutes_label;
139         Gtk::Label  ms_seconds_label;
140         Gtk::Label  colon4, colon5;
141
142         Gtk::Label  bars_label;
143         Gtk::Label  beats_label;
144         Gtk::Label  ticks_label;
145         Gtk::Label  b1;
146         Gtk::Label  b2;
147
148         Gtk::Label*  frames_upper_info_label;
149         Gtk::Label*  frames_lower_info_label;
150
151         Gtk::Label*  timecode_upper_info_label;
152         Gtk::Label*  timecode_lower_info_label;
153
154         Gtk::Label*  bbt_upper_info_label;
155         Gtk::Label*  bbt_lower_info_label;
156
157         Gtk::VBox   frames_info_box;
158         Gtk::VBox   timecode_info_box;
159         Gtk::VBox   bbt_info_box;
160
161         Gtk::EventBox  clock_base;
162         Gtk::Frame     clock_frame;
163
164         nframes64_t bbt_reference_time;
165         nframes_t last_when;
166         bool last_pdelta;
167         bool last_sdelta;
168
169         uint32_t last_hrs;
170         uint32_t last_mins;
171         uint32_t last_secs;
172         uint32_t last_frames;
173         bool last_negative;
174
175         long  ms_last_hrs;
176         long  ms_last_mins;
177         float ms_last_secs;
178
179         bool dragging;
180         double drag_start_y;
181         double drag_y;
182         double drag_accum;
183
184         void on_realize ();
185
186         bool field_motion_notify_event (GdkEventMotion *ev, Field);
187         bool field_button_press_event (GdkEventButton *ev, Field);
188         bool field_button_release_event (GdkEventButton *ev, Field);
189         bool field_button_scroll_event (GdkEventScroll *ev, Field);
190         bool field_key_press_event (GdkEventKey *, Field);
191         bool field_key_release_event (GdkEventKey *, Field);
192         bool field_focus_in_event (GdkEventFocus *, Field);
193         bool field_focus_out_event (GdkEventFocus *, Field);
194         bool drop_focus_handler (GdkEventFocus*);
195
196         void set_timecode (nframes_t, bool);
197         void set_bbt (nframes_t, bool);
198         void set_minsec (nframes_t, bool);
199         void set_frames (nframes_t, bool);
200
201         nframes_t get_frames (Field,nframes_t pos = 0,int dir=1);
202
203         void timecode_sanitize_display();
204         nframes_t timecode_frame_from_display () const;
205         nframes_t bbt_frame_from_display (nframes_t) const;
206         nframes_t bbt_frame_duration_from_display (nframes_t) const;
207         nframes_t minsec_frame_from_display () const;
208         nframes_t audio_frame_from_display () const;
209
210         void build_ops_menu ();
211         void setup_events ();
212
213         void timecode_offset_changed ();
214         void set_size_requests ();
215
216         static const uint32_t field_length[(int)AudioFrames+1];
217         static bool _has_focus;
218
219 };
220
221 #endif /* __audio_clock_h__ */