catch markers as they go away, to avoid selection corruption; add select-range-betwee...
[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
30 namespace ARDOUR {
31         class Session;
32 }
33
34 class AudioClock : public Gtk::HBox
35 {
36   public:
37         enum Mode {
38                 SMPTE,
39                 BBT,
40                 MinSec,
41                 Frames,
42                 Off
43         };
44         
45         AudioClock (std::string clock_name, bool transient, std::string widget_name, bool editable, bool is_duration = false, bool with_info = false);
46
47         Mode mode() const { return _mode; }
48         
49         void set (nframes_t, bool force = false, nframes_t offset = 0, int which = 0);
50         void set_mode (Mode);
51         
52         void set_widget_name (std::string);
53
54         std::string name() const { return _name; }
55
56         nframes_t current_time (nframes_t position = 0) const;
57         nframes_t current_duration (nframes_t position = 0) const;
58         void set_session (ARDOUR::Session *s);
59
60         sigc::signal<void> ValueChanged;
61
62         static sigc::signal<void> ModeChanged;
63         static std::vector<AudioClock*> clocks;
64
65         static bool has_focus() { return _has_focus; }
66
67   private:
68         ARDOUR::Session  *session;
69         Mode             _mode;
70         uint32_t          key_entry_state;
71         std::string      _name;
72         bool              is_transient;
73         bool              is_duration;
74         bool              editable;
75
76         Gtk::Menu  *ops_menu;
77
78         Gtk::HBox   smpte_packer_hbox;
79         Gtk::HBox   smpte_packer;
80
81         Gtk::HBox   minsec_packer_hbox;
82         Gtk::HBox   minsec_packer;
83
84         Gtk::HBox   bbt_packer_hbox;
85         Gtk::HBox   bbt_packer;
86
87         Gtk::HBox   frames_packer_hbox;
88         Gtk::HBox   frames_packer;
89        
90         enum Field {
91                 SMPTE_Hours,
92                 SMPTE_Minutes,
93                 SMPTE_Seconds,
94                 SMPTE_Frames,
95                 MS_Hours,
96                 MS_Minutes,
97                 MS_Seconds,
98                 Bars,
99                 Beats, 
100                 Ticks,
101                 AudioFrames
102         };
103
104         Gtk::EventBox  audio_frames_ebox;
105         Gtk::Label     audio_frames_label;
106
107         Gtk::HBox      off_hbox;
108
109         Gtk::EventBox  hours_ebox;
110         Gtk::EventBox  minutes_ebox;
111         Gtk::EventBox  seconds_ebox;
112         Gtk::EventBox  frames_ebox;
113
114         Gtk::EventBox  ms_hours_ebox;
115         Gtk::EventBox  ms_minutes_ebox;
116         Gtk::EventBox  ms_seconds_ebox;
117
118         Gtk::EventBox  bars_ebox;
119         Gtk::EventBox  beats_ebox;
120         Gtk::EventBox  ticks_ebox;
121
122         Gtk::Label  hours_label;
123         Gtk::Label  minutes_label;
124         Gtk::Label  seconds_label;
125         Gtk::Label  frames_label;
126         Gtk::Label  colon1, colon2, colon3;
127
128         Gtk::Label  ms_hours_label;
129         Gtk::Label  ms_minutes_label;
130         Gtk::Label  ms_seconds_label;
131         Gtk::Label  colon4, colon5;
132
133         Gtk::Label  bars_label;
134         Gtk::Label  beats_label;
135         Gtk::Label  ticks_label;
136         Gtk::Label  b1;
137         Gtk::Label  b2;
138
139         Gtk::Label*  frames_upper_info_label;
140         Gtk::Label*  frames_lower_info_label;
141
142         Gtk::Label*  smpte_upper_info_label;
143         Gtk::Label*  smpte_lower_info_label;
144         
145         Gtk::Label*  bbt_upper_info_label;
146         Gtk::Label*  bbt_lower_info_label;
147
148         Gtk::VBox   frames_info_box;
149         Gtk::VBox   smpte_info_box;
150         Gtk::VBox   bbt_info_box;
151
152         Gtk::EventBox  clock_base;
153         Gtk::Frame     clock_frame;
154
155         nframes_t last_when;
156         bool last_pdelta;
157         bool last_sdelta;
158
159         uint32_t last_hrs;
160         uint32_t last_mins;
161         uint32_t last_secs;
162         uint32_t last_frames;
163         bool last_negative;
164
165         long  ms_last_hrs;
166         long  ms_last_mins;
167         float ms_last_secs;
168
169         bool dragging;
170         double drag_start_y;
171         double drag_y;
172         double drag_accum;
173
174         void on_realize ();
175         
176         bool field_motion_notify_event (GdkEventMotion *ev, Field);
177         bool field_button_press_event (GdkEventButton *ev, Field);
178         bool field_button_release_event (GdkEventButton *ev, Field);
179         bool field_button_scroll_event (GdkEventScroll *ev, Field);
180         bool field_key_press_event (GdkEventKey *, Field);
181         bool field_key_release_event (GdkEventKey *, Field);
182         bool field_focus_in_event (GdkEventFocus *, Field);
183         bool field_focus_out_event (GdkEventFocus *, Field);
184         bool drop_focus_handler (GdkEventFocus*);
185
186         void set_smpte (nframes_t, bool);
187         void set_bbt (nframes_t, bool);
188         void set_minsec (nframes_t, bool);
189         void set_frames (nframes_t, bool);
190
191         nframes_t get_frames (Field,nframes_t pos = 0,int dir=1);
192         
193         void smpte_sanitize_display();
194         nframes_t smpte_frame_from_display () const;
195         nframes_t bbt_frame_from_display (nframes_t) const;
196         nframes_t bbt_frame_duration_from_display (nframes_t) const;
197         nframes_t minsec_frame_from_display () const;
198         nframes_t audio_frame_from_display () const;
199
200         void build_ops_menu ();
201         void setup_events ();
202
203         void smpte_offset_changed ();
204         void set_size_requests ();
205
206         static const uint32_t field_length[(int)AudioFrames+1];
207         static bool _has_focus;
208         
209 };
210
211 #endif /* __audio_clock_h__ */