timecode clock info patch from oofus, big clock mods from oofus, rec-sensitive color...
[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 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_name (std::string);
54
55         nframes_t current_time (nframes_t position = 0) const;
56         nframes_t current_duration (nframes_t position = 0) const;
57         void set_session (ARDOUR::Session *s);
58
59         sigc::signal<void> ValueChanged;
60         
61   private:
62         ARDOUR::Session  *session;
63         Mode             _mode;
64         uint32_t      key_entry_state;
65         bool              is_duration;
66         bool              editable;
67
68         Gtk::Menu  *ops_menu;
69
70         Gtk::HBox   smpte_packer_hbox;
71         Gtk::HBox   smpte_packer;
72
73         Gtk::HBox   minsec_packer_hbox;
74         Gtk::HBox   minsec_packer;
75
76         Gtk::HBox   bbt_packer_hbox;
77         Gtk::HBox   bbt_packer;
78
79         Gtk::HBox   frames_packer_hbox;
80         Gtk::HBox   frames_packer;
81        
82         enum Field {
83                 SMPTE_Hours,
84                 SMPTE_Minutes,
85                 SMPTE_Seconds,
86                 SMPTE_Frames,
87                 MS_Hours,
88                 MS_Minutes,
89                 MS_Seconds,
90                 Bars,
91                 Beats, 
92                 Ticks,
93                 AudioFrames
94         };
95
96         Gtk::EventBox  audio_frames_ebox;
97         Gtk::Label     audio_frames_label;
98
99         Gtk::EventBox  hours_ebox;
100         Gtk::EventBox  minutes_ebox;
101         Gtk::EventBox  seconds_ebox;
102         Gtk::EventBox  frames_ebox;
103
104         Gtk::EventBox  ms_hours_ebox;
105         Gtk::EventBox  ms_minutes_ebox;
106         Gtk::EventBox  ms_seconds_ebox;
107
108         Gtk::EventBox  bars_ebox;
109         Gtk::EventBox  beats_ebox;
110         Gtk::EventBox  ticks_ebox;
111
112         Gtk::Label  hours_label;
113         Gtk::Label  minutes_label;
114         Gtk::Label  seconds_label;
115         Gtk::Label  frames_label;
116         Gtk::Label  colon1, colon2, colon3;
117
118         Gtk::Label  ms_hours_label;
119         Gtk::Label  ms_minutes_label;
120         Gtk::Label  ms_seconds_label;
121         Gtk::Label  colon4, colon5;
122
123         Gtk::Label  bars_label;
124         Gtk::Label  beats_label;
125         Gtk::Label  ticks_label;
126         Gtk::Label  b1;
127         Gtk::Label  b2;
128
129         Gtk::Label*  frames_upper_info_label;
130         Gtk::Label*  frames_lower_info_label;
131
132         Gtk::Label*  smpte_upper_info_label;
133         Gtk::Label*  smpte_lower_info_label;
134         
135         Gtk::Label*  bbt_upper_info_label;
136         Gtk::Label*  bbt_lower_info_label;
137
138         Gtk::VBox   frames_info_box;
139         Gtk::VBox   smpte_info_box;
140         Gtk::VBox   bbt_info_box;
141
142         Gtk::EventBox  clock_base;
143         Gtk::Frame     clock_frame;
144
145         nframes_t last_when;
146
147         uint32_t last_hrs;
148         uint32_t last_mins;
149         uint32_t last_secs;
150         uint32_t last_frames;
151         bool last_negative;
152
153         long  ms_last_hrs;
154         long  ms_last_mins;
155         float ms_last_secs;
156
157         bool dragging;
158         double drag_start_y;
159         double drag_y;
160         double drag_accum;
161
162         void on_realize ();
163         
164         bool field_motion_notify_event (GdkEventMotion *ev, Field);
165         bool field_button_press_event (GdkEventButton *ev, Field);
166         bool field_button_release_event (GdkEventButton *ev, Field);
167         bool field_button_scroll_event (GdkEventScroll *ev, Field);
168         bool field_key_release_event (GdkEventKey *, Field);
169         bool field_focus_in_event (GdkEventFocus *, Field);
170         bool field_focus_out_event (GdkEventFocus *, Field);
171
172         void set_smpte (nframes_t, bool);
173         void set_bbt (nframes_t, bool);
174         void set_minsec (nframes_t, bool);
175         void set_frames (nframes_t, bool);
176
177         nframes_t get_frames (Field,nframes_t pos = 0,int dir=1);
178         
179         void smpte_sanitize_display();
180         nframes_t smpte_frame_from_display () const;
181         nframes_t bbt_frame_from_display (nframes_t) const;
182         nframes_t bbt_frame_duration_from_display (nframes_t) const;
183         nframes_t minsec_frame_from_display () const;
184         nframes_t audio_frame_from_display () const;
185
186         void build_ops_menu ();
187         void setup_events ();
188
189         void smpte_offset_changed ();
190         void set_size_requests ();
191
192         static const uint32_t field_length[(int)AudioFrames+1];
193 };
194
195 #endif /* __audio_clock_h__ */