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