tidy up (a bit) locations editing widget ; use pixbuf/string code from 2.0;remove...
[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                 Timecode,
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 focus ();
50
51         void set (nframes_t, bool force = false, nframes_t offset = 0, char which = 0);
52         void set_from_playhead ();
53         void locate ();
54         void set_mode (Mode);
55         void set_bbt_reference (nframes64_t);
56
57         void set_widget_name (std::string);
58
59         std::string name() const { return _name; }
60
61         nframes_t current_time (nframes_t position = 0) const;
62         nframes_t current_duration (nframes_t position = 0) const;
63         void set_session (ARDOUR::Session *s);
64
65         sigc::signal<void> ValueChanged;
66         sigc::signal<void> mode_changed;
67         sigc::signal<void> ChangeAborted;
68
69         static sigc::signal<void> ModeChanged;
70         static std::vector<AudioClock*> clocks;
71
72         static bool has_focus() { return _has_focus; }
73
74   private:
75         ARDOUR::Session  *session;
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
83         Gtk::Menu  *ops_menu;
84
85         Gtk::HBox   timecode_packer_hbox;
86         Gtk::HBox   timecode_packer;
87
88         Gtk::HBox   minsec_packer_hbox;
89         Gtk::HBox   minsec_packer;
90
91         Gtk::HBox   bbt_packer_hbox;
92         Gtk::HBox   bbt_packer;
93
94         Gtk::HBox   frames_packer_hbox;
95         Gtk::HBox   frames_packer;
96
97         enum Field {
98                 Timecode_Hours,
99                 Timecode_Minutes,
100                 Timecode_Seconds,
101                 Timecode_Frames,
102                 MS_Hours,
103                 MS_Minutes,
104                 MS_Seconds,
105                 Bars,
106                 Beats,
107                 Ticks,
108                 AudioFrames
109         };
110
111         Gtk::EventBox  audio_frames_ebox;
112         Gtk::Label     audio_frames_label;
113
114         Gtk::HBox      off_hbox;
115
116         Gtk::EventBox  hours_ebox;
117         Gtk::EventBox  minutes_ebox;
118         Gtk::EventBox  seconds_ebox;
119         Gtk::EventBox  frames_ebox;
120
121         Gtk::EventBox  ms_hours_ebox;
122         Gtk::EventBox  ms_minutes_ebox;
123         Gtk::EventBox  ms_seconds_ebox;
124
125         Gtk::EventBox  bars_ebox;
126         Gtk::EventBox  beats_ebox;
127         Gtk::EventBox  ticks_ebox;
128
129         Gtk::Label  hours_label;
130         Gtk::Label  minutes_label;
131         Gtk::Label  seconds_label;
132         Gtk::Label  frames_label;
133         Gtk::Label  colon1, colon2, colon3;
134
135         Gtk::Label  ms_hours_label;
136         Gtk::Label  ms_minutes_label;
137         Gtk::Label  ms_seconds_label;
138         Gtk::Label  colon4, colon5;
139
140         Gtk::Label  bars_label;
141         Gtk::Label  beats_label;
142         Gtk::Label  ticks_label;
143         Gtk::Label  b1;
144         Gtk::Label  b2;
145
146         Gtk::Label*  frames_upper_info_label;
147         Gtk::Label*  frames_lower_info_label;
148
149         Gtk::Label*  timecode_upper_info_label;
150         Gtk::Label*  timecode_lower_info_label;
151
152         Gtk::Label*  bbt_upper_info_label;
153         Gtk::Label*  bbt_lower_info_label;
154
155         Gtk::VBox   frames_info_box;
156         Gtk::VBox   timecode_info_box;
157         Gtk::VBox   bbt_info_box;
158
159         Gtk::EventBox  clock_base;
160         Gtk::Frame     clock_frame;
161
162         nframes64_t bbt_reference_time;
163         nframes_t last_when;
164         bool last_pdelta;
165         bool last_sdelta;
166
167         uint32_t last_hrs;
168         uint32_t last_mins;
169         uint32_t last_secs;
170         uint32_t last_frames;
171         bool last_negative;
172
173         long  ms_last_hrs;
174         long  ms_last_mins;
175         float ms_last_secs;
176
177         bool dragging;
178         double drag_start_y;
179         double drag_y;
180         double drag_accum;
181
182         void on_realize ();
183
184         bool field_motion_notify_event (GdkEventMotion *ev, Field);
185         bool field_button_press_event (GdkEventButton *ev, Field);
186         bool field_button_release_event (GdkEventButton *ev, Field);
187         bool field_button_scroll_event (GdkEventScroll *ev, Field);
188         bool field_key_press_event (GdkEventKey *, Field);
189         bool field_key_release_event (GdkEventKey *, Field);
190         bool field_focus_in_event (GdkEventFocus *, Field);
191         bool field_focus_out_event (GdkEventFocus *, Field);
192         bool drop_focus_handler (GdkEventFocus*);
193
194         void set_timecode (nframes_t, bool);
195         void set_bbt (nframes_t, bool);
196         void set_minsec (nframes_t, bool);
197         void set_frames (nframes_t, bool);
198
199         nframes_t get_frames (Field,nframes_t pos = 0,int dir=1);
200
201         void timecode_sanitize_display();
202         nframes_t timecode_frame_from_display () const;
203         nframes_t bbt_frame_from_display (nframes_t) const;
204         nframes_t bbt_frame_duration_from_display (nframes_t) const;
205         nframes_t minsec_frame_from_display () const;
206         nframes_t audio_frame_from_display () const;
207
208         void build_ops_menu ();
209         void setup_events ();
210
211         void timecode_offset_changed ();
212         void set_size_requests ();
213
214         static const uint32_t field_length[(int)AudioFrames+1];
215         static bool _has_focus;
216
217 };
218
219 #endif /* __audio_clock_h__ */