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